com.notuvy.singleapp.multiuser
Class MultiUserSingleAppEnforcer

java.lang.Object
  extended by com.notuvy.singleapp.multiuser.GenericEnforcer
      extended by com.notuvy.singleapp.multiuser.MultiUserSingleAppEnforcer
All Implemented Interfaces:
Enforcer
Direct Known Subclasses:
MultiUserDefer, MultiUserPreempt

public abstract class MultiUserSingleAppEnforcer
extends GenericEnforcer
implements Enforcer

A utility that enforces the invocation of a single application instance.

Author:
murali

Field Summary
protected  BrokerConnection fClientConnection
           
protected  Map<String,BrokerConnection> fUserMap
           
protected static org.apache.log4j.Logger LOG
           
protected static int MSG_TYPE_DEFER_MESSAGE
           
protected static int MSG_TYPE_PING
           
protected static int MSG_TYPE_PREEMPT_ACK
           
protected static int MSG_TYPE_PREEMPT_MESSAGE
           
static String TEST_USER_NAME
           
 
Fields inherited from class com.notuvy.singleapp.multiuser.GenericEnforcer
fAllowSystemExit
 
Constructor Summary
protected MultiUserSingleAppEnforcer(int pPort, Runnable pRunnable)
           
 
Method Summary
protected  boolean alreadyHaveInstanceForUser(BrokerConnection pIncomingConnection)
           
 void attempt()
           
 int getPort()
           
protected  ServerSocket getServer()
           
 String getUser()
           
protected abstract  void handleConnection(Socket pSocket)
          When the first instance receives a socket connection, handle it.
protected  void handlePing()
           
protected abstract  void handlePortConflict()
          If a conflict with an existing broker happens, define how to proceed.
protected abstract  void handleRelayedMessage()
          Handle the message relayed from the broker.
protected  void reattempt()
           
protected  void setServer(ServerSocket pServer)
           
 void shutdownServer()
           
protected  void startBrokerClientListener(BrokerConnection pBrokerConnection, Runnable pListener)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LOG

protected static final org.apache.log4j.Logger LOG

MSG_TYPE_DEFER_MESSAGE

protected static final int MSG_TYPE_DEFER_MESSAGE
See Also:
Constant Field Values

MSG_TYPE_PREEMPT_MESSAGE

protected static final int MSG_TYPE_PREEMPT_MESSAGE
See Also:
Constant Field Values

MSG_TYPE_PREEMPT_ACK

protected static final int MSG_TYPE_PREEMPT_ACK
See Also:
Constant Field Values

MSG_TYPE_PING

protected static final int MSG_TYPE_PING
See Also:
Constant Field Values

TEST_USER_NAME

public static final String TEST_USER_NAME
See Also:
Constant Field Values

fUserMap

protected Map<String,BrokerConnection> fUserMap

fClientConnection

protected BrokerConnection fClientConnection
Constructor Detail

MultiUserSingleAppEnforcer

protected MultiUserSingleAppEnforcer(int pPort,
                                     Runnable pRunnable)
Method Detail

getPort

public int getPort()

getUser

public String getUser()

getServer

protected ServerSocket getServer()

setServer

protected void setServer(ServerSocket pServer)

reattempt

protected void reattempt()

alreadyHaveInstanceForUser

protected boolean alreadyHaveInstanceForUser(BrokerConnection pIncomingConnection)

handlePing

protected void handlePing()
                   throws IOException
Throws:
IOException

startBrokerClientListener

protected void startBrokerClientListener(BrokerConnection pBrokerConnection,
                                         Runnable pListener)

attempt

public void attempt()
Specified by:
attempt in interface Enforcer

handlePortConflict

protected abstract void handlePortConflict()
If a conflict with an existing broker happens, define how to proceed.


handleConnection

protected abstract void handleConnection(Socket pSocket)
When the first instance receives a socket connection, handle it.

Parameters:
pSocket - The socket with the new incoming connection.

handleRelayedMessage

protected abstract void handleRelayedMessage()
                                      throws IOException
Handle the message relayed from the broker.

Throws:
IOException

shutdownServer

public void shutdownServer()
Specified by:
shutdownServer in interface Enforcer


Copyright © 2012. All Rights Reserved.