Skip to content
Browse files

removed spurious creation of bridge channel

  • Loading branch information...
1 parent 228b2f8 commit 4e039d480ca0924e57d751493ea02d4300fcb219 @belaban committed Nov 24, 2010
Showing with 39 additions and 35 deletions.
  1. +39 −35 src/org/jgroups/protocols/RELAY.java
View
74 src/org/jgroups/protocols/RELAY.java
@@ -168,14 +168,8 @@ public Object up(Event evt) {
return up_prot.up(new Event(Event.MSG, copy));
case FORWARD:
- if(is_coord) {
- try {
- forward(msg.getRawBuffer(), msg.getOffset(), msg.getLength());
- }
- catch(Exception e) {
- log.error("failed forwarding message", e);
- }
- }
+ if(is_coord)
+ forward(msg.getRawBuffer(), msg.getOffset(), msg.getLength());
else
log.warn("Cannot forward message as I'm not coordinator");
break;
@@ -295,31 +289,38 @@ public void run() {
log.error("failed sending view data to local cluster", e);
}
- try {
- if(log.isTraceEnabled())
- log.trace("I'm the coordinator, creating a channel (props=" + props + ", cluster_name=" + cluster_name + ")");
- bridge=new JChannel(props);
- bridge.setOpt(Channel.LOCAL, false); // don't receive my own messages
- bridge.setReceiver(new Receiver());
- bridge.connect(cluster_name);
- }
- catch(ChannelException e) {
- log.error("failed creating channel (props=" + props + ")", e);
+ if(create_bridge) {
+ try {
+ if(log.isTraceEnabled())
+ log.trace("I'm the coordinator, creating a channel (props=" + props + ", cluster_name=" + cluster_name + ")");
+ bridge=new JChannel(props);
+ bridge.setOpt(Channel.LOCAL, false); // don't receive my own messages
+ bridge.setReceiver(new Receiver());
+ bridge.connect(cluster_name);
+ if(view_data != null)
+ sendViewToRemote(view_data);
+ }
+ catch(ChannelException e) {
+ log.error("failed creating channel (props=" + props + ")", e);
+ }
}
-
- if(view_data != null)
- sendViewToRemote(view_data);
}
}
}
/** Forwards the message across the TCP link to the other local cluster */
- protected void forward(byte[] buffer, int offset, int length) throws Exception {
+ protected void forward(byte[] buffer, int offset, int length) {
Message msg=new Message(null, null, buffer, offset, length);
msg.putHeader(id, new RelayHeader(RelayHeader.Type.FORWARD));
- if(bridge != null)
- bridge.send(msg);
+ if(bridge != null) {
+ try {
+ bridge.send(msg);
+ }
+ catch(Throwable t) {
+ log.error("failed forwarding message over bridge", t);
+ }
+ }
}
/** Wraps the message annd sends it to the current coordinator */
@@ -408,12 +409,11 @@ public void receive(Message msg) {
try {
ViewData data=(ViewData)Util.streamableFromByteBuffer(ViewData.class, msg.getRawBuffer(),
msg.getOffset(), msg.getLength());
-
- UUID.add(data.uuids); // todo: remove
-
- // swap local and remote views
+ // swap local and remote views and null remote view
data.remote_view=data.local_view;
data.local_view=null;
+
+ UUID.add(data.uuids); // todo: remove
System.out.println("received view from remote: " + data);
Message view_msg=new Message(null, null, Util.streamableToByteBuffer(data));
@@ -424,18 +424,24 @@ public void receive(Message msg) {
log.error("failed unmarshalling view from remote cluster", e);
}
break;
- case BROADCAST_VIEW:
- // no-op
+ case BROADCAST_VIEW: // no-op
break;
default:
throw new IllegalArgumentException(hdr.type + " is not a valid type");
}
}
public void viewAccepted(View view) {
- if(bridge_view == null || !bridge_view.getVid().equals(view.getViewId()) && view.size() > 1) {
+ if(bridge_view == null)
bridge_view=view;
- sendViewToRemote(ViewData.create(local_view, remote_view));
+ else {
+
+ System.out.println("-- bridge_view: " + bridge_view + ", view: " + view);
+
+ if(!bridge_view.getVid().equals(view.getViewId()) && view.size() > 1) {
+ bridge_view=view;
+ sendViewToRemote(ViewData.create(local_view, remote_view));
+ }
}
}
}
@@ -448,8 +454,7 @@ protected void putOnLocalCluster(Message msg) {
if(log.isTraceEnabled())
log.trace("received msg from " + sender + ", passing down the stack with dest=" +
- msg.getDest() + " and src=" + msg.getSrc());
-
+ msg.getDest() + " and src=" + msg.getSrc());
down_prot.down(new Event(Event.MSG, msg));
}
@@ -480,7 +485,6 @@ public static RelayHeader createDisseminateHeader(Address original_sender) {
}
-
public int size() {
int retval=Global.BYTE_SIZE; // type
switch(type) {

0 comments on commit 4e039d4

Please sign in to comment.
Something went wrong with that request. Please try again.