solar.service.pack
Class ScribePackService

java.lang.Object
  |
  +--solar.service.BaseService
        |
        +--solar.service.pack.ScribePackService
All Implemented Interfaces:
EventHandler, PackConstants, PackService, RequestHandler, RpcConstants, Service

public class ScribePackService
extends BaseService
implements PackService, RpcConstants, PackConstants

The PACK service that runs at the server side and is built on top of Scribe.

Version:
$Id: ScribePackService.java,v 1.35 2003/10/13 19:34:25 glchen Exp $
Author:
Guanling Chen

Nested Class Summary
(package private)  class ScribePackService.Forwarder
          Responsible to delivery events to children in multicast tree.
(package private)  class ScribePackService.Handler
          Responsible to delivery events to local subscribers only.
(package private)  class ScribePackService.RootTask
          Periodically update the (pubId, rootAddress) mapping.
(package private)  class ScribePackService.Sender
          Responsible to delivery events to attached clients only.
(package private)  class ScribePackService.SubscribeTask
          Periodically refresh the subscription in the Scribe network.
 
Field Summary
protected  RpcService _coreRpc
           
protected  TransportService _coreTransport
           
protected  Address _coreTransportAddress
           
protected  java.lang.String _coreTransportName
           
protected  DispatchService _dispatch
           
protected  java.lang.String _edgeTransportName
           
protected  EndPointManager _epman
           
protected  java.util.Hashtable _fakeids
           
protected  ForwardProtocol _fwdproto
           
protected  InputProtocol _inproto
           
protected static org.apache.log4j.Logger _log
          Logging facility.
protected  OutputProtocol _outproto
           
protected  java.lang.String _packName
           
protected  OutputProtocol _pubrootproto
           
protected  java.util.Hashtable _roottasks
           
protected  ScribeManager _scribeman
           
protected  java.util.Hashtable _scribeProxies
           
protected  java.util.Hashtable _scribeRoots
           
protected  OutputProtocol _subrootproto
           
protected  java.util.Hashtable _subtasks
           
protected  java.util.Timer _timer
           
 
Fields inherited from class solar.service.BaseService
_inited, _manager, _name
 
Fields inherited from interface solar.service.rpc.RpcConstants
RPC_BLOCK, RPC_HANDLER, RPC_REPLY, RPC_REQUEST, RPC_TIMEOUT
 
Fields inherited from interface solar.service.pack.PackConstants
PACK_ACK, PACK_BUFFER_LIMIT, PACK_EVENT, PACK_FORWARD, PACK_LASTHOP, PACK_MEMORY_LIMIT, PACK_POLICY, PACK_PUBID, PACK_SUBID, PACK_SUSPEND_LIMIT
 
Constructor Summary
ScribePackService()
           
 
Method Summary
private  void addFakeId(Id pubId, Id fakeId)
           
private  void addRootTask(Id id, ScribePackService.RootTask roottask)
           
private  void addScribeProxy(Id id, Address proxy)
           
private  void addScribeRoot(Id id, Address root)
           
private  void addSubscribeTask(Id pubId, Id subId, ScribePackService.SubscribeTask subtask)
           
 void attachPublisher(Id pubId, Publisher publisher)
          Attach a PACK publisher to the service.
 void attachSubscriber(Id subId, Subscriber subscriber)
          Attach a PACK subscriber to the service.
private  java.lang.Object callRpc(Address dest, Request request)
           
 void detachPublisher(Id pubId)
          Detach a PACK publisher from the service.
 void detachSubscriber(Id subId)
          Detach a PACK subscriber from the service.
protected  void doAttachPublisher(Id pubId, Id session, Address address, Publisher publisher)
           
protected  void doAttachSubscriber(Id subId, Id session, Address address, Subscriber subscriber)
           
protected  void doDetachPublisher(Id pubId)
           
protected  void doDetachSubscriber(Id subId)
           
protected  void doPublish(Id pubId, Event evt)
           
protected  void doSubscribe(Id pubId, Id subId, java.lang.Object policy)
           
private  java.util.Set getFakeIds(Id pubId)
           
private  Address getScribeProxy(Id id)
           
private  Address getScribeRoot(Id id)
           
 void handleEvent(Event evt)
          Processing an event.
