Platform SDK Java 8.5 API Reference

com.genesyslab.platform.commons.protocol
Class ServerChannel

java.lang.Object
  extended by com.genesyslab.platform.commons.protocol.AbstractChannel
      extended by com.genesyslab.platform.commons.protocol.ServerChannel
All Implemented Interfaces:
AsyncChannel, AsyncInvokerSupport, Channel, ChannelListenerSupport, ConfigurationSupport, ConnectionInvokerSupport, EndpointSupport, OutputChannel, ProtocolDescriptionSupport, Receiver, ReceiverManagement, RequestReceiver, RequestReceiverManagement, ResponseChannel
Direct Known Subclasses:
CallbackProtocolListener, ChatProtocolsListener, ConfServerProtocolListener, EmailProtocolListener, EspEmailProtocolListener, ExternalServiceProtocolListener, InteractionServerProtocolListener, UniversalContactServerProtocolListener, UrsCustomProtocolListener

public class ServerChannel
extends AbstractChannel
implements OutputChannel, ResponseChannel, RequestReceiver, EndpointSupport, ConfigurationSupport, ProtocolDescriptionSupport, RequestReceiverManagement

This channel accepts client connections on given local Endpoint.
Method AbstractChannel.addChannelListener(ChannelListener) accepts ServerChannelListener, which provides notifications on incoming clients. When a new client connection is established onClientChannelOpened() method is notified.
By default, if no protocol name option is specified, Server Channel adds ADDP support for incoming connections. The AddpInterceptor.ACTIVE_KEY option is always set to false, because ADDP is to be initialized by client side.

Specific protocols may extend this class adding own customization and specifications.

See Also:
ExternalServiceProtocolListener, InteractionServerProtocolListener, ChatProtocolsListener

Nested Class Summary
 
Nested classes/interfaces inherited from class com.genesyslab.platform.commons.protocol.AbstractChannel
AbstractChannel.AsyncErrorNotifier
 
Field Summary
 
Fields inherited from interface com.genesyslab.platform.commons.protocol.Channel
DEFAULT_TIMEOUT, INFINITE_TIMEOUT
 
Fields inherited from interface com.genesyslab.platform.commons.protocol.Receiver
DEF_INPUT_SIZE
 
Constructor Summary
ServerChannel(Endpoint endpoint, java.lang.Class<T> clientChannelClass)
          Deprecated.  
ServerChannel(Endpoint endpoint, ClientChannelHandlerFactory clientChannelHandlerFactory)
          Creates ServerChannel instance to accept and handle incoming clients connections on the given Endpoint.
ServerChannel(Endpoint endpoint, long timeout, ProtocolFactory protocolFactory)
          The old style constructor for ServerChannel instance creation.
ServerChannel(Endpoint endpoint, ProtocolFactory protocolFactory)
          The old style constructor for ServerChannel instance creation.
 
Method Summary
 void addListener(OutputChannelListener listener)
          Attaches listener to OutputChannel implementer instance.
protected  void applyConfiguration()
           
 void beginClose()
          Method is asynchronous.
 void beginOpen()
          Method is asynchronous.
 void clearInput()
          Clears input of the receiver.
 void close()
          Closes listening socket and all its active clients connections.
 void close(long timeout)
          Closes listening socket and all its active clients connections.
 void closeClientChannels()
          Closes all connected client's channels, but the server socket remains in listening mode.
 void closeListener()
          Closes listening socket only, sets channel state to Closed.
 java.util.Collection<? extends Channel> getChannels()
           
 int getInputSize()
          Returns the amount of messages this Receiver can hold before start to "forget stale messages".
 java.net.InetSocketAddress getLocalEndPoint()
          Gets local address of the listening socket.
 ProtocolDescription getProtocolDescription()
           
protected  ProtocolFactory getProtocolFactory()
           
protected  void modifyNewChannel(DuplexChannel channel)
          This method modifies the new channel to support server mode of operation suggested by ServerChannel.
 void open()
          Opens channel synchronously.
 void open(long timeout)
          Opens channel synchronously.
 Message receive()
           
 Message receive(long timeout)
           
 RequestContext receiveRequest()
          Receives request from the client.
 RequestContext receiveRequest(long timeout)
          Receives request from the client.
 void releaseReceivers()
          Notifies receivers (threads waiting on receive() methods) they should stop waiting and return null.
 void removeListener(OutputChannelListener listener)
          Detaches listener from OutputChannel implementer instance.
 void resetReceiver()
          Resets the clients requests receiver.
 void send(Message message)
          Sends the given protocol message to all connected clients channels of this ServerChannel.
