01: /*
02: @license.text@
03: */
04: package com.pavelvlasov.metrics.sample;
05:
06: import java.net.MalformedURLException;
07: import java.rmi.Naming;
08: import java.rmi.RemoteException;
09: import java.rmi.registry.LocateRegistry;
10: import java.rmi.server.UnicastRemoteObject;
11:
12: import biz.hammurapi.metrics.RemoteSliceConsumer;
13: import biz.hammurapi.metrics.Slice;
14:
15: /**
16: * Simple remote slice consumer.
17: * Binds to //localhost/sliceConsumer. Creates RMI registry if necessary.
18: * Outputs to System.out.
19: * @author Pavel Vlasov
20: * @revision $Revision$
21: */
22: public class RemoteConsumer extends UnicastRemoteObject implements
23: RemoteSliceConsumer {
24:
25: public RemoteConsumer(int port, String bindName)
26: throws RemoteException, MalformedURLException {
27: try {
28: LocateRegistry.createRegistry(port);
29: System.out.println("RMI registry created");
30: } catch (Exception e) {
31: System.out.println("Connecting to RMI registry");
32: }
33:
34: String fullBindName = "//localhost:" + port + "/" + bindName;
35: Naming.rebind(fullBindName, this );
36: }
37:
38: public boolean consumeSlice(String category, Slice slice)
39: throws RemoteException {
40: System.out.println("[" + category + "] " + slice);
41: return true;
42: }
43:
44: public static void main(String[] args) throws Exception {
45: new RemoteConsumer(1099, "sliceConsumer");
46: }
47: }
|