Package org.globus.net
Class BaseServer
- java.lang.Object
-
- org.globus.net.BaseServer
-
- All Implemented Interfaces:
java.lang.Runnable
- Direct Known Subclasses:
CallbackHandler,GassServer
public abstract class BaseServer extends java.lang.Object implements java.lang.RunnableThis class provides the basics for writing various servers. Note: Sockets created by this server have a 5 minute default timeout. The timeout can be changed using thesetTimeout()function.
-
-
Field Summary
Fields Modifier and Type Field Description protected java.net.ServerSocket_serverprotected booleanacceptprotected Authorizationauthorizationprotected org.ietf.jgss.GSSCredentialcredentialsprotected org.globus.net.AbstractServerDeactivatordeactivatorA handler for the deactivation framework.protected java.lang.IntegergssModestatic intSO_TIMEOUTSocket timeout in milliseconds.protected inttimeoutprotected java.lang.Stringurl
-
Constructor Summary
Constructors Constructor Description BaseServer()BaseServer(boolean secure, int port)BaseServer(int port)BaseServer(org.ietf.jgss.GSSCredential cred, int port)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description org.ietf.jgss.GSSCredentialgetCredentials()java.lang.StringgetHost()Returns hostname of this server.java.lang.StringgetHostname()Returns hostname of this serverintgetPort()Returns port of this serverjava.lang.StringgetProtocol()intgetTimeout()java.lang.StringgetURL()Returns url of this serverprotected abstract voidhandleConnection(java.net.Socket socket)This method needs to be implemented by subclasses.protected voidinitialize()This method should be called by all subclasses.voidregisterDefaultDeactivator()Registers a default deactivation handler.voidrun()voidsetAuthorization(Authorization auth)voidsetGssMode(java.lang.Integer mode)voidsetTimeout(int timeout)Sets timeout for the created sockets.voidshutdown()Stops the server but does not stop all the client threadsprotected voidstart()Starts the server.voidunregisterDefaultDeactivator()Unregisters a default deactivation handler.protected java.net.SocketwrapSocket(java.net.Socket socket)
-
-
-
Field Detail
-
SO_TIMEOUT
public static final int SO_TIMEOUT
Socket timeout in milliseconds.- See Also:
- Constant Field Values
-
accept
protected boolean accept
-
_server
protected java.net.ServerSocket _server
-
url
protected java.lang.String url
-
credentials
protected org.ietf.jgss.GSSCredential credentials
-
authorization
protected Authorization authorization
-
gssMode
protected java.lang.Integer gssMode
-
timeout
protected int timeout
-
deactivator
protected org.globus.net.AbstractServerDeactivator deactivator
A handler for the deactivation framework.
-
-
Constructor Detail
-
BaseServer
public BaseServer() throws java.io.IOException- Throws:
java.io.IOException
-
BaseServer
public BaseServer(int port) throws java.io.IOException- Throws:
java.io.IOException
-
BaseServer
public BaseServer(org.ietf.jgss.GSSCredential cred, int port) throws java.io.IOException- Throws:
java.io.IOException
-
BaseServer
public BaseServer(boolean secure, int port) throws java.io.IOException- Throws:
java.io.IOException
-
-
Method Detail
-
initialize
protected void initialize()
This method should be called by all subclasses.
-
start
protected void start()
Starts the server.
-
setTimeout
public void setTimeout(int timeout)
Sets timeout for the created sockets. By default if not set, 5 minute timeout is used.
-
getTimeout
public int getTimeout()
-
shutdown
public void shutdown()
Stops the server but does not stop all the client threads
-
getCredentials
public org.ietf.jgss.GSSCredential getCredentials()
-
getProtocol
public java.lang.String getProtocol()
-
getURL
public java.lang.String getURL()
Returns url of this server- Returns:
- url of this server
-
getPort
public int getPort()
Returns port of this server- Returns:
- port number
-
getHostname
public java.lang.String getHostname()
Returns hostname of this server- Returns:
- hostname
-
getHost
public java.lang.String getHost()
Returns hostname of this server. The format of the host conforms to RFC 2732, i.e. for a literal IPv6 address, this method will return the IPv6 address enclosed in square brackets ('[' and ']').- Returns:
- hostname
-
run
public void run()
- Specified by:
runin interfacejava.lang.Runnable
-
wrapSocket
protected java.net.Socket wrapSocket(java.net.Socket socket) throws org.ietf.jgss.GSSException- Throws:
org.ietf.jgss.GSSException
-
setGssMode
public void setGssMode(java.lang.Integer mode)
-
setAuthorization
public void setAuthorization(Authorization auth)
-
handleConnection
protected abstract void handleConnection(java.net.Socket socket)
This method needs to be implemented by subclasses. Optimmaly, it should be a non-blocking call starting a separate thread to handle the client. Note that to start an SSL handshake, you need to call socket.getInput(Output) stream().
-
registerDefaultDeactivator
public void registerDefaultDeactivator()
Registers a default deactivation handler. It is used to shutdown the server without having a reference to the server. Call Deactivate.deactivateAll() to shutdown all registered servers.
-
unregisterDefaultDeactivator
public void unregisterDefaultDeactivator()
Unregisters a default deactivation handler.
-
-