Project JXTA

net.jxta.protocol
Class PeerAdvertisement

java.lang.Object
  extended bynet.jxta.document.Advertisement
      extended bynet.jxta.document.ExtendableAdvertisement
          extended bynet.jxta.protocol.PeerAdvertisement
All Implemented Interfaces:
Cloneable

public abstract class PeerAdvertisement
extends ExtendableAdvertisement
implements Cloneable

This type of advertisement is generated when instantiating a group on a peer and contains all the parameters that services need to publish. It is then published within the the group.


Field Summary
protected  int modCount
          Counts the changes made to this object.
 
Constructor Summary
PeerAdvertisement()
           
 
Method Summary
 Object clone()
          Make a safe clone of this PeerAdvertisement.
static String getAdvertisementType()
          Returns the identifying type of this Advertisement.
 String getBaseAdvType()
          Returns the base type of this advertisement hierarchy. Typically, only the most basic advertisement of a type will implement this method and declare it as final.
 StructuredDocument getDesc()
          returns the description
 String getDescription()
          returns the description
 ID getID()
          Returns a unique ID for that peer X group intersection.
 int getModCount()
          Returns the number of times this object has been modified since it was created.
 String getName()
          returns the name of the peer.
 PeerGroupID getPeerGroupID()
          Returns the id of the peergroup this peer advertisement is for.
 PeerID getPeerID()
          Returns the id of the peer.
 StructuredDocument getServiceParam(ID key)
          Returns the parameter element that matches the given key from the service parameters table.
 Hashtable getServiceParams()
          Returns the sets of parameters for all services.
protected  int incModCount()
           
 void putServiceParam(ID key, Element param)
          Puts a service parameter in the service parameters table under the given key.
 StructuredDocument removeServiceParam(ID key)
          Removes and returns the parameter element that matches the given key from the service parameters table.
 void setDesc(Element desc)
          sets the description
 void setDescription(String description)
          sets the description
 void setName(String name)
          sets the name of the peer.
 void setPeerGroupID(PeerGroupID gid)
          Returns the id of the peergroup this peer advertisement is for.
 void setPeerID(PeerID pid)
          Sets the id of the peer.
 void setServiceParams(Hashtable params)
          sets the sets of parameters for all services.
 
Methods inherited from class net.jxta.document.ExtendableAdvertisement
getDocument, handleElement
 
Methods inherited from class net.jxta.document.Advertisement
getAdvType, getIndexFields, toString
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

modCount

protected volatile int modCount
Counts the changes made to this object. The API increments it every time some change is not proven to be idempotent. We rely on implementations to increment modCount every time something is changed without going through the API.

Constructor Detail

PeerAdvertisement

public PeerAdvertisement()
Method Detail

getModCount

public int getModCount()
Returns the number of times this object has been modified since it was created. This permits to detect local changes that require refreshing some other data.

Returns:
int the current modification count.

incModCount

protected int incModCount()

getAdvertisementType

public static String getAdvertisementType()
Returns the identifying type of this Advertisement.

Returns:
String the type of advertisement

getBaseAdvType

public final String getBaseAdvType()
Returns the base type of this advertisement hierarchy. Typically, only the most basic advertisement of a type will implement this method and declare it as final.

Specified by:
getBaseAdvType in class ExtendableAdvertisement
Returns:
String the base type of advertisements in this hierarchy.

clone

public Object clone()
Make a safe clone of this PeerAdvertisement.

Overrides:
clone in class Advertisement
Returns:
Object an object of class PeerAdvertisement that is a deep-enough copy of this one.

getName

public String getName()
returns the name of the peer.

Returns:
String name of the peer.
Since:
JXTA 1.0

setName

public void setName(String name)
sets the name of the peer.

Parameters:
name - name of the peer.
Since:
JXTA 1.0

getPeerID

public PeerID getPeerID()
Returns the id of the peer.

Returns:
PeerID the peer id
Since:
JXTA 1.0

setPeerID

public void setPeerID(PeerID pid)
Sets the id of the peer.

Parameters:
pid - the id of this peer.
Since:
JXTA 1.0

getPeerGroupID

public PeerGroupID getPeerGroupID()
Returns the id of the peergroup this peer advertisement is for.

Returns:
PeerGroupID the peergroup id
Since:
JXTA 1.0

setPeerGroupID

public void setPeerGroupID(PeerGroupID gid)
Returns the id of the peergroup this peer advertisement is for.

Parameters:
gid - The id of the peer.
Since:
JXTA 1.0

getID

public ID getID()
Returns a unique ID for that peer X group intersection. This is for indexing purposes only.

We return a composite ID that represents this peer is this group rather than in the platform, which is what the regular peerId shows.

May-be one day we'll want to name a peer differently in each group, exactly in this way. In the meantime we still need it to uniquely identify this adv.

FIXME 20020604 bondolo@jxta.org This is a total hack as it assumes the format of a group id. It's supposed to be opaque. The real answer is to use a unique value within each group.

Specified by:
getID in class Advertisement
Returns:
ID the composite ID
Since:
JXTA 1.0

getDescription

public String getDescription()
returns the description

Returns:
String the description

setDescription

public void setDescription(String description)
sets the description

Parameters:
description - the description
Since:
JXTA 1.0

getDesc

public StructuredDocument getDesc()
returns the description

Returns:
the description
Since:
JXTA 1.0

setDesc

public void setDesc(Element desc)
sets the description

Parameters:
desc - the description
Since:
JXTA 1.0

setServiceParams

public void setServiceParams(Hashtable params)
sets the sets of parameters for all services. This method first makes a deep copy, in order to protect the active information from uncontrolled sharing. This quite an expensive operation. If only a few of the parameters need to be added, it is wise to use putServiceParam() instead.

Parameters:
params - The whole set of parameters.
Since:
JXTA 1.0

getServiceParams

public Hashtable getServiceParams()
Returns the sets of parameters for all services. This method returns a deep copy, in order to protect the real information from uncontrolled sharing while keeping it shared as long as it is safe. This quite an expensive operation. If only a few parameters need to be accessed, it is wise to use getServiceParam() instead.

Returns:
Returns the sets of parameters for all services.
Since:
JXTA 1.0

putServiceParam

public void putServiceParam(ID key,
                            Element param)
Puts a service parameter in the service parameters table under the given key. The key is of a subclass of ID; usually a ModuleClassID. This method makes a deep copy of the given element into an independent document.

Parameters:
key - The key.
param - The parameter, as an element. What is stored is a copy as a stand alone StructuredDocument which type is the element's name.
Since:
JXTA 1.0

getServiceParam

public StructuredDocument getServiceParam(ID key)
Returns the parameter element that matches the given key from the service parameters table. The key is of a subclass of ID; usually a ModuleClassID.

Parameters:
key - The key.
Returns:
StructuredDocument The matching parameter document or null if none matched. The document type id "Param".
Since:
JXTA 1.0

removeServiceParam

public StructuredDocument removeServiceParam(ID key)
Removes and returns the parameter element that matches the given key from the service parameters table. The key is of a subclass of ID; usually a ModuleClassID.

Parameters:
key - The key.
Returns:
Element the removed parameter element or null if not found. This is actually a StructureDocument of type "Param".
Since:
JXTA 1.0

JXTA J2SE