xmlBlaster 2.2.0 client API

org.xmlBlaster.client.protocol.socket
Class SocketConnection

java.lang.Object
  extended by org.xmlBlaster.client.protocol.socket.SocketConnection
All Implemented Interfaces:
I_XmlBlasterConnection, I_Plugin

public class SocketConnection
extends java.lang.Object
implements I_XmlBlasterConnection

This driver establishes exactly one connection to xmlBlaster-Server and uses this socket for asynchronous callbacks as well. This way we don't need to setup a callbackserver.

This "SOCKET:" driver needs to be registered in xmlBlaster.properties and will be started on xmlBlaster startup:

 ClientProtocolPlugin[SOCKET][1.0]=org.xmlBlaster.client.protocol.socket.SocketConnection
 

All adjustable parameters are explained in usage()

Author:
Marcel Ruff.
See Also:
The protocol.socket requirement

Field Summary
protected  SocketCallbackImpl cbReceiver
          SocketCallbackImpl listens on socket to receive callbacks
protected  Address clientAddress
           
protected  java.lang.String loginName
           
protected  java.lang.String sessionId
          The unique client sessionId
protected  java.net.Socket sock
          The socket connection to/from one client
 
Constructor Summary
SocketConnection()
          Called by plugin loader which calls init(Global, PluginInfo) thereafter.
SocketConnection(Global glob)
          Connect to xmlBlaster using plain socket with native message format.
SocketConnection(Global glob, java.applet.Applet ap)
          Connect to xmlBlaster using plain socket messaging.
 
Method Summary
 java.lang.String connect(java.lang.String connectQos)
          Login to the server.
 void connectLowlevel(Address address)
          Connects to xmlBlaster with one socket connection.
 boolean disconnect(java.lang.String qos)
          Does a logout and removes the callback server.
 java.lang.String[] erase(java.lang.String xmlKey_literal, java.lang.String qos_literal)
          Delete messages.
 MsgUnitRaw[] get(java.lang.String xmlKey_literal, java.lang.String qos_literal)
          Synchronous access a message.
 SocketUrl getLocalSocketUrl()
          A string with the local address and port (the client side).
 java.lang.String getLocalSocketUrlStr()
          A string with the local address and port (the client side).
 java.lang.String getLoginName()
           
 java.lang.String getProtocol()
          Returns the protocol type.
 java.net.Socket getSocket()
          Get the raw socket handle
 java.lang.String getType()
          Enforced by I_Plugin
 java.lang.String getVersion()
          Enforced by I_Plugin
 void init(Global glob, PluginInfo pluginInfo)
          This method is called by the PluginManager (enforced by I_Plugin).
 boolean isConnected()
           
 boolean isLoggedIn()
           
 java.lang.String ping(java.lang.String qos)
          Check server.
 java.lang.String publish(MsgUnitRaw msgUnit)
          Publish a message.
 java.lang.String[] publishArr(MsgUnitRaw[] msgUnitArr)
          Publish multiple messages in one sweep.
 void publishOneway(MsgUnitRaw[] msgUnitArr)
          Publish multiple messages in one sweep.
 I_ProgressListener registerProgressListener(I_ProgressListener listener)
          Register a listener for to receive information about the progress of incoming data.
 void resetConnection()
          Reset the driver on problems
 void setConnectReturnQos(ConnectReturnQos connectReturnQos)
          Pass the driver the decrypted and parsed ConnectReturnQos directly after a connect.
 void shutdown()
          Shut down the callback server.
 java.lang.String subscribe(java.lang.String xmlKey_literal, java.lang.String qos_literal)
          Enforced by I_XmlBlasterConnection interface (failsafe mode).
 java.lang.String toXml()
          Dump of the state, remove in future.
 java.lang.String toXml(java.lang.String extraOffset)
          Dump of the state, remove in future.
 java.lang.String[] unSubscribe(java.lang.String xmlKey_literal, java.lang.String qos_literal)
          Unsubscribe from messages.
static java.lang.String usage()
          Command line usage.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

sock

protected java.net.Socket sock
The socket connection to/from one client


cbReceiver

protected SocketCallbackImpl cbReceiver
SocketCallbackImpl listens on socket to receive callbacks


sessionId

protected java.lang.String sessionId
The unique client sessionId


loginName

protected java.lang.String loginName

clientAddress

protected Address clientAddress
Constructor Detail

SocketConnection

