xmlBlaster 2.2.0 API

org.xmlBlaster.authentication
Class SubjectInfo

java.lang.Object
  extended by javax.management.NotificationBroadcasterSupport
      extended by org.xmlBlaster.authentication.SubjectInfo
All Implemented Interfaces:
javax.management.NotificationBroadcaster, javax.management.NotificationEmitter

public final class SubjectInfo
extends javax.management.NotificationBroadcasterSupport

The SubjectInfo stores all known data about a client.

It also contains a subject queue, where messages are stored until they are delivered at the next login of this client.

There are three states for SubjectInfo namely UNDEF, ALIVE, DEAD. A transition from UNDEF directly to DEAD is not supported. Transitions from ALIVE or DEAD to UNDEF are not possible.

Author:
Marcel Ruff

Field Summary
 int ALIVE
          State after calling toAlive()
private  Authenticate authenticate
           
private  boolean blockClientLogin
           
 CallbackAddress[] callbackAddressCache
           
private  ContextNode contextNode
           
 int DEAD
          State after calling shutdown()
private  boolean determineNodeId
           
private  DispatchStatistic dispatchStatistic
           
private  ServerScope glob
           
private static long instanceCounter
          Statistics
private  long instanceId
           
private  java.util.concurrent.locks.ReentrantLock lock
           
private static java.util.logging.Logger log
           
private  int maxSessions
           
private  JmxMBeanHandle mbeanHandle
          My JMX registration
private  java.lang.String ME
           
private  MsgErrorHandler msgErrorHandler
           
private  NodeId nodeId
           
private  QueueQueryPlugin queueQueryPlugin
          this is used for administrative gets (queries on callback queue)
private  I_Subject securityCtx
          The partner class from the security framework
private  SessionInfo[] sessionArrCache
           
private  java.util.Map<java.lang.String,SessionInfo> sessionMap
          All sessions of this subject are stored in this map.
private  long startupTime
          Incarnation time of this object instance in millis
private  int state
           
private  SubjectInfoProtector subjectInfoProtector
           
private  SessionName subjectName
          The cluster wide unique identifier of the subject e.g.
private  I_Queue subjectQueue
          All MsgUnit which can't be delivered to the client (if he is not logged in) are queued here and are delivered when the client comes on line.
 int UNDEF
          State during and after construction
 
Constructor Summary
SubjectInfo(ServerScope glob, Authenticate authenticate, SessionName subjectName)
          

 
Method Summary
 java.lang.String blockClientAndResetConnections()
           
 void checkNumberOfSessions(ConnectQosServer qos)
           
private  I_Queue createSubjectQueue(CbQueueProperty prop)
           
 void finalize()
          Shutdown my queue
 SessionInfo findSessionInfo(AddressBase addr)
          If you have a callback address and want to know to which session it belongs.
 long forwardToSessionQueue()
          Forward entries in subject queue to all session queues, if no entries are available we return 0 without doing anything.
private  int forwardToSessionQueue(MsgQueueEntry entry)
          Forward the given message to session queue.
 CallbackAddress[] getCallbackAddresses()
          Get the callback addresses for this subjectQueue, every session callback may have decided to receive subject messages
 ContextNode getContextNode()
          The unique name of this subject instance.
 int getCountSessionsInternal()
           
 int getCountSessionsUser()
           
 java.lang.String getCreationDate()
           
 SessionInfo getFirstSession()
           
 java.lang.String getId()
          Cluster wide unique identifier "/node/heron/client/" e.g.
 java.util.concurrent.locks.ReentrantLock getLock()
          Access the synchronization object of this SubjectInfo instance.
 java.lang.String getLoginName()
          Access the unique login name of a client.
(package private)  int getMaxSessions()
           
 I_MsgErrorHandler getMsgErrorHandler()
           
 NodeId getNodeId()
           
 javax.management.MBeanNotificationInfo[] getNotificationInfo()
          JMX: Enforced by interface NotificationBroadcasterSupport
 int getNumAliveSessions()
           
(package private)  int getNumSessions()
          Access the number of sessions of this user.
(package private)  long getNumUpdate()
          How many update where sent for this client, the sum of all session and subject queues of this clients.