protected  void handlePackEvent(PackEvent evt)
           
 java.lang.Object handleRequest(Request request)
          Processing a request.
protected  void handleSubscribeEvent(SubscribeEvent evt)
           
 void init()
          Initiate the service, do not try to init dependent services here.
 void initDependents()
          Initialize dependent services here.
private  boolean isLocal(Address dest)
          Is the specified address actually same as local address.
static Id makeFakeId(Id pubId, Id subId)
           
 Guid makeGuid(Id id)
          Return a global unique ID.
private  Id makeSession()
          Return a new session ID.
 void publish(Id pubId, Event evt)
          Publish an event to all subscribers.
private  void removeRootTask(Id id)
           
private  void removeScribeProxy(Id id)
           
private  void removeScribeRoot(Id id)
           
private  void removeSubscribeTask(Id subId)
           
private  void removeSubscribeTask(Id pubId, Id subId)
           
private  void sendToClient(Address dest, Event evt)
          Send an event to client using edge_transport.
private  boolean sendToParent(Id pubId, Event evt)
          Send an event to a topic's parent, return false if parent is null.
private  boolean sendToProxy(Id id, Event evt)
          Send an event to a topic's proxy, return false if proxy is local.
private  boolean sendToRoot(Id id, Event evt)
          Send an event to a topic's root, return false if root is local.
 void subscribe(Id pubId, Id subId, java.lang.Object policy)
          Make a subscription to a PACK publisher.
 
Methods inherited from class solar.service.BaseService
assertInited, getDependentService, getName, getServiceManager, handleDispatchUnit, handleEvent, hasInited, init, setInited, setName, setServiceManager, start, stop
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface solar.service.Service
getName, getServiceManager, handleDispatchUnit, hasInited, setName, setServiceManager, start, stop
 

Field Detail

_log

protected static org.apache.log4j.Logger _log
Logging facility.


_packName

protected java.lang.String _packName

_coreTransportName

protected java.lang.String _coreTransportName

_edgeTransportName

protected java.lang.String _edgeTransportName

_coreTransportAddress

protected Address _coreTransportAddress

_coreRpc

protected RpcService _coreRpc

_dispatch

protected DispatchService _dispatch

_coreTransport

protected TransportService _coreTransport

_scribeman

protected ScribeManager _scribeman

_scribeRoots

protected java.util.Hashtable _scribeRoots

_scribeProxies

protected java.util.Hashtable _scribeProxies

_inproto

protected InputProtocol _inproto

_outproto

protected OutputProtocol _outproto

_fwdproto

protected ForwardProtocol _fwdproto

_pubrootproto

protected OutputProtocol _pubrootproto

_subrootproto

protected OutputProtocol _subrootproto

_fakeids

protected java.util.Hashtable _fakeids

_epman

protected EndPointManager _epman

_timer

protected java.util.Timer _timer

_subtasks

protected java.util.Hashtable _subtasks

_roottasks

protected java.util.Hashtable _roottasks
Constructor Detail

ScribePackService

public ScribePackService()
Method Detail

init

public void init()
          throws ServiceException
Description copied from interface: Service
Initiate the service, do not try to init dependent services here.

Specified by:
init in interface Service
Overrides:
init in class BaseService
ServiceException

initDependents

public void initDependents()
                    throws ServiceException
Description copied from interface: Service
Initialize dependent services here.

Specified by:
initDependents in interface Service
Overrides:
initDependents in class BaseService
ServiceException

handleRequest

public java.lang.Object handleRequest(Request request)
                               throws java.lang.Exception
Description copied from interface: RequestHandler
Processing a request.

Specified by:
handleRequest in interface RequestHandler
Overrides:
handleRequest in class BaseService
java.lang.Exception

handleEvent

public void handleEvent(Event evt)
                 throws java.lang.Exception
Description copied from interface: EventHandler
Processing an event.

Specified by:
handleEvent in interface EventHandler
Overrides:
handleEvent in class BaseService
java.lang.Exception

handleSubscribeEvent

protected void handleSubscribeEvent(SubscribeEvent evt)
                             throws java.lang.Exception
java.lang.Exception

handlePackEvent

protected void handlePackEvent(PackEvent evt)
                        throws java.lang.Exception
java.lang.Exception

attachPublisher

public void attachPublisher(Id pubId,
                            Publisher publisher)
                     throws PackException
