SmartFrog 3.10.000

org.smartfrog.examples.dynamicwebserver.balancer
Class BalancerImpl

java.lang.Object
  extended by org.smartfrog.sfcore.reference.RemoteReferenceResolverHelperImpl
      extended by org.smartfrog.sfcore.prim.PrimImpl
          extended by org.smartfrog.examples.dynamicwebserver.balancer.BalancerImpl
All Implemented Interfaces:
java.rmi.Remote, Balancer, DataSource, MessageKeys, Diagnostics, Liveness, Prim, RemoteReferenceResolver, RemoteReferenceResolverHelper

public class BalancerImpl
extends PrimImpl
implements Prim, Balancer, DataSource

Title: BalancerImpl.

Description: BalancerImpl is the main class for a software load balancer for socket connections between a set of clients and a set of servers. The clients connect to a specific port on the balancer host and the balancer selects a server to handle the client session. The balancer opens a socket connection to the selected server and relays data between the client and the server. The balancer listens for client connections on a well-known port, specified by the "port" SmartFrog parameter.

The Balancer maintains a set of servers that are included in the selection algorithm for balancing. The curent selection algorithm is round-robin. An initial set of servers can be specified via the "hosts" SmartFrog parameter; if "hosts" is specified, the parameter "hostsPort" is used to specify the port number to connect to on the servers. Subsequent changes to the set of servers can be made at run-time via the Balancer remote interface; in this case the port number for each host can be specified individually.


Field Summary
 
Fields inherited from class org.smartfrog.sfcore.prim.PrimImpl
refLivenessDelay, refLivenessFactor, sfCompleteName, sfContext, sfDeployHooks, sfDeployWithHooks, sfExportRef, sfIsDeployed, sfIsStarted, sfIsTerminated, sfIsTerminating, sfLivenessCount, sfLivenessDelay, sfLivenessFactor, sfLivenessSender, sfParent, sfStartHooks, sfTerminateWithHooks, termLock
 
Fields inherited from interface org.smartfrog.examples.dynamicwebserver.balancer.Balancer
HOSTS, HOSTSPORT, LOGTO, NAME, PORT
 
Fields inherited from interface org.smartfrog.sfcore.common.MessageKeys
CANNOT_LINK_TO_PREDICATE, COMPONENT_TERMINATED, COPY_FAILED, COPY_SERIALIZE_FAILED, ERROR_NO_SECURITY_BUT_REQUIRED, ILLEGAL_BOOLEAN_PARAMETER, ILLEGAL_NUMERIC_PARAMETER, ILLEGAL_STRING_PARAMETER, ILLEGAL_VECTOR_PARAMETER, LIVENESS_SEND_FAILURE, LIVENESS_SEND_FAILURE_IN, MISSING_PARAMETER, MSG_CLASS_NOT_FOUND, MSG_CONNECT_ERR, MSG_CONT_OTHER_DEPLOY, MSG_DEPLOY_COMP_TERMINATED, MSG_DEPLOY_SUCCESS, MSG_DEPLOYWITH_PHASE_FAILED, MSG_DETACH_SUCCESS, MSG_DETACH_TERMINATE_SUCCESS, MSG_ERR_DEPLOY_FROM_URL, MSG_ERR_PARSE, MSG_ERR_RESOLVE_PHASE, MSG_ERR_SF_RUNNING, MSG_ERR_TERM, MSG_FAILED_INET_ADDRESS_LOOKUP, MSG_FAILED_TO_CONTACT_PARENT, MSG_FILE_NOT_FOUND, MSG_HOOK_ACTION_FAILED, MSG_ILLEGAL_ACCESS, MSG_ILLEGAL_CLASS_TYPE, MSG_ILLEGAL_CLASS_TYPE_EXPECTING_GOT, MSG_ILLEGAL_REFERENCE, MSG_INPUTSTREAM_NULL, MSG_INSTANTIATION_ERROR, MSG_INVALID_OBJECT_TYPE, MSG_INVOCATION_TARGET, MSG_LANG_NOT_FOUND, MSG_LIVENESS_START_FAILED, MSG_LOADING_URL, MSG_METHOD_NOT_FOUND, MSG_NON_REP_ATTRIB, MSG_NOT_COMPONENT_REFERENCE, MSG_NOT_FOUND_ATTRIBUTE, MSG_NOT_FOUND_REFERENCE, MSG_NOT_VALUE_REFERENCE, MSG_NULL_DEF_METHOD, MSG_NULL_URL, MSG_OBJECT_REGISTRATION_FAILED, MSG_PARENT_LOCATION_FAILED, MSG_PING_SUCCESS, MSG_RANDM_ERR, MSG_REMOTE_CONNECT_ERR, MSG_REPEATED_ATTRIBUTE, MSG_SF_DEAD, MSG_SF_READY, MSG_SF_TERMINATED, MSG_STACKTRACE_FOLLOWS, MSG_START_COMP_TERMINATED, MSG_TERMINATE_SUCCESS, MSG_UNHANDLED_EXCEPTION, MSG_UNKNOWN_HOST, MSG_UNRESOLVED_REFERENCE, MSG_UNRESOLVED_REFERENCE_IN, MSG_UPDATE_SUCCESS, MSG_URL_NOT_FOUND, MSG_URL_TO_PARSE_NOT_FOUND, MSG_WARNING_LIVENESS_ENABLED, MSG_WARNING_STACKTRACE_DISABLED, MSG_WARNING_STACKTRACE_ENABLED, ROOT_MUST_BE_COMPONENT, WARN_NO_SECURITY
 
