public class JavaCPN extends java.lang.Object implements JavaCPNInterface
No connection management has been implemented within Java/CPN as
this is a minimal implementation, however the important thing is that
it implements the same protocol at the Messaging Layer as the peer
entity. Generic send
and receive
functions have been provided at
the level of the Messaging Layer, meaning that sequences of bytes are
passed to the send method and returned from the receive method. The
connect
, accept
, and disconnect
methods have been provided at
the level of the Communication Layer from Comms/CPN. The
deliberate attempt was made to make the interface as close to that of
Comms/CPN as possible.
Methods external to the Java/CPN class must be used to convert from data (i.e. a string) into a ByteArrayInputStream object, and from a ByteArrayOutputStream object back into data. This is akin to the encoding and decoding functions passed into the send and receive functions of the Connection Management Layer in Comms/CPN. They are contained within the EncodeDecode class.
Constructor and Description |
---|
JavaCPN()
Constructor to create a new JavaCPN object.
|
Modifier and Type | Method and Description |
---|---|
void |
accept(int port)
Method to passively open a connection.
|
void |
connect(java.lang.String hostName,
int port)
Method to actively establish a connection.
|
void |
disconnect()
Method to disconnect the established connection.
|
java.io.ByteArrayOutputStream |
receive()
Method used to receive a ByteArrayOutputStream from an established
connection.
|
void |
send(java.io.ByteArrayInputStream sendBytes)
Method used to send a ByteArrayInputStream via an established
connection.
|
public JavaCPN()
connect
or the accept
methods need to be called.public void connect(java.lang.String hostName, int port) throws java.io.IOException, java.net.UnknownHostException
connect
in interface JavaCPNInterface
hostName
- The host to attempt to connect toport
- The port number to attempt to connect tojava.io.IOException
- Thrown when there is a communication errorjava.net.UnknownHostException
- Thrown when the host name provided as the argument
cannot be resolved into an IP addresspublic void accept(int port) throws java.io.IOException
accept
in interface JavaCPNInterface
port
- The port number to attempt to connect tojava.io.IOException
- Thrown when there is a communication errorpublic void send(java.io.ByteArrayInputStream sendBytes) throws java.net.SocketException
send
in interface JavaCPNInterface
sendBytes
- The byte stream to be sent to the receiving end of the connectionjava.net.SocketException
- Thrown if there is a problem sending the byte streampublic java.io.ByteArrayOutputStream receive() throws java.net.SocketException
receive
in interface JavaCPNInterface
java.net.SocketException
- Thrown if there is a problem sending the byte streampublic void disconnect() throws java.io.IOException
disconnect
in interface JavaCPNInterface
java.io.IOException
- if there is a problem closing the connectionCopyright © 2004-2014 The YAWL Foundation.