Description copied from interface: PackService
Attach a PACK publisher to the service.

Specified by:
attachPublisher in interface PackService
PackException

detachPublisher

public void detachPublisher(Id pubId)
                     throws PackException
Description copied from interface: PackService
Detach a PACK publisher from the service.

Specified by:
detachPublisher in interface PackService
PackException

attachSubscriber

public void attachSubscriber(Id subId,
                             Subscriber subscriber)
                      throws PackException
Description copied from interface: PackService
Attach a PACK subscriber to the service.

Specified by:
attachSubscriber in interface PackService
PackException

detachSubscriber

public void detachSubscriber(Id subId)
                      throws PackException
Description copied from interface: PackService
Detach a PACK subscriber from the service.

Specified by:
detachSubscriber in interface PackService
PackException

subscribe

public void subscribe(Id pubId,
                      Id subId,
                      java.lang.Object policy)
               throws PackException
Description copied from interface: PackService
Make a subscription to a PACK publisher.

Specified by:
subscribe in interface PackService
PackException

publish

public void publish(Id pubId,
                    Event evt)
             throws PackException
Description copied from interface: PackService
Publish an event to all subscribers.

Specified by:
publish in interface PackService
PackException

makeGuid

public Guid makeGuid(Id id)
Description copied from interface: PackService
Return a global unique ID.

Specified by:
makeGuid in interface PackService

makeFakeId

public static Id makeFakeId(Id pubId,
                            Id subId)

doAttachPublisher

protected void doAttachPublisher(Id pubId,
                                 Id session,
                                 Address address,
                                 Publisher publisher)

doDetachPublisher

protected void doDetachPublisher(Id pubId)
                          throws java.lang.Exception
java.lang.Exception

doAttachSubscriber

protected void doAttachSubscriber(Id subId,
                                  Id session,
                                  Address address,
                                  Subscriber subscriber)

doDetachSubscriber

protected void doDetachSubscriber(Id subId)
                           throws java.lang.Exception
java.lang.Exception

doSubscribe

protected void doSubscribe(Id pubId,
                           Id subId,
                           java.lang.Object policy)
                    throws PackException
PackException

doPublish

protected void doPublish(Id pubId,
                         Event evt)
                  throws PackException
PackException

callRpc

private java.lang.Object callRpc(Address dest,
                                 Request request)
                          throws java.lang.Exception
java.lang.Exception

isLocal

private boolean isLocal(Address dest)
Is the specified address actually same as local address.


sendToClient

private void sendToClient(Address dest,
                          Event evt)
                   throws java.lang.Exception
Send an event to client using edge_transport.

java.lang.Exception

sendToParent

private boolean sendToParent(Id pubId,
                             Event evt)
                      throws java.lang.Exception
Send an event to a topic's parent, return false if parent is null.

java.lang.Exception

sendToRoot

private boolean sendToRoot(Id id,
                           Event evt)
                    throws java.lang.Exception
Send an event to a topic's root, return false if root is local.

java.lang.Exception

sendToProxy

private boolean sendToProxy(Id id,
                            Event evt)
                     throws java.lang.Exception
Send an event to a topic's proxy, return false if proxy is local.

java.lang.Exception

makeSession

private Id makeSession()
Return a new session ID.


addRootTask

private void addRootTask(Id id,
                         ScribePackService.RootTask roottask)

removeRootTask

private void removeRootTask(Id id)

addSubscribeTask

private void addSubscribeTask(Id pubId,
                              Id subId,
                              ScribePackService.SubscribeTask subtask)

removeSubscribeTask

private void removeSubscribeTask(Id pubId,
                                 Id subId)

removeSubscribeTask

private void removeSubscribeTask(Id subId)

addScribeRoot

private void addScribeRoot(Id id,
                           Address root)

removeScribeRoot

private void removeScribeRoot(Id id)

getScribeRoot

private Address getScribeRoot(Id id)

addScribeProxy

private void addScribeProxy(Id id,
                            Address proxy)

removeScribeProxy

private void removeScribeProxy(Id id)

getScribeProxy

private Address getScribeProxy(Id id)

addFakeId

private void addFakeId(Id pubId,
                       Id fakeId)

getFakeIds

private java.util.Set getFakeIds(Id pubId)