(package private)  SessionInfo getOrCreateSessionInfo(SessionName sessionName, ConnectQosServer connectQos)
          Blocks for existing SessionInfo until it is initialized.
 I_Subject getSecurityCtx()
          Subject specific informations from the security framework
 SessionInfo getSession(SessionName sessionName)
          Find a session by its public session ID.
 SessionInfo getSessionByAbsoluteName(java.lang.String absoluteName)
          Find a session by its absolute name.
 SessionInfo getSessionByPublicId(long publicSessionId)
          Get the SessionInfo with its public session identifier e.g.
(package private)  I_AdminSession getSessionByPubSessionId(long pubSessionId)
          Find a session by its public session ID.
 SessionInfo getSessionInfo(SessionName sessionName)
          Find a session by its pubSessionId or return null if not found
(package private)  java.lang.String getSessionList()
          Access a list of public session identifier e.g.
 SessionInfo[] getSessions()
          Access the collection containing all SessionInfo objects of this user.
 SessionInfo[] getSessionsToClear(ConnectQosServer q)
          Check if client does a re-login and wants to destroy old sessions.
 java.lang.String getStateStr()
           
(package private)  SubjectInfoProtector getSubjectInfoProtector()
           
 SessionName getSubjectName()
          Access the unique login name of a client.
 I_Queue getSubjectQueue()
          This queue holds all messages which where addressed to destination loginName
 MsgUnit[] getSubjectQueueEntries(java.lang.String querySpec)
          Query the subject queue, can be peeking or consuming.
(package private)  long getSubjectQueueMaxMsgs()
           
(package private)  long getSubjectQueueNumMsgs()
           
(package private)  long getUptime()
           
 java.lang.String getUsageUrl()
          JMX
 boolean isAlive()
           
 boolean isBlockClientLogin()
           
 boolean isCluster()
           
 boolean isDead()
           
 boolean isLoggedIn()
          Is the client currently logged in?
 boolean isUndef()
           
(package private)  java.lang.String killClient()
          Kills all sessions of this client
 void notifyAboutLogin(SessionInfo sessionInfo)
          Get notification that the client did a login.
 void notifyAboutLogout(java.lang.String absoluteSessionName, boolean clearQueue, boolean forceShutdownEvenIfEntriesExist)
          Get notification that the client did a logout.
 java.lang.String[] peekSubjectMessages(int numOfEntries)
           
 java.lang.String[] peekSubjectMessagesToFile(int numOfEntries, java.lang.String path)
           
 void queueMessage(MsgQueueEntry entry)
          PtP mode: If the qos is set to forceQueuing the message is queued.
 java.lang.String setBlockClientLogin(boolean blockClient)
           
(package private)  void setMaxSessions(int max)
          JMX access.
 void setSecurityCtx(I_Subject securityCtx)
           
 void setSubjectQueueProperty(CbQueueProperty prop)
          Allows to overwrite queue property.
 void setUsageUrl(java.lang.String url)
           
 void shutdown(boolean clearQueue, boolean forceIfEntries)
          The shutdown is synchronized and checks if there is no need for this subject anymore.
 void toAlive(I_Subject securityCtx, CbQueueProperty prop)
          Initialize SubjectInfo
 java.lang.String toString()
           
 java.lang.String toXml()
          Dump state of this object into a XML ASCII string.
 java.lang.String toXml(java.lang.String extraOffset)
          Dump state of this object into a XML ASCII string.
 java.lang.String usage()
          JMX
 void waitUntilAlive(boolean returnLocked)
          if state==UNDEF we block until we are ALIVE (or DEAD)
 
Methods inherited from class javax.management.NotificationBroadcasterSupport
addNotificationListener, handleNotification, removeNotificationListener, removeNotificationListener, sendNotification
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

ME

private java.lang.String ME

glob

private final ServerScope glob

log

private static java.util.logging.Logger log

contextNode

private final ContextNode contextNode

authenticate

private final Authenticate authenticate

subjectName

private SessionName subjectName
The cluster wide unique identifier of the subject e.g. "/node/heron/client/joe"


securityCtx

private I_Subject securityCtx
The partner class from the security framework


blockClientLogin

private boolean blockClientLogin

sessionMap

private java.util.Map<java.lang.String,SessionInfo> sessionMap
All sessions of this subject are stored in this map. The absoluteSessionName == sessionInfo.getId() is the key, the SessionInfo object the value


sessionArrCache

