org.vishia.communication
Interface InterProcessComm

All Known Implementing Classes:
InterProcessComm_SocketImpl

public interface InterProcessComm

This interface is the applicable interface to realize a communication between processes at the same processor board or between processes via network using UDP/IP. In generally, realization of this class is hardware-depended. An implementation with socket communications (using java.net.Socket*) exists. But the user can realize its own solutions based on this interface, at example with using dual port RAM-communication at system level.


Field Summary
static int receiverShouldbeBlocking
          Mode of receiving, determined on open().
static int receiverShouldbePolling
          Mode of receiving, determined on open().
 
Method Summary
 int abortReceive()
          Abort receiving function
 int capacityToSendWithoutBlocking(int nrofBytesToSend)
          Tests wether a next send is done without blocking.
 int checkConnection()
          Checks the connection.
 int close()
          Closes the mailbox, only to be called on shutdown of the application.
 Address_InterProcessComm createAddress()
          Creates an empty instance for a address information, especially for the sender.
 Address_InterProcessComm createAddress(int p1, int p2)
           
 Address_InterProcessComm createAddress(java.lang.String address)
           
 Address_InterProcessComm createAddress(java.lang.String p1, int p2)
           
 int dataAvailable()
          Tests wether data are available to receive.
 boolean equals(Address_InterProcessComm address1P, Address_InterProcessComm address2P)
          Compare the address to another address, returns true if it is the same address.
 int flush()
          Flushs send data to destination.
 void freeData(byte[] data)
          Relinguishes the data buffer, after it is evaluated.
 java.lang.String getName()
           
 Address_InterProcessComm getOwnAddress()
          Gets the own address of this interProcessComm, it are the receive parameters.
 byte[] getSendBuffer(int len)
          Gets a buffer for send.
 int open(Address_InterProcessComm dstAddress, boolean shouldBlock)
          Opens the Communication.
 byte[] receive(int[] result, Address_InterProcessComm sender)
          Receives a Datagram.
 byte[] receiveData(int[] nrofBytes, byte[] buffer, Address_InterProcessComm sender)
           
 int send(byte[] data, int nBytes, Address_InterProcessComm addressee)
          Sends Data.
 java.lang.String translateErrorMsg(int nError)
           
 

Field Detail

receiverShouldbeBlocking

static final int receiverShouldbeBlocking
Mode of receiving, determined on open(). The receive()-call either blocks if no data are available (it should be called in an extra thread), or it returns a nullpointer, if no data are available. This is a polling manner.

See Also:
Constant Field Values

receiverShouldbePolling

static final int receiverShouldbePolling
Mode of receiving, determined on open(). The receive()-call either blocks if no data are available (it should be called in an extra thread), or it returns a nullpointer, if no data are available. This is a polling manner.

See Also:
Constant Field Values
Method Detail

open

int open(Address_InterProcessComm dstAddress,
         boolean shouldBlock)
Opens the Communication. Only called at startup.

Parameters:
dstAddress - The own address to which this interprocess-port is assigned. This address is also used when calling send() as information about the sender of the data.
mode - Ones of the value 'receiverIsBlocking' or 'receiverIsBlocking'.
Returns:
true if success, false if it failed. Use getReceiveErrorMsg() to detect the cause manually.

close

int close()
Closes the mailbox, only to be called on shutdown of the application.


send

int send(byte[] data,
         int nBytes,
         Address_InterProcessComm addressee)
Sends Data. The destination adress is defined on open. If a listener is associated with this class, the data will be forwarded to the users evaluation method defined in the implementation of the listener. So a evaluation may be execute directly without consideration of the users software and without consideration of the realization in this class. If no listener is associated, the data will be sent in the kind of realization of this class.

Parameters:
data - The data to be sent. The user should not touch the buffer after calling here.
nBytes - The number of bytes to be send.
addressee - The addressee, the receiver of the message. If it is a fix connection (TCP), then this parameter should be null. It isn't used. The addressee is given on #open(Address_InterProcessComm, int)-request.
Returns:
number of Bytes sent, if >=0. If <0 its an error code.

receive

byte[] receive(int[] result,
               Address_InterProcessComm sender)
Receives a Datagram. This method blocks until a Datagram is received. If a Datagram is received, the content of the Datagram will copied into the appropriated buffer.

Parameters:
data - out:
sender - Buffer for the sender of the message.
result - result[0] = Nr of Bytes sendet, if >=0. If <0 its an error code.
Returns:
The reference to the buffer containing data. On error, the content of this reference is not valid, but the user must call relinguishData() with this reference .

receiveData

byte[] receiveData(int[] nrofBytes,
                   byte[] buffer,
                   Address_InterProcessComm sender)
Parameters:
nrofBytes -
buffer -
sender -
Returns:

freeData

void freeData(byte[] data)
Relinguishes the data buffer, after it is evaluated.

Parameters:
data - The buffer delivered from receive!

checkConnection

int checkConnection()
Checks the connection. This is the alternativ method for polling instead of the callback methods errorConnection() and readyConnection().

Returns:
value less 0: error code, the connection is not available. If the value is >=0, the connection is established.

capacityToSendWithoutBlocking

int capacityToSendWithoutBlocking(int nrofBytesToSend)
Tests wether a next send is done without blocking. If the transfer medium supports this test and it has a limited capacity, the method is helpfull to use. If the medium doesnot support such quest, the nrofBytes is returned. It means, it has a capacity. send is possible but it is not guarented that the send doesnot block.

Returns:
nrofBytes of capacity to send without blocking, but not greater than argument nrofBytesToSend. 0 if the next send call will be blocked. negativ value if any error.

dataAvailable

int dataAvailable()
Tests wether data are available to receive. This is the alternativ method for polling instead of the callback methods dataAvailable() from the callback interface. This method can return 0 also if data are receiveable, if the implementation donot support such quest.

Returns:
value less 0: error code, the connection is not available. If the value is >0, data are available. If 0, no data are available.

abortReceive

int abortReceive()
Abort receiving function


getName

java.lang.String getName()

getOwnAddress

Address_InterProcessComm getOwnAddress()
Gets the own address of this interProcessComm, it are the receive parameters. The knowledge of receive address may be necessary at user level if the information about a other receive adress should be communicate to the partner. In most cases the partner knows the sender adress (back-info-argument of receive) from the implementation level, but in some cases (2-simplex-Ports TCP/UDP) the receive adress is the address getted here.


createAddress

Address_InterProcessComm createAddress()
Creates an empty instance for a address information, especially for the sender.

Returns:
An empty new instance apropriate to the kind of communication.

createAddress

Address_InterProcessComm createAddress(int p1,
                                       int p2)

createAddress

Address_InterProcessComm createAddress(java.lang.String p1,
                                       int p2)

createAddress

Address_InterProcessComm createAddress(java.lang.String address)

equals

boolean equals(Address_InterProcessComm address1P,
               Address_InterProcessComm address2P)
Compare the address to another address, returns true if it is the same address. This method can used to compare a known address with a sender address from InterProcessComm::receive().

Parameters:
address1 - The address to compare.
address2 - The address to compare. return true if the addresses describes the same communication slot. On Pc that is the same IP-Address and the same port.

translateErrorMsg

java.lang.String translateErrorMsg(int nError)

flush

int flush()
Flushs send data to destination.


getSendBuffer

byte[] getSendBuffer(int len)
Gets a buffer for send.