Networking
This page describe details how to us and improve the networking module in Janus.
Contents |
Enable Networking Support
First you need to include the janus network module in your maven POM :
<project ...> ... <dependencies> ... <dependency> <groupId>org.janus-project.kernel</groupId> <artifactId>network</artifactId> <version>${janus.version}</version> </dependency> </dependencies> ... </project>
The default implementation of the networking modules uses JXTA, if this implementation does not fit your needs you can Create Your Own Network Layer
OSGi applications
In your JanusApplication implementation class, locate the method getKernelAgentFactory() and set it with something like the following:
public KernelAgentFactory getKernelAgentFactory() { return new NetworkingKernelAgentFactory(context); }
If you created your application using the archetype all should already be ready, just uncomment the corresponding line.
Java Launcher
Janus is planed to become an OSGi platform but it also supports starting you application using the "traditional" java way.
Include the Janus network module in your maven POM as mentioned earlier.
To enable network support your "Launcher" class should look something like this:
public class Launcher { /** * @param argv * @throws Exception */ public static void main(String[] argv) throws Exception { Kernels.setPreferredKernelFactory(new NetworkingKernelAgentFactory(null)); Kernel kernel = Kernels.get(true); MyAgent agent = new MyAgent(); kernel.launchHeavyAgent(agent,"agent1"); } }
Notice that the only like included is :
Kernels.setPreferredKernelFactory(new NetworkingKernelAgentFactory(null));
This lets the Kernels instanciator know that you want a network enabled kernel.
That it!
Now the kernels in the network will be discovered and connected (if needed) automagically!


