📄 endpointserviceinterface.java
字号:
/*
* Copyright (c) 2001 Sun Microsystems, Inc. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Sun Microsystems, Inc. for Project JXTA."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Sun", "Sun Microsystems, Inc.", "JXTA" and "Project JXTA" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact Project JXTA at http://www.jxta.org.
*
* 5. Products derived from this software may not be called "JXTA",
* nor may "JXTA" appear in their name, without prior written
* permission of Sun.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL SUN MICROSYSTEMS OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of Project JXTA. For more
* information on Project JXTA, please see
* <http://www.jxta.org/>.
*
* This license is based on the BSD license adopted by the Apache Foundation.
*
* $Id: EndpointServiceInterface.java,v 1.5 2001/10/23 23:16:21 lomax Exp $
*/
package net.jxta.impl.endpoint;
import net.jxta.service.Service;
import net.jxta.document.Advertisement;
import net.jxta.id.ID;
import net.jxta.endpoint.EndpointService;
import net.jxta.endpoint.Message;
import net.jxta.endpoint.EndpointAddress;
import net.jxta.endpoint.EndpointMessenger;
import net.jxta.endpoint.EndpointListener;
import net.jxta.endpoint.EndpointFilterListener;
import net.jxta.endpoint.EndpointProtocol;
import net.jxta.peergroup.PeerGroup;
import net.jxta.exception.PeerGroupException;
import java.util.Enumeration;
import java.io.*;
/**
* The EndpointService Service provides a frontend API and enviroment to all
* endpoint protocols.
*
* Tag $Name: STABLE_07082002 $
* @version $Revision: 1.5 $
* @since JXTA 1.0
*/
public class EndpointServiceInterface implements EndpointService {
EndpointServiceImpl theRealThing = null;
public EndpointServiceInterface(EndpointServiceImpl s) {
theRealThing = s;
}
/**
* Sort of absurd but this is part of the API we're implementing.
* We would do a two-level API just for that.
*/
public Service getInterface() {
return this;
}
/**
* Returns the group to which this EndpointServiceImpl is attached.
*
* @return PeerGroup the group.
*/
public PeerGroup getGroup() {
return theRealThing.getGroup();
}
/**
* Returns an enumeration of the endpoint protocols available to this
* endpoint service.
*
* @return Enumeration the enumeration.
*/
public Enumeration getEndpointProtocols() {
return theRealThing.getEndpointProtocols();
}
/**
* Returns a new Message object suitable for use with this endpoint
* service.
*
* @return Message the new message.
*/
public Message newMessage() {
return theRealThing.newMessage();
}
/**
* Builds an EndpointAddress out the the given URI string.
* The resulting EndpointAddress uniquely identifies a message listener
* at a given network address.
*
* @param Uri the uri. The structure of the Uri is as follows:
* protocol://address/[serviceName][/serviceParam]
*
*/
public EndpointAddress newEndpointAddress(String Uri) {
return theRealThing.newEndpointAddress (Uri);
}
/**
* Builds and returns an EndpointMessager that may be used to send
* messages via this endpoint to the given destination.
*
* @param addr the destination address. This address specifies an
* endpoint protocol, the address of a peer by that endpoint protocol, and
* a serviceName and serviceParam, the concatenation of which designates
* uniquely the listener to which the messages must be delivered on arrival.
* (see newEndpointAddress).
* @return EndpointMessenger the messenger.
*/
public EndpointMessenger getMessenger(EndpointAddress addr)
throws IOException {
return theRealThing.getMessenger(addr);
}
/**
* Propagates the given message through all the endpoint protocols that
* are available to this endpoint. Some or all of these endpoint protocols
* may silently drop the message. Each protocol may interpret the resquest
* for propagation differenly. The endpointService does not define which
* destinations the message will actually reach.
*
* The concatenation of the serviceName and serviceParam arguments
* uniquely designates the listener to which the message must be delivered
* on arrival.
*
* @param srcMsg the message to be propagated.
* @param serviceName a destination service name
* @param serviceParam a destination queue name within that service
* @param prunePeer specifies the PeerID of a peer that needs not
* receive the message. (This is just a hint).
*/
public void propagate(Message srcMsg,
String serviceName,
String serviceParam)
throws IOException
{
theRealThing.propagate(srcMsg, serviceName, serviceParam);
}
/**
* Registers an incoming messages listener.
* Each incoming message addressed to the queue specified by
* the given address will be passed to the given listener.
* The address is usually formed by concatenating the the name of the
* invoking service and a parameter unique to that service accross all
* groups (the group ID is normally included for that purpose).
*
* For a message to match this address, it must have been sent through
* an EndpointMessenger obtain by providing an EndpointAddress constructed
* with matching serviceName and serviceParam (see newEndpointAddress and
* getMessenger), or by invoking propagate with matching serviceName
* and serviceParam.
*
* If a listener is already registered with the given address, an
* IllegalArgumentException is thrown.
*
* @param address a queue name, unique accross all groups on this peer,
* @param listener a listener for these messages.
*/
public void addListener(String address, EndpointListener listener)
throws IllegalArgumentException
{
theRealThing.addListener(address, listener);
}
/**
* Removes the given listener previously registered under the given
* address.
*
* @return boolean true is there was such a registration, false otherwise.
*/
public boolean removeListener(String address, EndpointListener listener) {
return theRealThing.removeListener(address, listener);
}
public void addFilterListener(String address,
EndpointFilterListener listener,
boolean incoming)
throws IllegalArgumentException
{
theRealThing.addFilterListener(address, listener, incoming);
}
public void removeFilterListener(String address,
EndpointFilterListener listener,
boolean incoming)
{
theRealThing.removeFilterListener(address, listener, incoming);
}
/**
* Handles the given incoming message by calling the listener specified
* by its destination as returned by the getDestAddress() method of the
* message.
*
* If the message cannot be delivered an IOException is thrawn.
*
* @param msg The message to be delivered.
*/
public void demux(Message msg) throws IOException {
theRealThing.demux(msg);
}
/**
* Returns the endpoint protocol registered under the given name.
*
* @return EndpointProtocol the endpoint protocol if found. null otherwise.
*/
public EndpointProtocol getEndpointProtocolByName(String name) {
return theRealThing.getEndpointProtocolByName(name);
}
/**
* Verifies that the given address can be reached.
* The verification is performed by the endpoint protocol designated
* by the given address, as returned by the getEndpointProtocolName()
* method of this address.
*
* The method, and accuracy of the verification depends upon each endpoint
* protocol.
*
* @return boolean true if the address can be reached. False otherwise.
*/
public boolean ping(EndpointAddress addr) {
return theRealThing.ping(addr);
}
/**
* Installs the given endpoint protocol in this endpoint.
*
* The endpoint protocol becomes usable by the endpoint service to send
* unicast messages and optionaly propagation and ping messages. The
* endpoint service becomes usable by this protocol to handle incoming
* messages.
*
* If an endpoint protocol by the same name exists in one of the parent
* endpoint services, this protocol takes precedence and hides the other.
*
* If an endpoint protocol by that name exists in this endpoint service,
* addEndpoint Protocol fails and throws PeerGroupException.
*
* @param proto the endpoint protocol to be installed.
*/
public synchronized void addEndpointProtocol (EndpointProtocol proto)
throws IllegalArgumentException
{
// FIXME TOO: We should probably make the interface refuse to do it.
// But that will have to wait until we have criteria to decide who
// gets an interface object and who gets the real thing. In the
// meantime just do it.
theRealThing.addEndpointProtocol(proto);
}
/**
* Removes the given endpoint protocol from this endpoint service.
*
* protocols remove themselves from the list when stopped.
* If someone wants to remove a protocol from the list, it has to call
* stopApp explicitly if relevant. "If relevant" is not all that easy
* to figure out, since the same protocol object may be present in
* several groups. conclusion. Don't do it if you don't know what you're
* doing.
*
* @param proto the protocol to be removed.
*/
public synchronized void removeEndpointProtocol(EndpointProtocol proto)
{
// FIXME TOO: We should probably make the interface refuse to do it.
// But that will have to wait until we have criteria to decide who
// gets an interface object and who gets the real thing. In the
// meantime just do it.
theRealThing.removeEndpointProtocol(proto);
}
/**
* Initialize the application
* FIXME: This is meaningless for the interface object;
* it is there only to satisfy the requirements of the
* interface that we implement. Ultimately, the API should define
* two levels of interfaces: one for the real service implementation
* and one for the interface object. Right now it feels a bit heavy
* to so that since the only different between the two would be
* init() and may-be getName().
* @param group PeerGroup this application is started from
* @since JXTA 1.0
*/
public void init(PeerGroup pg, ID id, Advertisement ia) {
}
/**
* This is here for temporary class hierarchy reasons.
* it is ALWAYS ignored. By definition, the interface object
* protects the real object's start/stop methods from being called
*
* @param arg A table of strings arguments.
* @return int status indication.
*/
public int startApp(String[] arg) {
return 0;
}
/**
* This is here for temporary class hierarchy reasons.
* it is ALWAYS ignored. By definition, the interface object
* protects the real object's start/stop methods from being called
*
* This request is currently ignored.
*/
public void stopApp() {
}
/**
* Returns the advertisment for this service.
*
* @return Advertisement the advertisement.
*
* @since JXTA 1.0
*/
public Advertisement getImplAdvertisement() {
return theRealThing.getImplAdvertisement();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -