Installation
To install and use the PeerWare package you have to go through the following steps:
- Install the PeerWare and µCode package
- Write your own code that creates one ore more peers using the PeerWare API
If you feel a bit lost in using PeerWare ... don't worry, as an example we have created a little GUI based application. You can take a look to it in the section A simple GUI application ...
Installing PeerWare package
To install the PeerWare and µCode package, just extract the pw.jar and the mucode.jar files from the distribution archive and append them to the local classpath.
This could be done by the following commands:
set CLASSPATH=%CLASSPATH%;XXX\mucode.jar;XXX\pw.jar (in a MS Window dos shell)
or
export CLASSPATH=$CLASSPATH:XXX/mucode.jar:XXX./pw.jar (in a bash shell)
where instead of XXX you have to put the path where pw.jar and mucode.jar are saved, formatted according to the OS conventions (ex: C:/temp in MS Win or /tmp/project in a Unix like system).
That's all folks! Now the PeerWare API can be used by your Java programs.
... a little remark about µCode: its standard behavior was not appropriate to work with PeerWare, so µCode has been modified, and a customized version is included into the current PeerWare distribution. Probably future µCode versions will take over these changes. For further details take a look to the µCode official development site
Creating a Peer using the PeerWare API
Have you already appended the pw.jar and mucode.jar to the local classpath? No ... go to the section Install the PeerWare package.
To create a Peer you have to create an instance of the class Peer contained into the package peerware. See documentation for more details.
A code example could be:
import peerware.*;
...
Peer p1;
p1 = new Peer(repositoryImpl, null, listeningIPPort); //for parameters details see documentation (javadoc)
...
By creating a Peer instance, you get a working peer you can use to connect to other ones. The Peer instance is also the entry point for using the PeerWare API.
Class Peer uses a directory in the local file system to cache for a while events directed to unreachable users.
You can choose which directory to use in the local file system by setting the java property "peerware.savedir" (new to java properties? Take a look to the Java Tutorial).
When executing a java class, instead of typing the command:
java MyClass
where MyClass is the name of the class to be executed,
you can both start the class execution and set the property peerware.savedir in this way:
java -Dpeerware.savedir=XXX MyClass
Remember to replace XXX with the full path of the directory to be used.
A simple GUI application using PeerWare
As you can guess from documentation, PeerWare is not an application but a middleware to be used for application development. If you want to quickly have a look to a PeerWare based application, we have included in the distribution a simple GUI program (whose name is GUIConsole and is contained in package console) that allows users to try the main PeerWare features.
To run GUIConsole type:
java console.GUIConsole [portNumber]
PortNumber is an optional parameter and is used to communicate to the GUIConsole on which IP port has the peer to listen for incoming connections.
Remember to include the pw.jar in the local classpath before running the GUIConsole program.