Toggle navigation
Toggle navigation
This project
Loading...
Sign in
홍길동
/
onos
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
Madan Jampani
2014-10-17 10:48:50 -0700
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
4a9cb6d072b0d428613064578edaeae0deec397c
4a9cb6d0
1 parent
ce430a48
Added sendAndReceive API to ClusterCommunicationService
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
68 additions
and
0 deletions
core/api/src/main/java/org/onlab/onos/store/cluster/messaging/ClusterCommunicationService.java
core/api/src/main/java/org/onlab/onos/store/cluster/messaging/ClusterMessageResponse.java
core/store/dist/src/main/java/org/onlab/onos/store/cluster/messaging/impl/ClusterCommunicationManager.java
core/api/src/main/java/org/onlab/onos/store/cluster/messaging/ClusterCommunicationService.java
View file @
4a9cb6d
...
...
@@ -37,6 +37,15 @@ public interface ClusterCommunicationService {
boolean
multicast
(
ClusterMessage
message
,
Set
<
NodeId
>
nodeIds
)
throws
IOException
;
/**
* Sends a message synchronously.
* @param message message to send
* @param toNodeId recipient node identifier
* @return ClusterMessageResponse which is reply future.
* @throws IOException
*/
ClusterMessageResponse
sendAndReceive
(
ClusterMessage
message
,
NodeId
toNodeId
)
throws
IOException
;
/**
* Adds a new subscriber for the specified message subject.
*
* @param subject message subject
...
...
core/api/src/main/java/org/onlab/onos/store/cluster/messaging/ClusterMessageResponse.java
0 → 100644
View file @
4a9cb6d
package
org
.
onlab
.
onos
.
store
.
cluster
.
messaging
;
import
java.util.concurrent.TimeUnit
;
import
java.util.concurrent.TimeoutException
;
import
org.onlab.onos.cluster.NodeId
;
public
interface
ClusterMessageResponse
{
public
NodeId
sender
();
public
byte
[]
get
(
long
timeout
,
TimeUnit
timeunit
)
throws
TimeoutException
;
public
byte
[]
get
(
long
timeout
)
throws
InterruptedException
;
}
core/store/dist/src/main/java/org/onlab/onos/store/cluster/messaging/impl/ClusterCommunicationManager.java
View file @
4a9cb6d
...
...
@@ -4,6 +4,9 @@ import static com.google.common.base.Preconditions.checkArgument;
import
java.io.IOException
;
import
java.util.Set
;
import
java.util.concurrent.TimeUnit
;
import
java.util.concurrent.TimeoutException
;
import
org.apache.felix.scr.annotations.Activate
;
import
org.apache.felix.scr.annotations.Component
;
import
org.apache.felix.scr.annotations.Deactivate
;
...
...
@@ -17,6 +20,7 @@ import org.onlab.onos.store.cluster.impl.ClusterMembershipEvent;
import
org.onlab.onos.store.cluster.messaging.ClusterCommunicationService
;
import
org.onlab.onos.store.cluster.messaging.ClusterMessage
;
import
org.onlab.onos.store.cluster.messaging.ClusterMessageHandler
;
import
org.onlab.onos.store.cluster.messaging.ClusterMessageResponse
;
import
org.onlab.onos.store.cluster.messaging.MessageSubject
;
import
org.onlab.onos.store.serializers.ClusterMessageSerializer
;
import
org.onlab.onos.store.serializers.KryoPoolUtil
;
...
...
@@ -28,6 +32,7 @@ import org.onlab.netty.Message;
import
org.onlab.netty.MessageHandler
;
import
org.onlab.netty.MessagingService
;
import
org.onlab.netty.NettyMessagingService
;
import
org.onlab.netty.Response
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
...
...
@@ -120,6 +125,22 @@ public class ClusterCommunicationManager
}
@Override
public
ClusterMessageResponse
sendAndReceive
(
ClusterMessage
message
,
NodeId
toNodeId
)
throws
IOException
{
ControllerNode
node
=
clusterService
.
getNode
(
toNodeId
);
checkArgument
(
node
!=
null
,
"Unknown nodeId: %s"
,
toNodeId
);
Endpoint
nodeEp
=
new
Endpoint
(
node
.
ip
().
toString
(),
node
.
tcpPort
());
try
{
Response
responseFuture
=
messagingService
.
sendAndReceive
(
nodeEp
,
message
.
subject
().
value
(),
SERIALIZER
.
encode
(
message
));
return
new
InternalClusterMessageResponse
(
toNodeId
,
responseFuture
);
}
catch
(
IOException
e
)
{
log
.
error
(
"Failed interaction with remote nodeId: "
+
toNodeId
,
e
);
throw
e
;
}
}
@Override
public
void
addSubscriber
(
MessageSubject
subject
,
ClusterMessageHandler
subscriber
)
{
messagingService
.
registerHandler
(
subject
.
value
(),
new
InternalClusterMessageHandler
(
subscriber
));
...
...
@@ -144,4 +165,30 @@ public class ClusterCommunicationManager
}
}
}
private
static
final
class
InternalClusterMessageResponse
implements
ClusterMessageResponse
{
private
final
NodeId
sender
;
private
final
Response
responseFuture
;
public
InternalClusterMessageResponse
(
NodeId
sender
,
Response
responseFuture
)
{
this
.
sender
=
sender
;
this
.
responseFuture
=
responseFuture
;
}
@Override
public
NodeId
sender
()
{
return
sender
;
}
@Override
public
byte
[]
get
(
long
timeout
,
TimeUnit
timeunit
)
throws
TimeoutException
{
return
responseFuture
.
get
(
timeout
,
timeunit
);
}
@Override
public
byte
[]
get
(
long
timeout
)
throws
InterruptedException
{
return
responseFuture
.
get
();
}
}
}
...
...
Please
register
or
login
to post a comment