|
Platform SDK Java 8.5 API Reference | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.genesyslab.platform.clusterprotocol.AbstractClusterChannel<P>
com.genesyslab.platform.clusterprotocol.ClusterProtocolImpl<P,B>
P
- the base client protocol type.B
- the base client protocol builder type.public abstract class ClusterProtocolImpl<P extends ClientChannel,B extends ProtocolBuilder<P,B>>
Abstract implementation base of Cluster Protocol interface.
It's a common functionality for all specific Cluster Protocols.
EspClusterProtocol
,
UcsClusterProtocol
,
EspEmailClusterProtocol
,
FlexChatClusterProtocol
Nested Class Summary | |
---|---|
protected class |
ClusterProtocolImpl.CompletionHelper<V,A>
|
protected class |
ClusterProtocolImpl.RequestFutureWrapper
|
Field Summary | |
---|---|
protected ClusterProtocolLoadBalancer |
loadBalancer
|
protected ClusterProtocolPolicy |
protocolPolicy
|
Fields inherited from class com.genesyslab.platform.clusterprotocol.AbstractClusterChannel |
---|
endpoint, execService |
Fields inherited from interface com.genesyslab.platform.commons.protocol.Receiver |
---|
DEF_INPUT_SIZE |
Fields inherited from interface com.genesyslab.platform.commons.protocol.Channel |
---|
DEFAULT_TIMEOUT, INFINITE_TIMEOUT |
Constructor Summary | |
---|---|
protected |
ClusterProtocolImpl(ProtocolBuilder<P,B> protocolBuilder,
ClusterProtocolPolicy protocolPolicy,
ClusterProtocolLoadBalancer loadBalancer)
|
Method Summary | ||
---|---|---|
void |
addNodes(java.lang.Iterable<WSConfig> nodes)
Adds collection of WarmStandby configurations as additional cluster protocol nodes. |
|
void |
addNodes(WSConfig... nodes)
Adds list of WarmStandby configurations as additional cluster protocol nodes. |
|
void |
addNodesEndpoints(Endpoint... endpoints)
Adds Endpoint's list as additional cluster protocol nodes. |
|
void |
addNodesEndpoints(java.lang.Iterable<Endpoint> endpoints)
Adds Endpoint's collection as additional cluster protocol nodes. |
|
protected void |
addNodesImpl(java.lang.Iterable<WSConfig> nodes)
|
|
void |
beginClose()
Method is asynchronous. |
|
void |
beginOpen()
Method is asynchronous. |
|
RequestFuture |
beginRequest(Message message)
Starts request and exits. |
|
RequestFuture |
beginRequest(Message message,
long timeout)
|
|
protected Protocol |
chooseProtocol(Message request)
|
|
void |
close(long timeout)
Closes channel synchronously with given timeout. |
|
|
closeAsync(CompletionHandler<ChannelClosedEvent,? super A> handler,
A attachment)
Initiates connections close to all of the cluster nodes. Provided Completion Handler will be notified when all cluster nodes connections got closed. |
|
void |
configure(ConnectionConfiguration config)
|
|
protected P |
createProtocol()
|
|
protected com.genesyslab.platform.clusterprotocol.ProtocolNodeRec |
createProtocolNode(WSConfig wsConfig)
|
|
Message |
endRequest(RequestFuture future)
Tries to finish request started with beginRequest() . |
|
Message |
endRequest(RequestFuture future,
long timeout)
Tries to finish request started with beginRequest() . |
|
java.util.List<Protocol> |
getAllNodesProtocols()
Returns snapshot list of all cluster protocol nodes. |
|
ConnectionConfiguration |
getConfiguration()
|
|
Endpoint |
getEndpoint()
|
|
Protocol |
getNextAvailableProtocol()
Returns reference to some opened instance of protocol in the cluster nodes pool in accordance to the LB strategy. |
|
Protocol |
getNextAvailableProtocol(Message message)
Returns reference to some opened instance of protocol in the cluster nodes pool in accordance to the LB strategy for handling of the given request message. |
|
Protocol |
getNodeProtocol(int protocolId)
Returns cluster protocol node instance by PSDK Protocol Id. It may be useful in cases, when it is required to get particular server connection by ProtocolId of specific response, or unsolicited event message. |
|
Protocol |
getNodeProtocol(java.lang.String nodeName)
Returns cluster protocol node instance by name of configured Endpoint or WSConfig . |
|
java.util.List<WSConfig> |
getNodesConfig()
Returns list of cluster nodes connections configurations. |
|
java.util.List<Protocol> |
getOpenedNodesProtocols()
Returns snapshot list of cluster protocol nodes, which are tracked as Opened at the moment. |
|
ProtocolDescription |
getProtocolDescription()
|
|
int |
getProtocolId()
|
|
ReferenceBuilder |
getReferenceBuilder()
|
|
ChannelState |
getState()
Returns channel state. |
|
protected void |
onChannelDisconnected(com.genesyslab.platform.clusterprotocol.ProtocolNodeRec protocolItem,
WSDisconnectedEvent event)
|
|
protected void |
onChannelFailure(com.genesyslab.platform.clusterprotocol.ProtocolNodeRec protocolItem,
WSTriedUnsuccessfullyEvent event)
|
|
protected void |
onChannelOpened(com.genesyslab.platform.clusterprotocol.ProtocolNodeRec protocolItem,
WSOpenedEvent event)
|
|
void |
open(long timeout)
Initiates connections to the initialized set of cluster nodes. Cluster Protocol will become Opened when at least one node is connected. |
|
|
openAsync(CompletionHandler<ChannelOpenedEvent,? super A> handler,
A attachment)
Initiates connections to the initialized set of cluster nodes. The completion handler will be notified by the first connection open event. |
|
ClusterProtocolPolicy |
policy()
Returns reference to the actual cluster protocol policy. |
|
void |
removeNodes(java.lang.Iterable<java.lang.String> names)
Removes cluster protocol node(s) by given nodes names. |
|
void |
removeNodes(java.lang.String... names)
Removes cluster protocol node(s) by given nodes names. |
|
Message |
request(Message message)
Sends the message and waitResponse for response. |
|
Message |
request(Message message,
long timeout)
Sends the message and waitResponse for response or while specified timeout is elapsed. |
|
|
requestAsync(Message message,
A attachment,
CompletionHandler<Message,? super A> handler)
Starts request and exits. |
|
|
requestAsync(Message message,
A attachment,
CompletionHandler<Message,? super A> handler,
long timeout)
Starts request and exits. |
|
void |
send(Message message)
Sends message to remote party. |
|
void |
setConnectionInvoker(AsyncInvoker connectionInvoker)
Deprecated. |
|
void |
setEndpoint(Endpoint endpoint)
|
|
void |
setInvoker(AsyncInvoker invoker)
Deprecated. |
|
void |
setNodes(java.lang.Iterable<WSConfig> nodes)
Sets or resets actual cluster nodes WarmStandby connections configurations. |
|
void |
setNodes(WSConfig... nodes)
Sets or resets actual cluster nodes WarmStandby connections configurations. |
|
void |
setNodesEndpoints(Endpoint... endpoints)
Sets or resets actual cluster nodes Endpoint's list. |
|
void |
setNodesEndpoints(java.lang.Iterable<Endpoint> endpoints)
Sets or resets actual cluster nodes Endpoint's list. |
|
protected void |
setNodesImpl(java.lang.Iterable<WSConfig> nodes)
|
|
protected void |
setState(ChannelState newState,
java.lang.Throwable cause)
|
|
void |
setTimeout(long timeout)
Sets default timeout for synchronous operations on channel. |
|
protected void |
validateEndpoints(java.lang.Iterable<Endpoint> endpoints)
|
|
protected void |
validateWSConfigs(java.lang.Iterable<WSConfig> nodes)
|
Methods inherited from class com.genesyslab.platform.clusterprotocol.AbstractClusterChannel |
---|
addChannelListener, addListener, clearInput, close, fireClosedEvent, fireClosedInternalChannelEvent, fireErrorEvent, fireErrorEvent, fireOnMessageRecv, fireOnMessageSend, fireOpenedEvent, fireOpenedInternalChannelEvent, getCopyResponse, getInputSize, getInterceptor, getTimeout, open, receive, receive, releaseReceivers, removeChannelListener, removeListener, resetReceiver, setCopyResponse, setInputSize, setMessageHandler, setReceiver, setupProtocolNode, throwNotClosed, throwNotOpened, throwNull, throwOnClosed |
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.InputChannel |
---|
setMessageHandler |
Methods inherited from interface com.genesyslab.platform.commons.protocol.MessageReceiver |
---|
receive, receive |
Methods inherited from interface com.genesyslab.platform.commons.protocol.Receiver |
---|
clearInput, getInputSize, releaseReceivers, setInputSize |
Methods inherited from interface com.genesyslab.platform.commons.protocol.OutputChannel |
---|
addListener, removeListener |
Methods inherited from interface com.genesyslab.platform.commons.protocol.RequestChannel |
---|
getCopyResponse, setCopyResponse |
Methods inherited from interface com.genesyslab.platform.commons.protocol.Channel |
---|
close, getTimeout, open |
Methods inherited from interface com.genesyslab.platform.commons.protocol.ChannelListenerSupport |
---|
addChannelListener, removeChannelListener |
Methods inherited from interface com.genesyslab.platform.commons.protocol.InterceptorSupport |
---|
getInterceptor |
Methods inherited from interface com.genesyslab.platform.commons.protocol.MessageReceiverManagement |
---|
setReceiver |
Methods inherited from interface com.genesyslab.platform.commons.protocol.ReceiverManagement |
---|
resetReceiver |
Field Detail |
---|
protected final ClusterProtocolPolicy protocolPolicy
protected final ClusterProtocolLoadBalancer loadBalancer
Constructor Detail |
---|
protected ClusterProtocolImpl(ProtocolBuilder<P,B> protocolBuilder, ClusterProtocolPolicy protocolPolicy, ClusterProtocolLoadBalancer loadBalancer)
Method Detail |
---|
public ClusterProtocolPolicy policy()
ClusterProtocol
policy
in interface ClusterProtocol
public ProtocolDescription getProtocolDescription()
getProtocolDescription
in interface ProtocolDescriptionSupport
public int getProtocolId()
getProtocolId
in interface Protocol
public ReferenceBuilder getReferenceBuilder()
getReferenceBuilder
in interface Protocol
public void setTimeout(long timeout)
Channel
setTimeout
in interface Channel
setTimeout
in class AbstractClusterChannel<P extends ClientChannel>
timeout
- timeout in millisecondsprotected void validateEndpoints(java.lang.Iterable<Endpoint> endpoints)
protected void validateWSConfigs(java.lang.Iterable<WSConfig> nodes)
public ChannelState getState()
AsyncChannel
getState
in interface AsyncChannel
public <A> void openAsync(CompletionHandler<ChannelOpenedEvent,? super A> handler, A attachment) throws ProtocolException
ClusterProtocol
openAsync
in interface ClusterProtocol
handler
- the completion handler to be notified with the operation result.attachment
- user defined optional attachment for the handler.
ProtocolException
public void open(long timeout) throws RegistrationException, ProtocolException, java.lang.IllegalStateException, java.lang.InterruptedException
Opened
when at least one node is connected.
open
in interface Channel
timeout
- the timeout to wait for Opened
state.
java.lang.IllegalStateException
- if protocol is not Closed
,
or it has no set nodes configurations or Endpoint's.
ProtocolTimeoutException
- if cluster protocol got no notification about
node connection in the given timeout frame. Note: it does not fail the open request,
protocol is Opening
and WarmStandby services continue to run re-connections.
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
Channel.open()
public void beginOpen() throws ProtocolException
AsyncChannel
beginOpen
in interface AsyncChannel
ProtocolException
- in case of problems establishing connectionpublic void close(long timeout) throws ProtocolException, java.lang.IllegalStateException, java.lang.InterruptedException
Channel
close
in interface Channel
ProtocolException
- if there is any problem related to the connection close
java.lang.IllegalStateException
- exception will not be thrown in current implementation.
java.lang.InterruptedException
- in case the close operation was interrupted.public void beginClose()
AsyncChannel
beginClose
in interface AsyncChannel
public <A> void closeAsync(CompletionHandler<ChannelClosedEvent,? super A> handler, A attachment)
ClusterProtocol
closeAsync
in interface ClusterProtocol
handler
- the completion handler to be notified with the operation result.attachment
- user defined optional attachment for the handler.protected P createProtocol()
createProtocol
in class AbstractClusterChannel<P extends ClientChannel>
protected com.genesyslab.platform.clusterprotocol.ProtocolNodeRec createProtocolNode(WSConfig wsConfig)
protected void setState(ChannelState newState, java.lang.Throwable cause)
protected Protocol chooseProtocol(Message request)
public Protocol getNextAvailableProtocol()
ClusterProtocol
getNextAvailableProtocol
in interface ClusterProtocol
ClusterProtocolLoadBalancer
public Protocol getNextAvailableProtocol(Message message)
ClusterProtocol
getNextAvailableProtocol
in interface ClusterProtocol
message
- the protocol message.
ClusterProtocolLoadBalancer
,
ClusterProtocolLoadBalancer.chooseNode(Message)
public java.util.List<Protocol> getOpenedNodesProtocols()
ClusterProtocol
Opened
at the moment.
getOpenedNodesProtocols
in interface ClusterProtocol
public java.util.List<Protocol> getAllNodesProtocols()
ClusterProtocol
getAllNodesProtocols
in interface ClusterProtocol
public Protocol getNodeProtocol(java.lang.String nodeName)
ClusterProtocol
Endpoint
or WSConfig
.
getNodeProtocol
in interface ClusterProtocol
nodeName
- name of configured Endpoint
or WSConfig
.
null
.public Protocol getNodeProtocol(int protocolId)
ClusterProtocol
ProtocolId
of specific response, or unsolicited event message.
getNodeProtocol
in interface ClusterProtocol
protocolId
- the protocol id.
null
.public void send(Message message) throws ProtocolException
OutputChannel
send
in interface OutputChannel
message
- Message to send
ProtocolException
- if there is some problems with message structurepublic Message request(Message message) throws ProtocolException, java.lang.IllegalStateException
RequestChannel
request
in interface RequestChannel
message
- Message to send
ProtocolException
- if some protocol problems occurred
java.lang.IllegalStateException
- if channel is not in an appropriate state
(e.g. closed)RequestChannel.request(Message, long)
public Message request(Message message, long timeout) throws ProtocolException, java.lang.IllegalStateException
RequestChannel
request
in interface RequestChannel
message
- Message to sendtimeout
- timeout in ms
ProtocolException
- if some protocol problems occurred
java.lang.IllegalStateException
- if channel is not in an appropriate state
(e.g. closed)public RequestFuture beginRequest(Message message) throws ProtocolException, java.lang.IllegalStateException
RequestChannel
RequestChannel.endRequest(RequestFuture)
method.
beginRequest
in interface RequestChannel
message
- message to request with
ProtocolException
- if sending of the request fails
java.lang.IllegalStateException
- if channel is in inappropriate state to
execute the requestChannel.setTimeout(long)
,
RequestChannel.requestAsync(Message, Object, CompletionHandler)
,
RequestChannel.endRequest(RequestFuture)
public RequestFuture beginRequest(Message message, long timeout) throws ProtocolException, java.lang.IllegalStateException
ProtocolException
java.lang.IllegalStateException
public <A> void requestAsync(Message message, A attachment, CompletionHandler<Message,? super A> handler) throws ProtocolException, java.lang.IllegalStateException
RequestChannel
requestAsync
in interface RequestChannel
A
- user callback attachment parameter typemessage
- message to request withattachment
- user defined parameter for the "callback"handler
- user defined "callback" interface for notification
about server response
ProtocolException
- if sending of the request fails
java.lang.IllegalStateException
- if channel is in inappropriate state to
execute the requestChannel.setTimeout(long)
,
RequestChannel.requestAsync(Message, Object, CompletionHandler, long)
public <A> void requestAsync(Message message, A attachment, CompletionHandler<Message,? super A> handler, long timeout) throws ProtocolException, java.lang.IllegalStateException
RequestChannel
Message request = ...;
ReqContext ctx = ...;
CompletionHandler<Message, ReqContext> rqCallback =
new CompletionHandler<Message, ReqContext>() {
public void completed(
final Message response,
final ReqContext ctx) {
// handle the response
}
public void failed(
final Throwable throwable,
final ReqContext ctx) {
// handle the request failure
}
};
protocol.requestAsync(request, ctx, rqCallback, timeout);
requestAsync
in interface RequestChannel
A
- user callback attachment parameter typemessage
- message to request withattachment
- user defined parameter for the "callback"handler
- user defined "callback" interface for notification
about server responsetimeout
- timeout waiting for server response before request invalidation
ProtocolException
- if sending of the request fails
java.lang.IllegalStateException
- if channel is in inappropriate state to
execute the requestpublic Message endRequest(RequestFuture future) throws ProtocolException
RequestChannel
beginRequest()
.
endRequest
in interface RequestChannel
future
- future object obtained from beginRequest()
ProtocolException
- if there are protocol related problemsRequestChannel.beginRequest(Message)
public Message endRequest(RequestFuture future, long timeout) throws ProtocolException
RequestChannel
beginRequest()
.
endRequest
in interface RequestChannel
future
- future object obtained from beginRequest()
timeout
- timeout to waitResponse for response
ProtocolException
- if there are protocol related problemsRequestChannel.beginRequest(Message)
protected void onChannelOpened(com.genesyslab.platform.clusterprotocol.ProtocolNodeRec protocolItem, WSOpenedEvent event)
onChannelOpened
in class AbstractClusterChannel<P extends ClientChannel>
protected void onChannelDisconnected(com.genesyslab.platform.clusterprotocol.ProtocolNodeRec protocolItem, WSDisconnectedEvent event)
onChannelDisconnected
in class AbstractClusterChannel<P extends ClientChannel>
protected void onChannelFailure(com.genesyslab.platform.clusterprotocol.ProtocolNodeRec protocolItem, WSTriedUnsuccessfullyEvent event)
onChannelFailure
in class AbstractClusterChannel<P extends ClientChannel>
public Endpoint getEndpoint()
getEndpoint
in interface EndpointSupport
public void setEndpoint(Endpoint endpoint)
setEndpoint
in interface EndpointSupport
public ConnectionConfiguration getConfiguration()
getConfiguration
in interface ConfigurationSupport
public void configure(ConnectionConfiguration config)
configure
in interface ConfigurationSupport
public void setNodesEndpoints(Endpoint... endpoints)
ClusterProtocol
setNodesEndpoints
in interface ClusterProtocol
endpoints
- list of cluster nodes Endpoint's.public void setNodesEndpoints(java.lang.Iterable<Endpoint> endpoints)
ClusterProtocol
setNodesEndpoints
in interface ClusterProtocol
endpoints
- collection of cluster nodes Endpoint's.public void setNodes(WSConfig... nodes)
ClusterProtocol
setNodes
in interface ClusterProtocol
nodes
- list of cluster nodes configuration.public void setNodes(java.lang.Iterable<WSConfig> nodes)
ClusterProtocol
setNodes
in interface ClusterProtocol
nodes
- collection of cluster nodes configuration.protected void setNodesImpl(java.lang.Iterable<WSConfig> nodes)
public void addNodesEndpoints(Endpoint... endpoints)
ClusterProtocol
addNodesEndpoints
in interface ClusterProtocol
endpoints
- list of cluster nodes Endpoint's.public void addNodesEndpoints(java.lang.Iterable<Endpoint> endpoints)
ClusterProtocol
addNodesEndpoints
in interface ClusterProtocol
endpoints
- collection of cluster nodes Endpoint's.public void addNodes(WSConfig... nodes)
ClusterProtocol
addNodes
in interface ClusterProtocol
nodes
- list of cluster nodes configuration.public void addNodes(java.lang.Iterable<WSConfig> nodes)
ClusterProtocol
addNodes
in interface ClusterProtocol
nodes
- connection of cluster nodes configurations.protected void addNodesImpl(java.lang.Iterable<WSConfig> nodes)
public void removeNodes(java.lang.String... names)
ClusterProtocol
removeNodes
in interface ClusterProtocol
names
- list of Endpoint's/WSConfig's names.public void removeNodes(java.lang.Iterable<java.lang.String> names)
ClusterProtocol
removeNodes
in interface ClusterProtocol
names
- collection of Endpoint's/WSConfig's names.public java.util.List<WSConfig> getNodesConfig()
ClusterProtocol
getNodesConfig
in interface ClusterProtocol
@Deprecated public void setInvoker(AsyncInvoker invoker)
setInvoker
in interface AsyncInvokerSupport
@Deprecated public void setConnectionInvoker(AsyncInvoker connectionInvoker)
setConnectionInvoker
in interface ConnectionInvokerSupport
|
Platform SDK Java 8.5 API Reference | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |