int protoVersion; // protocol version int port; // port to contact java.lang.String[] groups; // groups of interest (e.g., printing) net.jini.core.lookup.ServiceID[] heard; // os servidores já conhecidos java.io.ByteArrayOutputStream byteStr = new java.io.ByteArrayOutputStream(); java.io.DataOutputStream objStr = new java.io.DataOutputStream(byteStr); objStr.writeInt(protoVersion); objStr.writeInt(port); objStr.writeInt(heard.length); for (int i = 0; i < heard.length; i++) { heard[i].writeBytes(objStr); } objStr.writeInt(groups.length); for (int i = 0; i < groups.length; i++) { objStr.writeUTF(groups[i]); } byte[] packetBody = byteStr.toByteArray(); // the final result
public class ServiceItem implements Serializable { public ServiceItem(ServiceID serviceID, Object service, Entry[] attributeSets) {...} public ServiceID serviceID; public Object service; public Entry[] attributeSets; }
public interface ServiceRegistrar { ServiceRegistration register(ServiceItem item, long leaseDuration) throws RemoteException;
Object lookup(ServiceTemplate tmpl) throws RemoteException;
ServiceMatches lookup(ServiceTemplate tmpl, int maxMatches) throws RemoteException; int TRANSITION_MATCH_NOMATCH = 1 << 0; int TRANSITION_NOMATCH_MATCH = 1 << 1; int TRANSITION_MATCH_MATCH = 1 << 2;
EventRegistration notify(ServiceTemplate tmpl, int transitions, RemoteEventListener listener, MarshalledObject handback, long leaseDuration) throws RemoteException;
Class[] getEntryClasses(ServiceTemplate tmpl) throws RemoteException;
Object[] getFieldValues(ServiceTemplate tmpl, int setIndex, String field) throws NoSuchFieldException, RemoteException;
Class[] getServiceTypes(ServiceTemplate tmpl, String prefix) throws RemoteException;
ServiceID getServiceID(); LookupLocator getLocator() throws RemoteException;
String[] getGroups() throws RemoteException; }
package net.jini.core.lease;
import java.rmi.RemoteException;
public interface Lease { long FOREVER = Long.MAX_VALUE; long ANY = -1;
int DURATION = 1; // os dois possíveis formatos da seriação
int ABSOLUTE = 2; // absolute dá problema se relógios não são sincronizados
long getExpiration(); void cancel() throws UnknownLeaseException, RemoteException; void renew(long duration) throws LeaseDeniedException, UnknownLeaseException, RemoteException; void setSerialFormat(int format);
int getSerialFormat(); LeaseMap createLeaseMap(long duration); // usado para renovações em batch
boolean canBatch(Lease lease); }