private volatile SessionInfo[] sessionArrCache

callbackAddressCache

public CallbackAddress[] callbackAddressCache

msgErrorHandler

private MsgErrorHandler msgErrorHandler

dispatchStatistic

private final DispatchStatistic dispatchStatistic

subjectInfoProtector

private final SubjectInfoProtector subjectInfoProtector

nodeId

private NodeId nodeId

determineNodeId

private boolean determineNodeId

startupTime

private long startupTime
Incarnation time of this object instance in millis


maxSessions

private int maxSessions

UNDEF

public final int UNDEF
State during and after construction

See Also:
Constant Field Values

ALIVE

public final int ALIVE
State after calling toAlive()

See Also:
Constant Field Values

DEAD

public final int DEAD
State after calling shutdown()

See Also:
Constant Field Values

state

private int state

lock

private java.util.concurrent.locks.ReentrantLock lock

subjectQueue

private I_Queue subjectQueue
All MsgUnit which can't be delivered to the client (if he is not logged in) are queued here and are delivered when the client comes on line.

Node objects = MsgQueueEntry


queueQueryPlugin

private volatile QueueQueryPlugin queueQueryPlugin
this is used for administrative gets (queries on callback queue)


instanceCounter

private static long instanceCounter
Statistics


instanceId

private long instanceId

mbeanHandle

private JmxMBeanHandle mbeanHandle
My JMX registration

Constructor Detail

SubjectInfo

public SubjectInfo(ServerScope glob,
                   Authenticate authenticate,
                   SessionName subjectName)
            throws XmlBlasterException

Parameters:
subjectName - The unique loginName
securityCtx - The security context of this subject
prop - The property from the subject queue, usually from connectQos.getSubjectQueueProperty()
Throws:
XmlBlasterException
Method Detail

getContextNode

public final ContextNode getContextNode()
The unique name of this subject instance.

Returns:
Never null, for example "/xmlBlaster/node/heron/client/joe"

waitUntilAlive

public void waitUntilAlive(boolean returnLocked)
                    throws XmlBlasterException
if state==UNDEF we block until we are ALIVE (or DEAD)

Throws:
If - we are DEAD or on one minute timeout, subjectInfo is never locked in such a case
XmlBlasterException

getLock

public java.util.concurrent.locks.ReentrantLock getLock()
Access the synchronization object of this SubjectInfo instance.


getSubjectInfoProtector

SubjectInfoProtector getSubjectInfoProtector()

toAlive

public void toAlive(I_Subject securityCtx,
                    CbQueueProperty prop)
             throws XmlBlasterException
Initialize SubjectInfo

Parameters:
securityCtx - Can be null for PtP message with implicit SubjectInfo creation
prop - The property to configure the PtP message queue
Throws:
XmlBlasterException

createSubjectQueue

private I_Queue createSubjectQueue(CbQueueProperty prop)
                            throws XmlBlasterException
Throws:
XmlBlasterException

shutdown

public void shutdown(boolean clearQueue,
                     boolean forceIfEntries)
The shutdown is synchronized and checks if there is no need for this subject anymore.

clearQueue==false&&forceIfEntries==true: We shutdown and preserve existing PtP messages

Parameters:
clearQueue - Shall the message queue of the client be destroyed as well on last session logout?
forceIfEntries - Shutdown even if there are messages in the queue

finalize

public void finalize()
Shutdown my queue

Overrides:
finalize in class java.lang.Object

getOrCreateSessionInfo

SessionInfo getOrCreateSessionInfo(SessionName sessionName,
                                   ConnectQosServer connectQos)
                             throws XmlBlasterException
Blocks for existing SessionInfo until it is initialized. For new created SessionInfo you need to call sessionInfo.init()

Parameters:
sessionName -
connectQos -
Returns:
Throws:
XmlBlasterException

getSessionInfo

public SessionInfo getSessionInfo(SessionName sessionName)
Find a session by its pubSessionId or return null if not found


getNodeId

public final NodeId getNodeId()
                       throws XmlBlasterException
Returns:
not null if client is a cluster node, else null
Throws:
XmlBlasterException

isCluster

public boolean isCluster()
                  throws XmlBlasterException
Returns:
true if this client is an xmlBlaster cluster node
Throws:
XmlBlasterException

setSubjectQueueProperty