protected  void sendToChannelsExcept(java.util.Collection<OutputChannel> channels, Message message, OutputChannel except)
          Sends message to all channels in the collection except the one.
 void sendToChannelsExcept(Message message, OutputChannel except)
          Sends message to all channels except the one.
 void setClientRequestHandler(ClientRequestHandler handler)
          ServerChannel calls the handler on each new incoming message.
While the handler is assigned the receiver (external or internal) is ignored.
 void setInputSize(int inputSize)
          Sets the amount of messages this Receiver can hold before start to "forget stale messages".
 void setReceiver(RequestReceiverSupport receiver)
          Deprecated.  
 
Methods inherited from class com.genesyslab.platform.commons.protocol.AbstractChannel
addChannelListener, configure, connectionContext, copyTLSSettings, createChannelClosedEvent, fireClosed, fireErrorEvent, fireErrorEvent, generateChannelId, getChannelId, getConfiguration, getDefaultInvoker, getEndpoint, getEnpointPrefixInfo, getInvoker, getListenerHelper, getLocalEndpointInfo, getServerContext, getState, getStateMods, getTimeout, internal, onFireClosed, onFireErrorEvent, onFireOpened, onSetEndpoint, releaseDefaultInvoker, removeChannelListener, setConfiguration, setConnectionInvoker, setEndpoint, setInvoker, setServerContext, setState, setState, setTimeout, throwNotClosed, throwNotOpened, throwNotOpenedOnClose, throwNotOpenedOnSend, throwNull, throwNullEndpoint
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.genesyslab.platform.commons.protocol.Channel
getTimeout, setTimeout
 
Methods inherited from interface com.genesyslab.platform.commons.protocol.AsyncChannel
getState
 
Methods inherited from interface com.genesyslab.platform.commons.protocol.ChannelListenerSupport
addChannelListener, removeChannelListener
 
Methods inherited from interface com.genesyslab.platform.commons.protocol.EndpointSupport
getEndpoint, setEndpoint
 
Methods inherited from interface com.genesyslab.platform.commons.protocol.ConfigurationSupport
configure, getConfiguration
 

Constructor Detail

ServerChannel

public ServerChannel(Endpoint endpoint,
                     ProtocolFactory protocolFactory)
The old style constructor for ServerChannel instance creation.

Parameters:
endpoint - the local Endpoint to accept connections on.
protocolFactory - the specific protocol factory.
See Also:
ServerChannel(Endpoint, ClientChannelHandlerFactory)

ServerChannel

public ServerChannel(Endpoint endpoint,
                     ClientChannelHandlerFactory clientChannelHandlerFactory)
Creates ServerChannel instance to accept and handle incoming clients connections on the given Endpoint.

Parameters:
endpoint - the local Endpoint to accept connections on.
clientChannelHandlerFactory - the factory of handlers for clients connections.

ServerChannel

@Deprecated
public ServerChannel(Endpoint endpoint,
                                java.lang.Class<T> clientChannelClass)
Deprecated. 

This temporary constructor is not recommended for usage.
It was provided as a staging solution and it is not able to handle all the protocols needs.
Its going to be removed in the next major release.

See Also:
ServerChannel(Endpoint, ClientChannelHandlerFactory)

ServerChannel

public ServerChannel(Endpoint endpoint,
                     long timeout,
                     ProtocolFactory protocolFactory)
The old style constructor for ServerChannel instance creation.

Parameters:
endpoint - the local Endpoint to accept connections on.
timeout - the protocol timeout value for the server channel.
protocolFactory - the specific protocol factory.
See Also:
ServerChannel(Endpoint, ClientChannelHandlerFactory)
Method Detail

getLocalEndPoint

public java.net.InetSocketAddress getLocalEndPoint()
Gets local address of the listening socket.

Returns:
local address of the listening socket.

open

public void open()
          throws ProtocolException,
                 java.lang.InterruptedException,
                 ChannelNotClosedException
Opens channel synchronously.

Specified by:
open in interface Channel
Throws:
ChannelNotClosedException - when channel isn't closed
RegistrationException - if there is an error related to registration procedure like server error about wrong client name, user password, etc
ProtocolException - if there is any problem related to the connection open
java.lang.InterruptedException
See Also:
Channel.setTimeout(long), Channel.open(long)

open

public void open(long timeout)
          throws ProtocolException,
                 java.lang.InterruptedException,
                 ChannelNotClosedException
