Project JXTA

net.jxta.impl.endpoint
Class QuotaIncomingMessageListener

java.lang.Object
  extended bynet.jxta.impl.endpoint.QuotaIncomingMessageListener
All Implemented Interfaces:
EndpointListener

public class QuotaIncomingMessageListener
extends Object
implements EndpointListener

A wrapper around an EndpointListener which imposes fair sharing quotas.

NOTE: 20020526 jice There would be great value in making such an object the explicit interface between the endpoint and its clients, rather than a bland listener interface The client would have the ability to specify the threads limit, possibly setting it zero, and then could have access to the buffer. To implement that with a simple listener would mean that the endpoint has to TRUST the client that the listener does no-more than queuing and signaling or else, force a full and possibly redundant hand-shake in all cases, as is the case now. To be improved.


Nested Class Summary
(package private) static class QuotaIncomingMessageListener.ListenerThread
          The thread which services removing items from the queue
(package private) static class QuotaIncomingMessageListener.MessageFromSource
          An incoming message in the queue with its addresses and accounting
(package private) static class QuotaIncomingMessageListener.MyCacheListener
          A canonical mapping of all the message originators.
 
Field Summary
(package private) static int GmaxMsgSize
          Max guaranteed supported message size (bytes).
(package private) static int GmaxResPerSender
          Every sender account can over allocate up to 5 messages worth of queue size if the space is available.
(package private) static int GmaxSenders
          Max guaranteed senders (integer).
(package private) static int GminResPerSender
          Every sender account will always be granted 2 messages worth of queue size.
(package private) static int MaxExtraPerSender
          There is a limit to the amount of on-the-fly that a single sender can hog.
(package private) static int NeverReserved
          There is a part of the non-reserved resources that we will never use for reservation by senders in excess of GmaxSenders even if the number of accounts is way beyond the max garaunteed.
(package private) static int TotalExtra
          Additional resources in reserve, to be allocated on the fly.
 
Constructor Summary
QuotaIncomingMessageListener(String name, EndpointListener listener)
          Constructor for the QuotaIncomingMessageListener object
QuotaIncomingMessageListener(String name, EndpointListener listener, InboundMeter incomingMessageListenerMeter)
          Constructor for the QuotaIncomingMessageListener object
 
Method Summary
 void close()
          Close this listener and release all of its resources.
 QuotaIncomingMessageListener doOne()
          process one message and move on.
 EndpointListener getListener()
          Gets the listener attribute of the QuotaIncomingMessageListener object
 void processIncomingMessage(Message message, EndpointAddress srcAddr, EndpointAddress dstAddr)
          

Try to give a new thread for this message (this listener).

 String toString()
          

Returns our name

 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

GmaxMsgSize

static int GmaxMsgSize
Max guaranteed supported message size (bytes). This is a theoretical maximum message size and should reflect the maximum size of messages used in relevant protocols. All other calculations assume this as the "default" message size. If message size is very variable then this should be the median message size rather than the maximum.


GmaxSenders

static int GmaxSenders
Max guaranteed senders (integer). Expected number of message sources amongst whom resouces are to be shared.


GminResPerSender

static int GminResPerSender
Every sender account will always be granted 2 messages worth of queue size.


GmaxResPerSender

static int GmaxResPerSender
Every sender account can over allocate up to 5 messages worth of queue size if the space is available. If peers are very bursty with messages then this should be higher.


TotalExtra

static int TotalExtra
Additional resources in reserve, to be allocated on the fly. Available reservations beyond GminResPerSender are taken from there, so, we must have enough. This space is fairly shared by all senders who are over their minumum reserved allocation.


MaxExtraPerSender

static int MaxExtraPerSender
There is a limit to the amount of on-the-fly that a single sender can hog. If peers are very bursty with messages then this should be higher.


NeverReserved

static int NeverReserved
There is a part of the non-reserved resources that we will never use for reservation by senders in excess of GmaxSenders even if the number of accounts is way beyond the max garaunteed. Instead we'll prefer to grant 0 reserved items to additional senders.

Constructor Detail

QuotaIncomingMessageListener

public QuotaIncomingMessageListener(String name,
                                    EndpointListener listener)
Constructor for the QuotaIncomingMessageListener object

Parameters:
name - a unique name for this listener
listener - the recipient listener.

QuotaIncomingMessageListener

public QuotaIncomingMessageListener(String name,
                                    EndpointListener listener,
                                    InboundMeter incomingMessageListenerMeter)
Constructor for the QuotaIncomingMessageListener object

Parameters:
name - a unique name for this listener
listener - the recipient listener.
incomingMessageListenerMeter - metering handler.
Method Detail

toString

public String toString()

Returns our name


getListener

public EndpointListener getListener()
Gets the listener attribute of the QuotaIncomingMessageListener object

Returns:
The listener value

close

public void close()
Close this listener and release all of its resources.


doOne

public QuotaIncomingMessageListener doOne()
process one message and move on.


processIncomingMessage

public void processIncomingMessage(Message message,
                                   EndpointAddress srcAddr,
                                   EndpointAddress dstAddr)

Try to give a new thread for this message (this listener). Subsequently it will run other listenersaccording to what the dispatcher says.

Specified by:
processIncomingMessage in interface EndpointListener

JXTA J2SE