jwrapper.jwutils
Class JWSockIPC

java.lang.Object
  extended by jwrapper.jwutils.JWSockIPC

public class JWSockIPC
extends java.lang.Object

Used to reliably and easily set up a Socket (for inter-process communication) between the current process and a child process to be launched by JWSystem. Optionally provides multiple AES encrypted channels layered over the socket.


Method Summary
static void cancelIPC(java.util.Properties launchProperties)
          Cancel a previously prepared JWSockIPC
 void close()
          Close this JWSockIPC and the Socket underlying it
static JWSockIPC connectChild()
          Called by the child process to establish a Socket back to the parent process for IPC
static JWSockIPC connectChild(java.lang.String propsprefix)
          Called by the child process to establish a Socket back to the parent process for IPC
static JWSockIPC connectParent(java.util.Properties launchProperties)
          Called by the parent process after launching the child process to establish the Socket for IPC
static JWSockIPC connectParent(java.lang.String propsprefix, java.util.Properties launchProperties)
          Called by the parent process after launching the child process to establish the Socket for IPC
static JWSockIPC createNewIPC(java.net.Socket sock)
           
 java.io.InputStream getInChannel(short id)
          Get the multiplexed InputStream with the specified ID (-32,768 to 32,767 inclusive) This is paired with the InputStream of the same ID on the opposing Process.
 java.io.OutputStream getOutChannel(short id)
          Get the multiplexed OutputStream with the specified ID (-32,768 to 32,767 inclusive).
 java.net.Socket getRawUnencryptedSocket()
          Get the raw Socket set up by JWSockIPC between the parent and child process.
static void setupForIPC(java.util.Properties launchProperties, boolean aesEncrypted)
          Set up a child process for JWSockIPC by configuring its launch properties
static void setupForIPC(java.lang.String propsprefix, java.util.Properties launchProperties, boolean aesEncrypted)
          Set up a child process for JWSockIPC by configuring its launch properties
 void setupMultipleChannels()
          Set up multiplexing on the Socket to split it into multiple (63355) in/out channels (InputStream/OutputStream pairs).
 void setupPingsAndReportClosure(JWSockIPCListener listener, short channel, long timeoutMS)
          Set up pings (keepalive) on a multiplexed channel (e.g.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Method Detail

cancelIPC

public static void cancelIPC(java.util.Properties launchProperties)
Cancel a previously prepared JWSockIPC

Parameters:
launchProperties -

close

public void close()
Close this JWSockIPC and the Socket underlying it


connectChild

public static JWSockIPC connectChild()
                              throws java.io.IOException
Called by the child process to establish a Socket back to the parent process for IPC

Returns:
Throws:
java.io.IOException

connectChild

public static JWSockIPC connectChild(java.lang.String propsprefix)
                              throws java.io.IOException
Called by the child process to establish a Socket back to the parent process for IPC

Returns:
Throws:
java.io.IOException

connectParent

public static JWSockIPC connectParent(java.util.Properties launchProperties)
                               throws java.io.IOException
Called by the parent process after launching the child process to establish the Socket for IPC

Parameters:
launchProperties -
Returns:
Throws:
java.io.IOException

connectParent

public static JWSockIPC connectParent(java.lang.String propsprefix,
                                      java.util.Properties launchProperties)
                               throws java.io.IOException
Called by the parent process after launching the child process to establish the Socket for IPC

Parameters:
launchProperties -
Returns:
Throws:
java.io.IOException

createNewIPC

public static JWSockIPC createNewIPC(java.net.Socket sock)

getInChannel

public java.io.InputStream getInChannel(short id)
Get the multiplexed InputStream with the specified ID (-32,768 to 32,767 inclusive) This is paired with the InputStream of the same ID on the opposing Process.

Parameters:
id -
Returns:

getOutChannel

public java.io.OutputStream getOutChannel(short id)
Get the multiplexed OutputStream with the specified ID (-32,768 to 32,767 inclusive). This is paired with the InputStream of the same ID on the opposing Process.

Parameters:
id -
Returns:

getRawUnencryptedSocket

public java.net.Socket getRawUnencryptedSocket()
Get the raw Socket set up by JWSockIPC between the parent and child process. IMPORTANT you should not use multiplexing if you read/write to the Socket directly.


setupForIPC

public static void setupForIPC(java.util.Properties launchProperties,
                               boolean aesEncrypted)
                        throws java.io.IOException
Set up a child process for JWSockIPC by configuring its launch properties

Parameters:
launchProperties -
Throws:
java.io.IOException

setupForIPC

public static void setupForIPC(java.lang.String propsprefix,
                               java.util.Properties launchProperties,
                               boolean aesEncrypted)
                        throws java.io.IOException
Set up a child process for JWSockIPC by configuring its launch properties

Parameters:
launchProperties -
Throws:
java.io.IOException

setupMultipleChannels

public void setupMultipleChannels()
                           throws java.io.IOException
Set up multiplexing on the Socket to split it into multiple (63355) in/out channels (InputStream/OutputStream pairs). If encryption was requested then these channels will all be AES encrypted.

Throws:
java.io.IOException

setupPingsAndReportClosure

public void setupPingsAndReportClosure(JWSockIPCListener listener,
                                       short channel,
                                       long timeoutMS)
Set up pings (keepalive) on a multiplexed channel (e.g. 32767) and report into the listener interface if the stream fails or pings stop (indicating that the remote process has died or the socket has been shut down). IMPORTANT this must be set up by the parent and child process on the same channel. This call will block until the remote side has also called setupPingsAndReportClosure.

Parameters:
listener, - can be null
channel - the multiplexed channel to set up pings on.
timeoutMS -

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object