public class RefCountingSpreadWrapper extends AbstractActivatable implements SpreadWrapper
SpreadWrapper
instances which counts calls to
activate()
and deactivate()
and only passes these calls
down to a wrapped instance of SpreadWrapper
in case they are the
first or the last.SpreadWrapper.ConnectionState
Activatable.State
Constructor and Description |
---|
RefCountingSpreadWrapper(SpreadWrapper wrapped)
Creates a new instance wrapping an the given instance.
|
Modifier and Type | Method and Description |
---|---|
void |
activate()
Activates all resources that belong to a specific object.
|
void |
deactivate()
Deactivate all resources that are owned by a specific object in order to
correctly tear down.
|
String |
getPrivateGroup()
Returns the name of the private spread group for the wrapped connection.
|
InetAddress |
getSpreadhost() |
SpreadWrapper.ConnectionState |
getStatus()
Indicates the current state of the underlying connection.
|
URI |
getTransportUri()
Returns the transport URI for this spread connection.
|
boolean |
isActive()
Tells whether this class is currently active or not.
|
boolean |
isConnected()
Indicate whether this wrapper is currently successfully connected to a
spread daemon.
|
boolean |
isShutdown()
Indicate whether a shutdown was requested.
|
boolean |
isUseTcpNoDelay() |
void |
join(String group)
If connected, joins the specified group.
|
void |
leave(String group)
If connected and joined, leaves the specified group.
|
spread.SpreadMessage |
receive()
Receive the next message from the spread connection in groups this
wrapper has joined.
|
void |
send(DataMessage msg)
Sends the given message.
|
close
public RefCountingSpreadWrapper(SpreadWrapper wrapped)
wrapped
- instance to wrap.public void activate() throws RSBException
Activatable
activate
in interface Activatable
RSBException
- generic error related to RSBpublic void deactivate() throws RSBException, InterruptedException
Activatable
deactivate
in interface Activatable
RSBException
- generic error related to RSBInterruptedException
- interrupted while waiting for proper deactivation. Object
might be in an undefined state nowpublic boolean isActive()
Activatable
isActive
in interface Activatable
true
if activepublic SpreadWrapper.ConnectionState getStatus()
SpreadWrapper
getStatus
in interface SpreadWrapper
public InetAddress getSpreadhost()
getSpreadhost
in interface SpreadWrapper
public boolean isUseTcpNoDelay()
isUseTcpNoDelay
in interface SpreadWrapper
public void join(String group) throws spread.SpreadException
SpreadWrapper
join
in interface SpreadWrapper
group
- group to joinspread.SpreadException
- error joiningpublic void send(DataMessage msg)
SpreadWrapper
send
in interface SpreadWrapper
msg
- the message to sendpublic void leave(String group)
SpreadWrapper
leave
in interface SpreadWrapper
group
- the group to leavepublic String getPrivateGroup()
SpreadWrapper
getPrivateGroup
in interface SpreadWrapper
null
if not connected so far.public boolean isConnected()
SpreadWrapper
isConnected
in interface SpreadWrapper
true
if connected, else false
public spread.SpreadMessage receive() throws InterruptedIOException, spread.SpreadException
SpreadWrapper
receive
in interface SpreadWrapper
InterruptedIOException
- interrupted while waiting for the messagespread.SpreadException
- error while reading the next messagepublic boolean isShutdown()
SpreadWrapper
isShutdown
in interface SpreadWrapper
true
if requested.public URI getTransportUri()
SpreadWrapper
getTransportUri
in interface SpreadWrapper
Copyright © 2018 CoR-Lab. All rights reserved.