Constructor Summary
BalancerImpl()
          Constructor for the Balancer component
 
Method Summary
 void addServer(java.lang.String hostname)
          Implementation of the Balancer interface
 void addServer(java.lang.String hostname, int port)
          Implementation of the Balancer interface
 int getData()
          implementation of DataSource interface resets the data after every request - so only suited to single requestor
static void main(java.lang.String[] args)
          Used to start the component from the command line.
 void removeServer(java.lang.String hostname)
          Implementation of the Balancer interface
 void sfDeploy()
          Standard sfDeploy().
 void sfStart()
          Standard sfStart().
 void sfTerminateWith(TerminationRecord tr)
          Standard sfTerminateWith()
 void stop()
          Stop the load balancer.
 java.lang.String toString()
          Returns textual representation.
 
Methods inherited from class org.smartfrog.sfcore.prim.PrimImpl
equals, hashCode, registerWithProcessCompound, sfAddAttribute, sfAttributeKeyFor, sfAttributes, sfCompleteName, sfCompleteNameSafe, sfContainsAttribute, sfContainsValue, sfContext, sfDeployedHost, sfDeployedProcessName, sfDeployWith, sfDetach, sfDetachAndTerminate, sfDiagnosticsReport, sfDumpState, sfExport, sfExportRef, sfExportRef, sfGetApplicationLog, sfGetCoreLog, sfGetLog, sfIsDeployed, sfIsRemote, sfIsStarted, sfIsTerminated, sfIsTerminating, sfLivenessFailure, sfLog, sfParent, sfParentageChanged, sfPing, sfRemoveAttribute, sfReplaceAttribute, sfResolve, sfResolve, sfResolveHere, sfResolveHere, sfResolveParent, sfSetLog, sfStartLivenessSender, sfStopLivenessSender, sfTerminate, sfTerminatedWith, sfTerminateQuietlyWith, sfValues, terminateComponent, terminateNotifying
 
Methods inherited from class org.smartfrog.sfcore.reference.RemoteReferenceResolverHelperImpl
sfResolve, sfResolve, sfResolve, sfResolve, sfResolve, sfResolve, sfResolve, sfResolve, sfResolve, sfResolve, sfResolve, sfResolve, sfResolve, sfResolve, sfResolve, sfResolve, sfResolve, sfResolve, sfResolve, sfResolve, sfResolve, sfResolve, sfResolve, sfResolve, sfResolve, sfResolve, sfResolve, sfResolve, sfResolve, sfResolve, sfResolve, sfResolve, sfResolve, sfResolve, sfResolve, sfResolve, sfResolve, sfResolve, sfResolve, sfResolve, sfResolve, sfResolve, sfResolve, sfResolveWithParser
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.smartfrog.sfcore.prim.Prim
sfAddAttribute, sfAttributeKeyFor, sfAttributes, sfCompleteName, sfContainsAttribute, sfContainsValue, sfContext, sfDeployedHost, sfDeployedProcessName, sfDeployWith, sfDetach, sfDetachAndTerminate, sfDumpState, sfIsDeployed, sfIsStarted, sfIsTerminated, sfIsTerminating, sfParent, sfParentageChanged, sfRemoveAttribute, sfReplaceAttribute, sfTerminate, sfTerminatedWith, sfTerminateQuietlyWith, sfValues
 
