-
Notifications
You must be signed in to change notification settings - Fork 0
Setup Manual
JennyNet is easily set up but a few considerations have to be made in order to make the layer function to your expectations.
In order to setup the layer, an understanding is required about its basic workings. Communication between the local and the remote layer occurs through "connections" (type Connection). A connection is defined by two socket addresses, the local and the remote. A socket address is a host-address and a port number. Multiple connections can be set up in the local layer and they are always a Client. In order to establish a connection a client addresses a Server as remote partner. When the link between the hosts is made, the remote layer also establishes a connection through the server. The server only creates a connection when a call is made from a client. A connection rendered by a server complies with the ServerConnection interface, an extension of Connection. Referencing the same host for client and server, and running both client and server in the same program, is all possible.
A connection offers services to an application. The first communication services are sending of objects (instances of serialisable classes) and sending of files. Each of these parts require some setup activity before they can be used.
File Transfer requires for the receiving layer to define a "landing zone" for incoming files. The zone has to be named as a writeable folder in the file-system; it is set as property TRANSFER_ROOT_PATH in a connection's parameters (ConnectionParameters.setFileRootDir()). The sending layer has no restrictions to send files.
Object Transfer requires the classes of objects to be transferred to be registered at the serialisation devices of both involved connections. Serialisation devices are objects of the Serialization interface which are associated to a connection. These objects realise serialisation and de-serialisation of transfer-objects and take on the registrations of their types. The registration can be performed specialising at a particular connection or on a generic level in the JennyNet class, where default serialisation devices can be retrieved and used. The default devices are copied into connections when these are instantiated. Later modifications of default devices will not become vaild for existing connections.
Connection-parameters are a tool to fine-tune the behaviour of a Connection through setting parameter values or activating special services which the implementation is capable of. Connection-parameter sets are available at different places and abstraction levels. Each connection has its own set of parameters which can be adjusted to special needs. In the beginning, when a connection is initialised, a copy of a current default parameter set is created and placed into the connection. These generic sets are available at 1) JennyNet global class, referred to by Client and Server, and 2) each Server instance, referred to by ServerConnection. By modifying properties in the generic sets at an early time, the application can avoid to set each individual connection with identical values.
There are design alternatives which should be considered when setting the JennyNet layer into use. After choosing on and setting up design alternatives, the application should proceed with setting the global connection-parameters by modifying JennyNet.getDefaultParameters() (returning ConnectionParameters, initially set to a functioning standard edition). If objects are to be transmitted, the application proceeds to registering the classes used into one or more default serialisation devices. In JennyNet there is one default serialisation available per serialisation method. Each default serialisation has a basic set of Java classes already registered.
Design alternatives consist of the following decisions
- whether events from a single connection are received through a listener (
ConnectionListener) or through polling - whether an individual output thread for events is used by each connection or a generic single
- whether a custom serialisation method is to be added
- what serialisation method is the default method (2 implemented methods available)
- whether incoming file-transfers are allowed
- whether incoming file-transfers are stored in a generic folder or a special folder for each connection
- Server: whether incoming connections are signaled to the application via
ServerListeneror theServer.accept()method (polling)
These decisions are realised via methods of the JennyNet static class or in connection-parameters. In case of the server, the method Server.setSignalMethod() is to be used.
// this example decides for listeners to receive events from servers and connections
// we use the default for output-thread usage (global single)
// we use the default serialisation method (0 = Java-serialisation)
// we allow file-transfers and set a generic landing folder for incoming
ConnectionParameters defaultPar = JennyNet.getDefaultParameters();
defaultPar.setFileRootDir(new File("/home/hans/landing-files"));
// we fix a parcel-size for our application and enhance the capacity of queues
defaultPar.setTransmissonParcelSize(128000);
defaultPar.setObjectQueueCapacity(500);
// we activate ALIVE sending and IDLE-STATE checking (connection services)
defaultPar.setAlivePeriod(120000);
defaultPar.setIdleThreshold(1000);
// we register two classes to be used for sending objects
Serialization ser = JennyNet.getDefaultSerialisation(0);
ser.registerClass(OurCommands.class);
ser.registerClass(OurResults.class);
// when creating a connection we add our connection-listener
Client client = new Client();
client.addListener(new OurConnectionListener());
// when creating a server we add our server-listener (dealing with new connections)
Server server = new Server(25000);
server.addListener(new OurServerListener());
// optionally we can add a connection-listener to the server
// the server then adds the given connection-listeners to new connections
server.addConnectionListener(new OurServerConnectionListener());
// we don't allow for file-transfers (do nothing)
// we use the Kryo serialisation (method 1)
JennyNet.setDefaultSerialisationMethod(1);
// we opt for using individual output-threads for event dispatching
ConnectionParameters defaultPar = JennyNet.getDefaultParameters();
defaultPar.setDeliverThreadUsage(ThreadUsage.INDIVIDUAL);
// we adjust CONFIRM-TIMEOUT and DELIVER-TOLERANCE
defaultPar.setConfirmTimeout()(60000);
defaultPar.setDeliverTolerance(30000);
// we register two classes to be used for sending objects
Serialization ser = JennyNet.getDefaultSerialisation(1);
ser.registerClass(OurCommands.class);
ser.registerClass(OurResults.class);
// when creating a connection we wrap it into the poll-service
// a user-thread then calls 'pollBay.take()' in a loop (rendering the next ConnectionEvent)
Client client = new Client();
ConnectionPollService pollBay = new ConnectionPollService(client);
// when creating a server we set the signaling-method 'ACCEPT'
// a user-thread then calls 'server.accept()' in a loop (rendering the next incoming ServerConnection)
Server server = new Server(25000);
server.setSignalMethod(ServerSignalMethod.ACCEPT);