Package org.objectweb.joram.mom.dest
Class Destination
- java.lang.Object
-
- fr.dyade.aaa.agent.Agent
-
- org.objectweb.joram.mom.dest.Destination
-
- All Implemented Interfaces:
AgentMBean,Encodable,Serializable,DestinationMBean
public abstract class Destination extends Agent implements DestinationMBean
TheDestinationclass implements the common behavior of MOM destinations.- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description private static String[]_rightsprivate AgentIdadminIdIdentifier of the destination's administrator.protected Hashtable<AgentId,Integer>clientsTable of the destination readers and writers.private longcreationDatedate of creation.private static booleanDEBUGprivate booleandeletabletrueif the destination successfully processed a deletion request.protected AgentIddmqIdIdentifier of the dead message queue this destination must send its dead messages to, if any.protected booleanfreeReadingtrueif the READ access is granted to everybody.protected booleanfreeWritingtrueif the WRITE access is granted to everybody.private List<MessageInterceptor>interceptorsprivate List<Properties>interceptorsPropthe interceptors list.private static Loggerloggerprotected longnbMsgsDeliverSinceCreationprotected longnbMsgsSentToDMQSinceCreationprivate longperiodperiod to run task at regular interval: cleaning, load-balancing, etc.static IntegerREADREAD access value.static IntegerREADWRITEREAD and WRITE access value.private static longserialVersionUIDdefine serialVersionUID for interoperability, fix with 5.15.0 value.(package private) StringBufferstrbufTransientStringBufferused to build message, this buffer is created during agent initialization, then reused during the destination life.protected static booleanstrictCountersprotected WakeUpTasktaskprotected booleantemporarystatic IntegerWRITEWRITE access value.-
Fields inherited from class fr.dyade.aaa.agent.Agent
agentProfiling, emptyString, fixed, logmon
-
Fields inherited from interface fr.dyade.aaa.common.encoding.Encodable
BOOLEAN_ENCODED_SIZE, BYTE_ENCODED_SIZE, DOUBLE_ENCODED_SIZE, FLOAT_ENCODED_SIZE, INT_ENCODED_SIZE, LONG_ENCODED_SIZE, SHORT_ENCODED_SIZE
-
-
Constructor Summary
Constructors Modifier Constructor Description Destination()Empty constructor for newInstance().protectedDestination(String name, boolean fixed, int stamp)Constructor with parameters for fixing the destination and specifying its identifier.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description private voidaddInterceptor(String agentId, String agentName, Properties prop)voidagentFinalize(boolean last)Finalizes the agent before it is garbaged.protected voidagentInitialize(boolean firstTime)Gives this agent an opportunity to initialize after having been deployed, and each time it is loaded into memory.private booleancanBeDeleted()Returnstrueif the destination might be deleted.protected voidclientMessages(AgentId from, ClientMessages not)Method implementing the reaction to aClientMessagesnotification holding messages sent by a client.voiddecode(Decoder decoder)Decodes the object.voiddelete()Permits this agent to destroy itself.protected voiddeleteNot(AgentId from, DeleteNot not)Method implementing the reaction to aDeleteNotnotification requesting the deletion of the destination.protected abstract voiddoClientMessages(AgentId from, ClientMessages not, boolean throwsExceptionOnFullDest)protected abstract voiddoDeleteNot(DeleteNot not)protected abstract voiddoRightRequest(AgentId user, int right)This method is needed for right revocation.private voiddoSetPeriod(long period)protected abstract voiddoUnknownAgent(UnknownAgent not)voidencode(Encoder encoder)Encodes the object.protected abstract voidfinalize(boolean last)Finalizes the destination before it is garbaged.protected voidforward(AgentId to, Notification not)StringgetCreationDate()Returns this destination creation time through aStringof the form:dow mon dd hh:mm:ss zzz yyyy.longgetCreationTimeInMillis()Returns this destination creation time as a long.StringgetDestinationId()Returns the unique identifier of the destination.AgentIdgetDMQAgentId()StringgetDMQId()Return the unique identifier of DMQ set for this destination if any.intgetEncodedSize()Returns the size of the encoded object.protected Hashtable<String,Object>getJMXStatistics(String names)Returns values of all valid JMX attributes about the destination.private StringgetMBeanName()longgetNbMsgsDeliverSinceCreation()Returns the number of messages delivered since creation time of this destination.abstract longgetNbMsgsReceiveSinceCreation()Returns the number of messages received since creation time of this destination.longgetNbMsgsSentToDMQSinceCreation()Returns the number of erroneous messages forwarded to the DMQ since creation time of this destination..longgetPeriod()Returns the period value of this destination, -1 if not set.StringgetRight(String userid)Returns a string representation of rights set on this destination for a particular user.String[]getRights()Returns a string representation of the rights set on this destination.protected voidgetRights(AgentId from, GetRightsRequestNot not)Method implementing the reaction to aGetRightsRequestnotification requesting the rights about this destination.(package private) abstract PropertiesgetStats()abstract bytegetType()Returns the type of this destination: Queue or Topic.protected voidhandleAdminRequestNot(AgentId from, FwdAdminRequestNot not)protected voidhandleDeniedMessage(String msgId, AgentId replyTo)Method used to do specific actions when a message is denied because of a lack of rights.protected abstract voidinitialize(boolean firstTime)Initializes the destination.protected booleaninterceptorsAvailable()protected booleanisAdministrator(AgentId client)Checks the administering permission of a given client agent.booleanisFreeReading()Tests if this destination is free for reading.booleanisFreeWriting()Tests if this destination is free for writing.protected booleanisLocal(AgentId id)protected booleanisReader(AgentId client)Checks the reading permission of a given client agent.protected booleanisValidJMXAttribute(String attrName)This method allows to exclude some JMX attribute of getJMXStatistics method.protected booleanisWriter(AgentId client)Checks the writing permission of a given client agent.protected voidpostProcess(ClientMessages msgs)This method is needed to add processing after the standard handling.protected ClientMessagespreProcess(AgentId from, ClientMessages msgs)This method is needed to add processing before the standard handling.protected voidprocessAdminCommand(AdminCommandRequest request, AgentId replyTo, String requestMsgId)Proccess an admin command.protected MessageprocessInterceptors(Message msg)Run all defined interceptors on the message.protected PropertiesprocessPause(Properties prop)Pause / Resume the message distribution.protected voidprocessSetRight(AgentId user, int right)set user right.protected PropertiesprocessStartHandler(Properties prop)Start the acquisition queue/topic handler.protected PropertiesprocessStopHandler(Properties prop)Stop the acquisition queue/topic handler.voidreact(AgentId from, Notification not)Distributes the received notifications to the appropriate reactions.private voidreadObject(ObjectInputStream in)private voidremoveInterceptor(String classNames)private voidreplaceInterceptor(String agentId, String agentName, Properties prop)protected voidreplyToTopic(AdminReply reply, AgentId replyTo, String requestMsgId, String replyMsgId)protected voidrequestGroupNot(AgentId from, RequestGroupNot not)voidsetAdminId(AgentId adminId)Sets the administrator of the destination.voidsetFreeReading(boolean on)Sets theFreeReadingattribute for this destination.voidsetFreeWriting(boolean on)Sets theFreeWritingattribute for this destination.voidsetPeriod(long period)Sets or unsets the period for this destination.voidsetProperties(Properties prop, boolean firstTime)Sets the configuration of aDestination.protected voidsetRight(SetRight request, AgentId replyTo, String requestMsgId, String replyMsgId)Method implementing the reaction to aSetRightRequestnotification requesting rights to be set for a user.protected voidunknownAgent(AgentId from, UnknownAgent not)Method implementing the reaction to anUnknownAgentnotification.abstract voidwakeUpNot(WakeUpNot not)private voidwriteObject(ObjectOutputStream out)-
Methods inherited from class fr.dyade.aaa.agent.Agent
agentSave, delete, delete, deploy, deploy, doAdminSyncNotification, getAgentId, getCommitTime, getEncodableClassId, getId, getLogTopic, getName, getReactNb, getReactTime, hasName, incWorkInProgress, isAgentProfiling, isDeployed, isFixed, isUpdated, load, needToBeCommited, resetCommitTime, resetReactTime, resetTimer, save, sendTo, sendTo, sendTo, setAgentProfiling, setName, setNoSave, setSave, toString
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface fr.dyade.aaa.agent.AgentMBean
getAgentId, getCommitTime, getReactNb, getReactTime, isAgentProfiling, isFixed, resetCommitTime, resetReactTime, resetTimer, setAgentProfiling
-
Methods inherited from interface org.objectweb.joram.mom.dest.DestinationMBean
getName, toString
-
-
-
-
Field Detail
-
serialVersionUID
private static final long serialVersionUID
define serialVersionUID for interoperability, fix with 5.15.0 value. This value is identical in 5.15.0, 5.16.0, 5.16.3, 5.17 and next. It is different in 5.16.1 and 5.16.2 (and 5.17.0RC).- See Also:
- Constant Field Values
-
logger
private static final Logger logger
-
DEBUG
private static final boolean DEBUG
-
temporary
protected transient boolean temporary
-
deletable
private boolean deletable
trueif the destination successfully processed a deletion request.
-
period
private long period
period to run task at regular interval: cleaning, load-balancing, etc.
-
adminId
private AgentId adminId
Identifier of the destination's administrator. In any case the administration topics are authorized to handle the destination, this mechanism allows an other agent to get the same rights. In particular it is needed to allow user's proxy to handle temporary destinations.
-
task
protected transient WakeUpTask task
-
interceptorsProp
private List<Properties> interceptorsProp
the interceptors list.
-
interceptors
private transient List<MessageInterceptor> interceptors
-
freeReading
protected boolean freeReading
trueif the READ access is granted to everybody.
-
freeWriting
protected boolean freeWriting
trueif the WRITE access is granted to everybody.
-
READ
public static final Integer READ
READ access value.
-
WRITE
public static final Integer WRITE
WRITE access value.
-
READWRITE
public static final Integer READWRITE
READ and WRITE access value.
-
dmqId
protected AgentId dmqId
Identifier of the dead message queue this destination must send its dead messages to, if any.
-
strbuf
transient StringBuffer strbuf
TransientStringBufferused to build message, this buffer is created during agent initialization, then reused during the destination life.
-
creationDate
private long creationDate
date of creation.
-
strictCounters
protected static boolean strictCounters
-
nbMsgsDeliverSinceCreation
protected long nbMsgsDeliverSinceCreation
-
nbMsgsSentToDMQSinceCreation
protected long nbMsgsSentToDMQSinceCreation
-
_rights
private static String[] _rights
-
-
Constructor Detail
-
Destination
public Destination()
Empty constructor for newInstance().
-
Destination
protected Destination(String name, boolean fixed, int stamp)
Constructor with parameters for fixing the destination and specifying its identifier. Be careful, this constructor should only be used for destinations with well known stamps, it throws an exception otherwise.- Parameters:
name- Name of destination;fixed- If true, destination is fixed in memory.stamp- Specific stamp for resulting agent.
-
-
Method Detail
-
getType
public abstract byte getType()
Returns the type of this destination: Queue or Topic.- Specified by:
getTypein interfaceDestinationMBean- Returns:
- the type of this destination.
- See Also:
DestinationConstants.TOPIC_TYPE,DestinationConstants.QUEUE_TYPE,DestinationConstants.TEMPORARY
-
agentInitialize
protected void agentInitialize(boolean firstTime) throws ExceptionGives this agent an opportunity to initialize after having been deployed, and each time it is loaded into memory.- Overrides:
agentInitializein classAgent- Parameters:
firstTime- true when first called by the factory- Throws:
Exception- unspecialized exception
-
initialize
protected abstract void initialize(boolean firstTime) throws ExceptionInitializes the destination.- Parameters:
firstTime- true when first called by the factory- Throws:
Exception
-
agentFinalize
public void agentFinalize(boolean last)
Finalizes the agent before it is garbaged.- Overrides:
agentFinalizein classAgent- Parameters:
last- true if the destination is deleted
-
finalize
protected abstract void finalize(boolean last)
Finalizes the destination before it is garbaged.- Parameters:
last- true if the destination is deleted
-
getMBeanName
private final String getMBeanName()
-
getStats
abstract Properties getStats()
-
react
public void react(AgentId from, Notification not) throws Exception
Distributes the received notifications to the appropriate reactions.
-
doSetPeriod
private void doSetPeriod(long period)
-
setAdminId
public final void setAdminId(AgentId adminId)
Sets the administrator of the destination.- Parameters:
adminId- Identifier of the administrator of the destination.
-
setProperties
public void setProperties(Properties prop, boolean firstTime) throws Exception
Sets the configuration of aDestination. Be careful, this is done a first time beforeAgent.deploy(), so the agent is serialized and initialized afterwards.
After deployment, firstTime argument is set to false.- Parameters:
prop- The initial set of properties.- Throws:
Exception
-
isLocal
protected boolean isLocal(AgentId id)
-
canBeDeleted
private final boolean canBeDeleted()
Returnstrueif the destination might be deleted.
-
getPeriod
public long getPeriod()
Returns the period value of this destination, -1 if not set.- Specified by:
getPeriodin interfaceDestinationMBean- Returns:
- the period value of this destination; -1 if not set.
-
setPeriod
public void setPeriod(long period)
Sets or unsets the period for this destination.- Specified by:
setPeriodin interfaceDestinationMBean- Parameters:
period- The period value to be set or -1 for unsetting previous value (ignore 0).
-
wakeUpNot
public abstract void wakeUpNot(WakeUpNot not)
-
setRight
protected void setRight(SetRight request, AgentId replyTo, String requestMsgId, String replyMsgId)
Method implementing the reaction to aSetRightRequestnotification requesting rights to be set for a user.- Parameters:
request- ACLreplyTo- Identifier of the senderrequestMsgId- identifier of the requestreplyMsgId- identifier of the reply
-
doRightRequest
protected abstract void doRightRequest(AgentId user, int right)
This method is needed for right revocation. It allows to remove request or subscription from users no longer authorized.- Parameters:
user- The user about right modification.right- The right modification.
-
processSetRight
protected void processSetRight(AgentId user, int right) throws RequestException
set user right.- Throws:
RequestException
-
getRights
protected void getRights(AgentId from, GetRightsRequestNot not) throws AccessException
Method implementing the reaction to aGetRightsRequestnotification requesting the rights about this destination.- Throws:
AccessException- If the requester is not the administrator.
-
getRights
public String[] getRights()
Returns a string representation of the rights set on this destination.- Specified by:
getRightsin interfaceDestinationMBean- Returns:
- the rights set on this destination.
-
getRight
public String getRight(String userid)
Returns a string representation of rights set on this destination for a particular user. The user is pointed out by its unique identifier.- Specified by:
getRightin interfaceDestinationMBean- Parameters:
userid- The user's unique identifier.- Returns:
- the rights set on this destination.
-
isValidJMXAttribute
protected boolean isValidJMXAttribute(String attrName)
This method allows to exclude some JMX attribute of getJMXStatistics method. It must be overloaded in subclass.- Parameters:
attrName- name of attribute to test.- Returns:
- true if the attribute is a valid one.
-
getJMXStatistics
protected final Hashtable<String,Object> getJMXStatistics(String names)
Returns values of all valid JMX attributes about the destination.- Parameters:
names- A comma separated list of requested JMX attribute names.- Returns:
- a Hashtable containing the values of all valid JMX attributes about the destination. The keys are the name of corresponding attributes.
-
clientMessages
protected void clientMessages(AgentId from, ClientMessages not) throws AccessException
Method implementing the reaction to aClientMessagesnotification holding messages sent by a client.If the sender is not a writer on the destination the messages are sent to the DMQ and an exception is thrown. Otherwise, the processing of the received messages is performed in subclasses.
- Throws:
AccessException- If the sender is not a WRITER on the destination.
-
handleDeniedMessage
protected void handleDeniedMessage(String msgId, AgentId replyTo)
Method used to do specific actions when a message is denied because of a lack of rights.
-
unknownAgent
protected void unknownAgent(AgentId from, UnknownAgent not)
Method implementing the reaction to anUnknownAgentnotification.If the unknown agent is the DMQ, its identifier is set to null. If it is a client of the destination, it is removed. Specific processing is also done in subclasses.
-
deleteNot
protected void deleteNot(AgentId from, DeleteNot not)
Method implementing the reaction to aDeleteNotnotification requesting the deletion of the destination.The processing is done in subclasses if the sender is an administrator.
-
requestGroupNot
protected void requestGroupNot(AgentId from, RequestGroupNot not)
-
isReader
protected boolean isReader(AgentId client)
Checks the reading permission of a given client agent.- Parameters:
client- AgentId of the client requesting a reading permission.
-
isWriter
protected boolean isWriter(AgentId client)
Checks the writing permission of a given client agent.- Parameters:
client- AgentId of the client requesting a writing permission.
-
isAdministrator
protected boolean isAdministrator(AgentId client)
Checks the administering permission of a given client agent.- Parameters:
client- AgentId of the client requesting an admin permission.
-
doClientMessages
protected abstract void doClientMessages(AgentId from, ClientMessages not, boolean throwsExceptionOnFullDest) throws AccessException
- Throws:
AccessException
-
doUnknownAgent
protected abstract void doUnknownAgent(UnknownAgent not)
-
doDeleteNot
protected abstract void doDeleteNot(DeleteNot not)
-
delete
public void delete()
Description copied from class:AgentPermits this agent to destroy itself. If necessary, this method should be overloaded to work properly.- Specified by:
deletein interfaceAgentMBean- Specified by:
deletein interfaceDestinationMBean- Overrides:
deletein classAgent
-
preProcess
protected ClientMessages preProcess(AgentId from, ClientMessages msgs)
This method is needed to add processing before the standard handling. It is used in subclass ofQueueandTopic. The incoming messages can be modified or deleted during the processing.- Parameters:
from- The sender of the messagemsgs- The incoming messages.- Returns:
- The incoming messages after processing.
-
postProcess
protected void postProcess(ClientMessages msgs)
This method is needed to add processing after the standard handling. It is used in subclass ofQueueandTopic. The incoming messages can be modified or deleted during the processing.- Parameters:
msgs- The incoming messages.
-
writeObject
private void writeObject(ObjectOutputStream out) throws IOException
- Throws:
IOException
-
readObject
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException
- Throws:
IOExceptionClassNotFoundException
-
getDestinationId
public final String getDestinationId()
Returns the unique identifier of the destination.- Specified by:
getDestinationIdin interfaceDestinationMBean- Returns:
- the unique identifier of the destination.
-
isFreeReading
public boolean isFreeReading()
Tests if this destination is free for reading.- Specified by:
isFreeReadingin interfaceDestinationMBean- Returns:
- true if anyone can receive messages from this destination; false otherwise.
-
setFreeReading
public void setFreeReading(boolean on)
Sets theFreeReadingattribute for this destination.- Specified by:
setFreeReadingin interfaceDestinationMBean- Parameters:
on- if true anyone can receive message from this destination.
-
isFreeWriting
public boolean isFreeWriting()
Tests if this destination is free for writing.- Specified by:
isFreeWritingin interfaceDestinationMBean- Returns:
- true if anyone can send messages to this destination; false otherwise.
-
setFreeWriting
public void setFreeWriting(boolean on)
Sets theFreeWritingattribute for this destination.- Specified by:
setFreeWritingin interfaceDestinationMBean- Parameters:
on- if true anyone can send message to this destination.
-
getDMQId
public String getDMQId()
Return the unique identifier of DMQ set for this destination if any.- Specified by:
getDMQIdin interfaceDestinationMBean- Returns:
- the unique identifier of DMQ set for this destination if any; null otherwise.
-
getDMQAgentId
public AgentId getDMQAgentId()
-
getCreationTimeInMillis
public long getCreationTimeInMillis()
Returns this destination creation time as a long.- Specified by:
getCreationTimeInMillisin interfaceDestinationMBean- Returns:
- the destination creation time as UTC milliseconds from the epoch.
-
getCreationDate
public String getCreationDate()
Returns this destination creation time through aStringof the form:dow mon dd hh:mm:ss zzz yyyy.- Specified by:
getCreationDatein interfaceDestinationMBean- Returns:
- the destination creation time.
-
getNbMsgsReceiveSinceCreation
public abstract long getNbMsgsReceiveSinceCreation()
Returns the number of messages received since creation time of this destination.- Specified by:
getNbMsgsReceiveSinceCreationin interfaceDestinationMBean- Returns:
- the number of messages received since creation time.
-
getNbMsgsDeliverSinceCreation
public long getNbMsgsDeliverSinceCreation()
Returns the number of messages delivered since creation time of this destination. It includes messages all delivered messages to a consumer, already acknowledged or not.- Specified by:
getNbMsgsDeliverSinceCreationin interfaceDestinationMBean- Returns:
- the number of messages delivered since creation time.
-
getNbMsgsSentToDMQSinceCreation
public long getNbMsgsSentToDMQSinceCreation()
Returns the number of erroneous messages forwarded to the DMQ since creation time of this destination..- Specified by:
getNbMsgsSentToDMQSinceCreationin interfaceDestinationMBean- Returns:
- the number of erroneous messages forwarded to the DMQ.
-
replyToTopic
protected void replyToTopic(AdminReply reply, AgentId replyTo, String requestMsgId, String replyMsgId)
-
forward
protected final void forward(AgentId to, Notification not)
-
handleAdminRequestNot
protected void handleAdminRequestNot(AgentId from, FwdAdminRequestNot not)
- Parameters:
from-not-
-
processAdminCommand
protected void processAdminCommand(AdminCommandRequest request, AgentId replyTo, String requestMsgId)
Proccess an admin command.- Parameters:
request- The administration request.replyTo- The destination to reply.requestMsgId- The JMS message id needed to reply.
-
processStartHandler
protected Properties processStartHandler(Properties prop) throws Exception
Start the acquisition queue/topic handler.- Parameters:
prop- properties for start if needed (can be null)- Returns:
- properties for the reply.
- Throws:
Exception
-
processStopHandler
protected Properties processStopHandler(Properties prop) throws Exception
Stop the acquisition queue/topic handler.- Parameters:
prop- properties for start if needed (can be null)- Returns:
- properties for the reply.
- Throws:
Exception
-
processPause
protected Properties processPause(Properties prop) throws Exception
Pause / Resume the message distribution.- Parameters:
prop- properties for start if needed (can be null)- Returns:
- properties for the reply.
- Throws:
Exception
-
processInterceptors
protected Message processInterceptors(Message msg)
Run all defined interceptors on the message.- Parameters:
msg- the message- Returns:
- message potentially modified by the interceptors, null if an interceptor reject the message.
-
interceptorsAvailable
protected boolean interceptorsAvailable()
- Returns:
- true if interceptors set
-
addInterceptor
private void addInterceptor(String agentId, String agentName, Properties prop) throws Exception
- Throws:
Exception
-
removeInterceptor
private void removeInterceptor(String classNames) throws Exception
- Throws:
Exception
-
replaceInterceptor
private void replaceInterceptor(String agentId, String agentName, Properties prop) throws Exception
- Throws:
Exception
-
getEncodedSize
public int getEncodedSize() throws ExceptionDescription copied from class:AgentReturns the size of the encoded object.- Specified by:
getEncodedSizein interfaceEncodable- Overrides:
getEncodedSizein classAgent- Returns:
- the size of the encoded object
- Throws:
Exception- if an error occurs
-
encode
public void encode(Encoder encoder) throws Exception
Description copied from class:AgentEncodes the object.
-
-