Implementing Own Nodes / Workers

This chapter illustrates by way of an example how to implement own Nodes and NodeWorkers in jadice server in order to be able to carry out new processing operations.

Basically, two steps are necessary to put own nodes and workers into action: First, you have to implement a Node class which is recognized both by the client and the server (see the section called “Node Class”). Then the corresponding NodeWorker class which needs to be recognized only by the server has to be implemented (see the section called “Worker Class”).

Node Class

The new node class has to extend the abstract super class Node. It needs a constructor without parameters (default constructor).

Furthermore, the method getWorkerClassName() can be overwritten. This method returns as default return value the full qualified class name of the Node in which Node is replaced by Worker and worker is inserted as an additional namespace level (example: com.acme.jadiceserver.ExampleNode.getWorkerClassName() returns com.acme.jadiceserver.worker.ExampleWorker).

If you have chosen a different package structure, this method can be overwritten so that the full qualified class name of the corresponding worker class is returned:

Example 6.21. Implementing a Node

package com.mycompany.jadice.client;

import com.levigo.jadice.server.Node;

public class DemoNode extends Node {

  public String getWorkerClassName() {
    // Full qualified class name of the worker class
    return "com.mycompany.jadice.worker.DemoWorker";
  }


If the NodeWorker should receive parameters when it is running, this can be achieved through further methods in the Node implementation. Please note that all object and static attributes have to implement the interface Serializable since they are serialized and transferred via JMS (see section the section called “Configuring the Embedded Message Broker”).

Example 6.22. Adding a Parameter to the Example Node from Example 6.21, “Implementing a Node

public String getMyParameter() {
  // Should be modifiable via a setter method
  return "a Parameter";
}


The implemented Node has to be incorporated into the class path both on the client and the server side. It can be integrated in own workflows as shown with the Nodes in the section the section called “Application Scenarios and Code Examples”.

Worker Class

The worker class which carries out the conversion extends the abstract generic super class NodeWorker<N>. The type parameter <N> designates the corresponding Node class.

Here you have to implement the abstract method work() in which the conversion is conducted on the server side.

Example 6.23. Implementing a NodeWorker

package com.mycompany.jadice.server;

import java.io.InputStream;

import com.levigo.jadice.server.core.NodeWorker;
import com.levigo.jadice.server.shared.types.BundledStream;
import com.levigo.jadice.server.shared.types.Stream;
import com.levigo.jadice.server.shared.types.StreamDescriptor;
import com.mycompany.jadice.client.DemoNode;

public class DemoWorker extends NodeWorker<DemoNode> {

  protected void work() throws Throwable {
    // Parameter as defined in the example above
    String myParam = getNode().getMyParameter();

    // Retrive input data
    for (Stream stream : getInputBundle()) {
      InputStream unprocessedIS = stream.getInputStream();
      // Meta data of the received stream
      StreamDescriptor unprocessedSD = stream.getDescriptor();

      // Method to process the data (not shown here)
      InputStream processedIS = process(unprocessedIS, myParam);

      // Meta data of the processed data
      // unprocessedSD is set as "parent"
      StreamDescriptor processedSD = new StreamDescriptor(unprocessedSD);
      processedSD.setDescription("<Beschreibung>");
      processedSD.setMimeType("<MIME Type>");
      processedSD.setFileName("<Dateiname>");

      // Link result result with its meta data
      Stream result = new BundledStream(processedIS, processedSD);
      // pass the result
      getOutputBundle().addStream(result);
    }
  }
  }


The NodeWorker implemeted in this way just needs to be incorporated into the class path of jadice server and is automatically called when using the corresponding Node from Example 6.21, “Implementing a Node.

[jadice server Version 5.8.7.0: Documentation for Developers and Administrators. Published: 2021-04-15]