Source code: com/fetish/directory/FadaProxy.java
1 package com.fetish.directory;
2
3 import net.jini.lease.*;
4 import net.jini.core.lease.*;
5 import net.jini.lookup.*;
6 import net.jini.core.lookup.*;
7 import net.jini.discovery.*;
8 import net.jini.core.discovery.*;
9 import net.jini.event.*;
10 import net.jini.core.event.*;
11 import net.jini.core.entry.Entry;
12 import java.rmi.*;
13 import java.io.*;
14 import com.fetish.directory.tool.*;
15
16 /**
17 * The proxy class for the FADA node.
18 */
19
20 public class FadaProxy implements java.io.Serializable, FadaInterface,
21 LUSManager, Directory {
22
23 Remote ref;
24 String url;
25 transient ServiceID id;
26 transient Directory dir;
27 transient LUSManager lusm;
28
29 private void writeObject( ObjectOutputStream o ) throws IOException {
30 o.writeObject( ( Object )this.ref );
31 o.writeObject( ( Object )this.url );
32 }
33
34 private void readObject( ObjectInputStream i ) throws IOException,
35 ClassNotFoundException {
36 this.ref = ( Remote )i.readObject();
37 this.url = ( String )i.readObject();
38 this.dir = ( Directory )ref;
39 this.lusm = ( LUSManager )ref;
40 this.id = lusm.getServiceID();
41 }
42
43 public FadaProxy() {
44 }
45
46 public FadaProxy( Remote ref, String url ) throws RemoteException {
47 this.ref = ref;
48 this.dir = ( Directory )ref;
49 this.lusm = ( LUSManager )ref;
50 this.id = null;
51 this.url = url;
52 }
53
54 public ServiceMatches lookup(
55 SearchCriteriaInterface criteria,
56 int nHops,
57 long timeout,
58 int maxResponses
59 ) throws java.rmi.RemoteException {
60 return dir.lookup( criteria, nHops, timeout, maxResponses );
61 }
62
63 /**
64 * Returns all services registered in this node.
65 */
66 public ServiceMatches getServices() throws RemoteException {
67 return dir.getServices();
68 }
69
70 public String getUrl() throws RemoteException {
71 return this.url;
72 }
73
74 public boolean lookup(
75 SearchCriteriaInterface criteria,
76 SearchIDInterface searchID,
77 String target,
78 String excluded,
79 int nHops,
80 long timeout,
81 int maxResponses
82 ) throws java.rmi.RemoteException {
83 return dir.lookup(
84 criteria,
85 searchID,
86 target,
87 excluded,
88 nHops,
89 timeout,
90 maxResponses
91 );
92 }
93
94
95 public void addLookupResult( SearchIDInterface id, ServiceMatches sm )
96 throws java.rmi.RemoteException {
97 dir.addLookupResult( id, sm );
98 }
99
100 public void startedSearches( SearchIDInterface id, int numSearches )
101 throws java.rmi.RemoteException {
102 dir.startedSearches( id, numSearches );
103 }
104
105 public ServiceRegistration register( ServiceItem item, long leaseDuration )
106 throws java.rmi.RemoteException {
107 // Fiddle with the ServiceItem
108 InterfaceEntry intEnt[] = InterfaceGetter.getInterfaces(
109 item.service.getClass()
110 );
111 Entry[] newEntries = new Entry[ item.attributeSets.length +
112 intEnt.length ];
113 for( int i = 0; i < item.attributeSets.length; i++ ) {
114 newEntries[ i ] = item.attributeSets[ i ];
115 }
116 for( int j = 0; j < intEnt.length; j++ ) {
117 newEntries[ item.attributeSets.length + j ] = intEnt[ j ];
118 }
119 item.attributeSets = newEntries;
120 return dir.register( item, leaseDuration );
121 }
122
123 public void unregister( ServiceID sid ) throws java.rmi.RemoteException {
124 dir.unregister( sid );
125 }
126
127 public EventRegistration notify(
128 ServiceTemplate tmpl,
129 int transitions,
130 RemoteEventListener listener,
131 MarshalledObject handback,
132 long leaseDuration
133 ) throws java.rmi.RemoteException {
134 return null;
135 }
136
137 public void setMaxTime( int maxTime ) throws RemoteException {
138 lusm.setMaxTime( maxTime );
139 }
140
141 public int getMaxTime() throws RemoteException {
142 return lusm.getMaxTime();
143 }
144
145 public ServiceID getServiceID() throws RemoteException {
146 return this.id;
147 }
148
149 public LookupLocator getLocator() throws java.rmi.RemoteException {
150 return lusm.getLocator();
151 }
152
153 public void isolate() throws RemoteException {
154 lusm.isolate();
155 }
156
157 public boolean isAlone() throws RemoteException {
158 return lusm.isAlone();
159 }
160
161 public boolean connect( LUSManager node ) throws RemoteException {
162 return lusm.connect( node );
163 }
164
165 public boolean justConnect( LUSManager node ) throws RemoteException {
166 return lusm.justConnect( node );
167 }
168
169 public boolean disconnect( LUSManager node ) throws RemoteException {
170 return lusm.disconnect( node );
171 }
172
173 public boolean justDisconnect( LUSManager node ) throws RemoteException {
174 return lusm.justDisconnect( node );
175 }
176
177 public boolean disconnect( String node ) throws RemoteException {
178 return lusm.disconnect( node );
179 }
180
181 public boolean justDisconnect( String node ) throws RemoteException {
182 return lusm.justDisconnect( node );
183 }
184
185 public LUSManager[] getNeighbors() throws RemoteException {
186 return lusm.getNeighbors();
187 }
188
189 public void setLease( Lease lease ) throws RemoteException {
190 ( ( FadaInterface )ref ).setLease( lease );
191 }
192
193 public void setServiceID( ServiceID id ) throws RemoteException {
194 this.id = id;
195 ( ( FadaInterface )ref ).setServiceID( id );
196 }
197
198 public void setRegistrar( String registrar )
199 throws RemoteException {
200 ( ( FadaInterface )ref ).setRegistrar( registrar );
201 }
202
203 public void stop( String passwd ) {
204 //System.out.println( "Stopping the node..." );
205 //try {
206 //lusm.stop( passwd );
207 //System.out.println( "Stopped" );
208 //this.ref = null;
209 //this.lusm = null;
210 //this.dir = null;
211 //} catch( Exception e ) {
212 //}
213 }
214
215 }