Opens channel synchronously.

Specified by:
open in interface Channel
Parameters:
timeout - timeout in milliseconds
Throws:
ChannelNotClosedException - when channel isn't closed
RegistrationException - if there is an error related to registration procedure like server error about wrong client name, user password, etc
ProtocolException - if there is any problem related to the connection open
java.lang.InterruptedException
See Also:
Channel.open()

close

public void close()
           throws ProtocolException,
                  java.lang.InterruptedException,
                  java.lang.IllegalStateException
Closes listening socket and all its active clients connections.

Specified by:
close in interface Channel
Throws:
ProtocolException - exception will not be thrown in current implementation.
java.lang.InterruptedException - in case the close operation was interrupted.
java.lang.IllegalStateException - exception will not be thrown in current implementation.

close

public void close(long timeout)
           throws ProtocolException,
                  java.lang.InterruptedException,
                  java.lang.IllegalStateException
Closes listening socket and all its active clients connections.

Specified by:
close in interface Channel
Parameters:
timeout - currently not used.
Throws:
ProtocolException - exception will not be thrown in current implementation.
java.lang.InterruptedException - in case the close operation was interrupted.
java.lang.IllegalStateException - exception will not be thrown in current implementation.

closeListener

public void closeListener()
                   throws ProtocolException,
                          java.lang.InterruptedException,
                          java.lang.IllegalStateException
Closes listening socket only, sets channel state to Closed. States of client connections are not changed. Use close() to close it all, or closeClientChannels() to close clients connections separately.

Throws:
ProtocolException - exception will not be thrown in current implementation.
java.lang.InterruptedException - in case the close operation was interrupted.
java.lang.IllegalStateException - exception will not be thrown in current implementation.

closeClientChannels

public void closeClientChannels()
                         throws java.lang.InterruptedException
Closes all connected client's channels, but the server socket remains in listening mode.

Throws:
java.lang.InterruptedException - in case the close operation was interrupted.

send

public void send(Message message)
          throws ProtocolException
Sends the given protocol message to all connected clients channels of this ServerChannel.

Specified by:
send in interface OutputChannel
Parameters:
message - Message to send
Throws:
ProtocolException - if there is some problems with message structure

addListener

public void addListener(OutputChannelListener listener)
Description copied from interface: OutputChannel
Attaches listener to OutputChannel implementer instance. Checks for duplication, will not add the same listener twice

Specified by:
addListener in interface OutputChannel
Parameters:
listener - listener to be attached.

removeListener

public void removeListener(OutputChannelListener listener)
Description copied from interface: OutputChannel
Detaches listener from OutputChannel implementer instance. Does nothing if listener was not attached before.

Specified by:
removeListener in interface OutputChannel
Parameters:
listener - listener to be detached.

sendToChannelsExcept

public void sendToChannelsExcept(Message message,
                                 OutputChannel except)
                          throws ProtocolException
Sends message to all channels except the one.

Parameters:
message - Message to send
except - channel to miss from sending
Throws:
ProtocolException - In the case of an unrecoverable protocol error. Client applications should not try to deal with these exceptions, except for logging or displaying to users or technical administrators. Check the exception cause for more details.

beginOpen

public void beginOpen()
               throws ProtocolException
Description copied from interface: AsyncChannel
Method is asynchronous. It will start connection sequence and return. Whether connection is established on return is not specified.

Specified by:
beginOpen in interface AsyncChannel
Throws:
ProtocolException - in case of problems establishing connection

beginClose

public void beginClose()
Description copied from interface: AsyncChannel
Method is asynchronous. It will start disconnection and return. Whether connection is closed on return is not specified.

Specified by:
beginClose in interface AsyncChannel

receiveRequest

public RequestContext receiveRequest()
                              throws java.lang.InterruptedException
Description copied from interface: RequestReceiver
Receives request from the client. Depending on implementation this method will or won't block for some or infinite time.

Specified by:
receiveRequest in interface RequestReceiver
Specified by:
receiveRequest in interface ResponseChannel
Returns:
Message from the channel or null if the channel is "empty"
Throws:
java.lang.InterruptedException - if thread is interrupted during this method execution

receiveRequest

public RequestContext receiveRequest(long timeout)
                              throws java.lang.InterruptedException
Receives request from the client. Depending on timeout value this method will or won't block for some time. See Channel description for timeout values meaning.