Methods inherited from interface org.smartfrog.sfcore.prim.Liveness
sfPing
 
Methods inherited from interface org.smartfrog.sfcore.reference.RemoteReferenceResolver
sfResolve, sfResolve, sfResolveHere, sfResolveHere, sfResolveParent
 
Methods inherited from interface org.smartfrog.sfcore.reference.RemoteReferenceResolverHelper
sfResolve, sfResolve, sfResolve, sfResolve, sfResolve, sfResolve, sfResolve, sfResolve, sfResolve, sfResolve, sfResolve, sfResolve, sfResolve, sfResolve, sfResolve, sfResolve, sfResolve, sfResolve, sfResolve, sfResolve, sfResolve, sfResolve, sfResolve, sfResolve, sfResolve, sfResolve, sfResolve, sfResolve, sfResolve, sfResolve, sfResolve, sfResolve, sfResolve, sfResolve, sfResolve, sfResolve, sfResolve, sfResolve, sfResolve, sfResolve, sfResolve, sfResolve, sfResolve, sfResolveWithParser
 
Methods inherited from interface org.smartfrog.sfcore.prim.Diagnostics
sfDiagnosticsReport
 

Constructor Detail

BalancerImpl

public BalancerImpl()
             throws java.rmi.RemoteException
Constructor for the Balancer component

Throws:
java.rmi.RemoteException - in case of Remote/network error
Method Detail

addServer

public void addServer(java.lang.String hostname,
                      int port)
Implementation of the Balancer interface

Specified by:
addServer in interface Balancer
Parameters:
hostname - The host name of the new server
port - The port number on the new server used open the connection from the balancer

addServer

public void addServer(java.lang.String hostname)
Implementation of the Balancer interface

Specified by:
addServer in interface Balancer
Parameters:
hostname - The host name of the new server

removeServer

public void removeServer(java.lang.String hostname)
Implementation of the Balancer interface

Specified by:
removeServer in interface Balancer
Parameters:
hostname - The host name of the server to remove from the set

getData

public int getData()
            throws java.rmi.RemoteException
implementation of DataSource interface resets the data after every request - so only suited to single requestor

Specified by:
getData in interface DataSource
Returns:
the number of connections since last request
Throws:
java.rmi.RemoteException - in case of Remote/network error

stop

public void stop()
Stop the load balancer.


main

public static void main(java.lang.String[] args)
Used to start the component from the command line.

Parameters:
args - command line arguments

toString

public java.lang.String toString()
Returns textual representation.

Overrides:
toString in class PrimImpl
Returns:
textual representation

sfDeploy

public void sfDeploy()
              throws SmartFrogException,
                     java.rmi.RemoteException
Standard sfDeploy().

Specified by:
sfDeploy in interface Prim
Overrides:
sfDeploy in class PrimImpl
Throws:
SmartFrogException - error while deploying
java.rmi.RemoteException - In case of network/rmi error

sfStart

public void sfStart()
             throws SmartFrogException,
                    java.rmi.RemoteException
Standard sfStart().

Specified by:
sfStart in interface Prim
Overrides:
sfStart in class PrimImpl
Throws:
SmartFrogException - error while starting
java.rmi.RemoteException - In case of network/rmi error

sfTerminateWith

public void sfTerminateWith(TerminationRecord tr)
Standard sfTerminateWith()

Overrides:
sfTerminateWith in class PrimImpl
Parameters:
tr - TerminationRecord object

SmartFrog CORE 3.10.000

(C) Copyright 1998-2006 Hewlett-Packard Development Company, LP