public final void setSubjectQueueProperty(CbQueueProperty prop)
                                   throws XmlBlasterException
Allows to overwrite queue property.

It will be only written if prop!= null.

Parameters:
prop - CbQueueProperty transports subject queue property as well TODO: we should have a clear named SubjectQueueProperty
Throws:
XmlBlasterException

getSubjectQueue

public I_Queue getSubjectQueue()
This queue holds all messages which where addressed to destination loginName

Returns:
never null

getSecurityCtx

public I_Subject getSecurityCtx()
Subject specific informations from the security framework

Returns:
null if created without login (for example with a PtP message)

setSecurityCtx

public void setSecurityCtx(I_Subject securityCtx)

queueMessage

public final void queueMessage(MsgQueueEntry entry)
                        throws XmlBlasterException
PtP mode: If the qos is set to forceQueuing the message is queued.

Parameters:
msgUnit - The message. Only called in sync mode on publish (TopicHandler)
destination - The Destination object of the receiver
Throws:
XmlBlasterException

forwardToSessionQueue

public final long forwardToSessionQueue()
Forward entries in subject queue to all session queues, if no entries are available we return 0 without doing anything.

Returns:
number of messages taken from queue and forwarded

forwardToSessionQueue

private final int forwardToSessionQueue(MsgQueueEntry entry)
                                 throws XmlBlasterException
Forward the given message to session queue.

Returns:
Number of session queues this message is forwarded to. -1 if not delivered because the available sessions don't want PtP
Throws:
XmlBlasterException - if not delivered at all.

getMsgErrorHandler

public final I_MsgErrorHandler getMsgErrorHandler()

isLoggedIn

public final boolean isLoggedIn()
Is the client currently logged in?

Returns:
true yes false client is not on line

getSessions

public final SessionInfo[] getSessions()
Access the collection containing all SessionInfo objects of this user.

Returns:
never null

getCountSessionsInternal

public final int getCountSessionsInternal()
Returns:
true it publicSessionId is given by xmlBlaster server (if < 0)

getCountSessionsUser

public final int getCountSessionsUser()
Returns:
true it publicSessionId is given by user/client (if > 0)

getSessionByAbsoluteName

public final SessionInfo getSessionByAbsoluteName(java.lang.String absoluteName)
Find a session by its absolute name.

Parameters:
absoluteName - e.g. "/node/heron/client/joe/2"
Returns:
SessionInfo or null if not found

getSession

public final SessionInfo getSession(SessionName sessionName)
Find a session by its public session ID.

Parameters:
sessionName -
Returns:
SessionInfo or null if not found

getFirstSession

public final SessionInfo getFirstSession()

getCallbackAddresses

public final CallbackAddress[] getCallbackAddresses()
Get the callback addresses for this subjectQueue, every session callback may have decided to receive subject messages


findSessionInfo

public final SessionInfo findSessionInfo(AddressBase addr)
If you have a callback address and want to know to which session it belongs.

Parameters:
addr - The address object
Returns:
the sessionInfo or null

checkNumberOfSessions

public final void checkNumberOfSessions(ConnectQosServer qos)
                                 throws XmlBlasterException
Throws:
Throws - XmlBlasterException if max. sessions is exhausted
XmlBlasterException

getSessionsToClear

public SessionInfo[] getSessionsToClear(ConnectQosServer q)
Check if client does a re-login and wants to destroy old sessions.

Returns:
never null

notifyAboutLogin

public final void notifyAboutLogin(SessionInfo sessionInfo)
                            throws XmlBlasterException
Get notification that the client did a login.

This instance may exist before a login was done, for example when some messages where directly addressed to this client.
This notifies about a client login.

Throws:
XmlBlasterException

notifyAboutLogout

public final void notifyAboutLogout(java.lang.String absoluteSessionName,
                                    boolean clearQueue,
                                    boolean forceShutdownEvenIfEntriesExist)
                             throws XmlBlasterException
Get notification that the client did a logout.
Note that the loginName is not reset.

Parameters:
absoluteSessionName - == sessionInfo.getId()
clearQueue - Shall the message queue of the client be cleared&destroyed as well (e.g. disconnectQos.deleteSubjectQueue())?
forceShutdownEvenIfEntriesExist - on last session
Throws:
XmlBlasterException

getSubjectName