public SocketConnection()
Called by plugin loader which calls init(Global, PluginInfo) thereafter.


SocketConnection

public SocketConnection(Global glob)
                 throws XmlBlasterException
Connect to xmlBlaster using plain socket with native message format.

Throws:
XmlBlasterException

SocketConnection

public SocketConnection(Global glob,
                        java.applet.Applet ap)
                 throws XmlBlasterException
Connect to xmlBlaster using plain socket messaging.

Throws:
XmlBlasterException
Method Detail

getLoginName

public java.lang.String getLoginName()

getType

public java.lang.String getType()
Enforced by I_Plugin

Specified by:
getType in interface I_Plugin

getVersion

public java.lang.String getVersion()
Enforced by I_Plugin

Specified by:
getVersion in interface I_Plugin

init

public void init(Global glob,
                 PluginInfo pluginInfo)
          throws XmlBlasterException
This method is called by the PluginManager (enforced by I_Plugin).

Specified by:
init in interface I_Plugin
Throws:
XmlBlasterException
See Also:
I_Plugin.init(org.xmlBlaster.util.Global,org.xmlBlaster.util.plugin.PluginInfo)

getSocket

public java.net.Socket getSocket()
                          throws XmlBlasterException
Get the raw socket handle

Throws:
XmlBlasterException

connectLowlevel

public void connectLowlevel(Address address)
                     throws XmlBlasterException
Connects to xmlBlaster with one socket connection.

Specified by:
connectLowlevel in interface I_XmlBlasterConnection
Parameters:
address - Contains the remote address, e.g. the host and port where the remote server listens
Throws:
XmlBlasterException - ErrorCode.COMMUNICATION* if the server is not reachable, in this case we can poll for the server.
Other errors if for example a malformed address is passed, in this case we stop and give up.
See Also:
I_XmlBlasterConnection.connectLowlevel(Address)

resetConnection

public void resetConnection()
Reset the driver on problems

Specified by:
resetConnection in interface I_XmlBlasterConnection

getLocalSocketUrl

public SocketUrl getLocalSocketUrl()
A string with the local address and port (the client side).

Returns:
For example "localhost:66557"

getLocalSocketUrlStr

public java.lang.String getLocalSocketUrlStr()
A string with the local address and port (the client side).

Returns:
For example "socket://myServer.com:7607", never null

setConnectReturnQos

public void setConnectReturnQos(ConnectReturnQos connectReturnQos)
Description copied from interface: I_XmlBlasterConnection
Pass the driver the decrypted and parsed ConnectReturnQos directly after a connect. Some driver take the secretSessionId from it or a returned remote address

Specified by:
setConnectReturnQos in interface I_XmlBlasterConnection
See Also:
I_XmlBlasterConnection.setConnectReturnQos(ConnectReturnQos)

connect

public java.lang.String connect(java.lang.String connectQos)
                         throws XmlBlasterException
Login to the server.

Specified by:
connect in interface I_XmlBlasterConnection
Parameters:
connectQos - The encrypted connect QoS
Returns:
ConnectReturnQos XML string
Throws:
XmlBlasterException - if login fails

getProtocol

public final java.lang.String getProtocol()
Returns the protocol type.

Specified by:
getProtocol in interface I_XmlBlasterConnection
Returns:
"SOCKET"

disconnect

public boolean disconnect(java.lang.String qos)
                   throws XmlBlasterException
Does a logout and removes the callback server.

Specified by:
disconnect in interface I_XmlBlasterConnection
Parameters:
sessionId - The client sessionId
Throws:
XmlBlasterException

shutdown

public void shutdown()
              throws XmlBlasterException
Shut down the callback server. Is called by logout()

Specified by:
shutdown in interface I_XmlBlasterConnection
Specified by:
shutdown in interface I_Plugin
Throws:
XmlBlasterException - if an exception occurs. The exception is handled by the RunLevelManager depending on how the plugin has been configured with the action:

<action do='STOP' onShutdownRunlevel='2' sequence='5' onFail='resource.configuration.pluginFailed'> If onFail is defined to something, the RunLevelManager will stop.


isLoggedIn

public final boolean isLoggedIn()
Specified by:
isLoggedIn in interface I_XmlBlasterConnection
Returns:
true if you are logged in

isConnected

public final boolean isConnected()
Returns:
true if the socket connection is established

subscribe