Specified by:
receiveRequest in interface RequestReceiver
Specified by:
receiveRequest in interface ResponseChannel
Parameters:
timeout - timeout to waitResponse for message
Returns:
Message from the channel or null if the channel is "empty"
Throws:
java.lang.InterruptedException - if thread is interrupted during this method execution
ChannelNotOpenedException - if channel is not in appropriate state to call the method
ChannelReceiverInitializationException - if external receiver or client request handler is set.

getChannels

public java.util.Collection<? extends Channel> getChannels()

getProtocolFactory

protected ProtocolFactory getProtocolFactory()

modifyNewChannel

protected void modifyNewChannel(DuplexChannel channel)
This method modifies the new channel to support server mode of operation suggested by ServerChannel. It sets special ReceiverSupport on the channel. If you want to handle requests other way (e.g. thread per channel) you have to override this method. Next, it sets Configuration for all new channels. By default, if no protocol name is specified, adds ADDP support. Overrides configuration option "x-addp-active" by always setting it to "false", because it is client channel responsibility to initiate ADDP.

Parameters:
channel - incoming (accepted) channel

sendToChannelsExcept

protected void sendToChannelsExcept(java.util.Collection<OutputChannel> channels,
                                    Message message,
                                    OutputChannel except)
                             throws ProtocolException
Sends message to all channels in the collection except the one.

Parameters:
channels - list of channels to send
message - Message to send
except - channel to miss from sending or null if no channel should be missed
Throws:
ProtocolException - In the case of an unrecoverable protocol error. Client applications should not try to deal with these exceptions, except for logging or displaying to users or technical administrators. Check the exception cause for more details.

getProtocolDescription

public ProtocolDescription getProtocolDescription()
Specified by:
getProtocolDescription in interface ProtocolDescriptionSupport

receive

public Message receive()
                throws java.lang.InterruptedException,
                       java.lang.IllegalStateException
Throws:
java.lang.InterruptedException
java.lang.IllegalStateException

receive

public Message receive(long timeout)
                throws java.lang.InterruptedException,
                       java.lang.IllegalStateException
Throws:
java.lang.InterruptedException
java.lang.IllegalStateException

clearInput

public void clearInput()
Description copied from interface: Receiver
Clears input of the receiver. Please note, that there is no strict guaranties that input will be empty after this method has returned, the messages could be delivered by another thread.

Specified by:
clearInput in interface Receiver

getInputSize

public int getInputSize()
Description copied from interface: Receiver
Returns the amount of messages this Receiver can hold before start to "forget stale messages".

Specified by:
getInputSize in interface Receiver
Returns:
maximum count of messages stored in receiver

setInputSize

public void setInputSize(int inputSize)
Sets the amount of messages this Receiver can hold before start to "forget stale messages".

This method is applicable for internal receiver usage scenario only. It does nothing if client request handler (setClientRequestHandler(ClientRequestHandler)) or external receiver (setReceiver(RequestReceiverSupport)) is in use.

Specified by:
setInputSize in interface Receiver
Parameters:
inputSize - maximum count of messages stored in receiver

releaseReceivers

public void releaseReceivers()
Notifies receivers (threads waiting on receive() methods) they should stop waiting and return null.

This method is applicable for internal receiver usage scenario only. It does nothing if client request handler (setClientRequestHandler(ClientRequestHandler)) or external receiver (setReceiver(RequestReceiverSupport)) is in use.

Specified by:
releaseReceivers in interface Receiver

applyConfiguration

protected void applyConfiguration()
Specified by:
applyConfiguration in class AbstractChannel

setClientRequestHandler

public void setClientRequestHandler(ClientRequestHandler handler)
ServerChannel calls the handler on each new incoming message.
While the handler is assigned the receiver (external or internal) is ignored.

Parameters:
handler - the handler for client requests procession.

setReceiver

@Deprecated
public void setReceiver(RequestReceiverSupport receiver)
Deprecated. 

Sets the requests receiver.

Specified by:
setReceiver in interface RequestReceiverManagement
Parameters:
receiver - the receiver of client request messages.
Throws:
ChannelNotClosedException - if the channel isn't closed.
See Also:
setClientRequestHandler(ClientRequestHandler)

resetReceiver

public void resetReceiver()
Resets the clients requests receiver.

Specified by:
resetReceiver in interface ReceiverManagement
Throws:
ChannelNotClosedException - when channel isn't closed

Platform SDK Java 8.5 API Reference

Send comments on this topicTechpubs.webadmin@genesys.com.
Document version: 8.5.302.00
Copyright © 2006–2017 Genesys Telecommunications Laboratories, Inc. All rights reserved.