public final SessionName getSubjectName()
Access the unique login name of a client.
If not known, its unique key (subjectId) is delivered

Returns:
The SessionName object specific for a subject (pubSessionId is null)

getId

public final java.lang.String getId()
Cluster wide unique identifier "/node/heron/client/" e.g. for logging

Returns:
e.g. "client/joe

toString

public final java.lang.String toString()
Overrides:
toString in class java.lang.Object
See Also:
getId()

getLoginName

public final java.lang.String getLoginName()
Access the unique login name of a client.
If not known, its unique key (subjectId) is delivered

Returns:
loginName

toXml

public final java.lang.String toXml()
Dump state of this object into a XML ASCII string.

Returns:
internal state of SubjectInfo as a XML ASCII string

toXml

public final java.lang.String toXml(java.lang.String extraOffset)
Dump state of this object into a XML ASCII string.

Parameters:
extraOffset - indenting of tags for nice output
Returns:
internal state of SubjectInfo as a XML ASCII string

getSessionByPublicId

public final SessionInfo getSessionByPublicId(long publicSessionId)
Get the SessionInfo with its public session identifier e.g. "5"

Returns:
null if not found

isUndef

public final boolean isUndef()

isAlive

public final boolean isAlive()

isDead

public final boolean isDead()

getStateStr

public final java.lang.String getStateStr()

getSubjectQueueEntries

public MsgUnit[] getSubjectQueueEntries(java.lang.String querySpec)
                                 throws XmlBlasterException
Query the subject queue, can be peeking or consuming.

Parameters:
querySpec - Can be configured to be consuming
Throws:
XmlBlasterException
See Also:
The engine.qos.queryspec.QueueQuery requirement

getUptime

long getUptime()
Returns:
startupTime in seconds

getCreationDate

public final java.lang.String getCreationDate()

getNumUpdate

long getNumUpdate()
How many update where sent for this client, the sum of all session and subject queues of this clients.


getSubjectQueueNumMsgs

long getSubjectQueueNumMsgs()

getSubjectQueueMaxMsgs

long getSubjectQueueMaxMsgs()

isBlockClientLogin

public boolean isBlockClientLogin()

setBlockClientLogin

public java.lang.String setBlockClientLogin(boolean blockClient)

blockClientAndResetConnections

public java.lang.String blockClientAndResetConnections()

getNumSessions

int getNumSessions()
Access the number of sessions of this user.

Returns:
The number of sessions of this user

getNumAliveSessions

public int getNumAliveSessions()

getMaxSessions

int getMaxSessions()
Returns:
The max allowed simultaneous logins of this user

setMaxSessions

void setMaxSessions(int max)
JMX access.

Parameters:
Change - the max allowed simultaneous logins of this user

getSessionList

java.lang.String getSessionList()
Access a list of public session identifier e.g. "1,5,7,12"

Returns:
An empty string if no sessions available

getSessionByPubSessionId

I_AdminSession getSessionByPubSessionId(long pubSessionId)
Find a session by its public session ID.

Parameters:
pubSessionId - e.g. "-2"
Returns:
I_AdminSession or null if not found

killClient

java.lang.String killClient()
                      throws XmlBlasterException
Kills all sessions of this client

Returns:
The list of killed sessions (public session IDs), in a human readable string
Throws:
XmlBlasterException

peekSubjectMessages

public java.lang.String[] peekSubjectMessages(int numOfEntries)
                                       throws XmlBlasterException
Throws:
XmlBlasterException

peekSubjectMessagesToFile

public java.lang.String[] peekSubjectMessagesToFile(int numOfEntries,
                                                    java.lang.String path)
                                             throws java.lang.Exception
Throws:
java.lang.Exception

usage

public java.lang.String usage()
JMX


getUsageUrl

public java.lang.String getUsageUrl()
JMX


setUsageUrl

public void setUsageUrl(java.lang.String url)

getNotificationInfo

public javax.management.MBeanNotificationInfo[] getNotificationInfo()
JMX: Enforced by interface NotificationBroadcasterSupport

Specified by:
getNotificationInfo in interface javax.management.NotificationBroadcaster
Overrides:
getNotificationInfo in class javax.management.NotificationBroadcasterSupport

xmlBlaster 2.2.0 API

Copyright © 1999-2014 The xmlBlaster.org contributers.