public final java.lang.String subscribe(java.lang.String xmlKey_literal,
                                        java.lang.String qos_literal)
                                 throws XmlBlasterException
Enforced by I_XmlBlasterConnection interface (failsafe mode). Subscribe to messages.

Specified by:
subscribe in interface I_XmlBlasterConnection
Throws:
XmlBlasterException
See Also:
The interface.subscribe requirement

unSubscribe

public final java.lang.String[] unSubscribe(java.lang.String xmlKey_literal,
                                            java.lang.String qos_literal)
                                     throws XmlBlasterException
Unsubscribe from messages.

Specified by:
unSubscribe in interface I_XmlBlasterConnection
Throws:
XmlBlasterException
See Also:
The interface.unSubscribe requirement

publish

public final java.lang.String publish(MsgUnitRaw msgUnit)
                               throws XmlBlasterException
Publish a message. The normal publish is handled here like a publishArr

Specified by:
publish in interface I_XmlBlasterConnection
Throws:
XmlBlasterException
See Also:
The interface.publish requirement

publishArr

public final java.lang.String[] publishArr(MsgUnitRaw[] msgUnitArr)
                                    throws XmlBlasterException
Publish multiple messages in one sweep.

Specified by:
publishArr in interface I_XmlBlasterConnection
Throws:
XmlBlasterException
See Also:
The interface.publish requirement

publishOneway

public final void publishOneway(MsgUnitRaw[] msgUnitArr)
                         throws XmlBlasterException
Publish multiple messages in one sweep.

Specified by:
publishOneway in interface I_XmlBlasterConnection
Throws:
XmlBlasterException
See Also:
The interface.publish requirement

erase

public final java.lang.String[] erase(java.lang.String xmlKey_literal,
                                      java.lang.String qos_literal)
                               throws XmlBlasterException
Delete messages.

Specified by:
erase in interface I_XmlBlasterConnection
Throws:
XmlBlasterException
See Also:
The interface.erase requirement

get

public final MsgUnitRaw[] get(java.lang.String xmlKey_literal,
                              java.lang.String qos_literal)
                       throws XmlBlasterException
Synchronous access a message.

Specified by:
get in interface I_XmlBlasterConnection
Throws:
XmlBlasterException
See Also:
The interface.get requirement

ping

public java.lang.String ping(java.lang.String qos)
                      throws XmlBlasterException
Check server.

Specified by:
ping in interface I_XmlBlasterConnection
Returns:
The StatusQosData string
Throws:
XmlBlasterException
See Also:
CORBA xmlBlaster.idl

toXml

public java.lang.String toXml()
                       throws XmlBlasterException
Dump of the state, remove in future.

Throws:
XmlBlasterException

toXml

public java.lang.String toXml(java.lang.String extraOffset)
                       throws XmlBlasterException
Dump of the state, remove in future.

Throws:
XmlBlasterException

registerProgressListener

public I_ProgressListener registerProgressListener(I_ProgressListener listener)
Register a listener for to receive information about the progress of incoming data. Only one listener is supported, the last call overwrites older calls.

Specified by:
registerProgressListener in interface I_XmlBlasterConnection
Parameters:
listener - Your listener, pass 0 to unregister.
Returns:
The previously registered listener or 0

usage

public static java.lang.String usage()
Command line usage.

  • -dispatch/connection/plugin/socket/port Specify a port number where xmlBlaster SOCKET server listens Default is port "+DEFAULT_SERVER_PORT+", the port 0 switches this feature off
  • -dispatch/connection/plugin/socket/hostname Specify a hostname where the xmlBlaster web server runs. Default is the localhost
  • -dispatch/connection/plugin/socket/localPort You can specify our client side port as well (usually you shouldn't) Default is that the port is chosen by the operating system
  • -dispatch/connection/plugin/socket/localHostname Specify the hostname who we are. Makes sense for multi homed computers Defaults to our hostname
  • -dispatch/connection/plugin/socket/responseTimeout How long to wait for a method invocation to return Defaults to 'forever', the value to pass is milli seconds
  • -dispatch/connection/plugin/socket/multiThreaded Use seperate threads per update() on client side [true]
  • -dump[socket] true switches on detailed SOCKET debugging [false]
  • These variables may be set in xmlBlaster.properties as well. Don't use the "-" prefix there.


    xmlBlaster 2.2.0 client API

    Copyright © 1999-2014 The xmlBlaster.org contributers.