mirror of https://github.com/apache/cloudstack.git
Fixed index out of bounds exception
This commit is contained in:
parent
3327371f97
commit
2c75352f7c
|
|
@ -30,11 +30,11 @@ import org.apache.cloudstack.framework.serializer.MessageSerializer;
|
|||
|
||||
public class MessageBusBase implements MessageBus {
|
||||
|
||||
private Gate _gate;
|
||||
private List<ActionRecord> _pendingActions;
|
||||
private final Gate _gate;
|
||||
private final List<ActionRecord> _pendingActions;
|
||||
|
||||
private SubscriptionNode _subscriberRoot;
|
||||
private MessageSerializer _messageSerializer;
|
||||
private final SubscriptionNode _subscriberRoot;
|
||||
private MessageSerializer _messageSerializer;
|
||||
|
||||
public MessageBusBase() {
|
||||
_gate = new Gate();
|
||||
|
|
@ -77,7 +77,7 @@ public class MessageBusBase implements MessageBus {
|
|||
if(current != null)
|
||||
current.removeSubscriber(subscriber, false);
|
||||
} else {
|
||||
this._subscriberRoot.removeSubscriber(subscriber, true);
|
||||
_subscriberRoot.removeSubscriber(subscriber, true);
|
||||
}
|
||||
_gate.leave();
|
||||
} else {
|
||||
|
|
@ -129,7 +129,7 @@ public class MessageBusBase implements MessageBus {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void publish(String senderAddress, String subject, PublishScope scope,
|
||||
public void publish(String senderAddress, String subject, PublishScope scope,
|
||||
Object args) {
|
||||
|
||||
if(_gate.enter(true)) {
|
||||
|
|
@ -151,40 +151,38 @@ public class MessageBusBase implements MessageBus {
|
|||
private void onGateOpen() {
|
||||
synchronized(_pendingActions) {
|
||||
ActionRecord record = null;
|
||||
if(_pendingActions.size() > 0) {
|
||||
while((record = _pendingActions.remove(0)) != null) {
|
||||
switch(record.getType()) {
|
||||
case Subscribe :
|
||||
{
|
||||
SubscriptionNode current = locate(record.getSubject(), null, true);
|
||||
assert(current != null);
|
||||
current.addSubscriber(record.getSubscriber());
|
||||
}
|
||||
break;
|
||||
|
||||
case Unsubscribe :
|
||||
if(record.getSubject() != null) {
|
||||
SubscriptionNode current = locate(record.getSubject(), null, false);
|
||||
if(current != null)
|
||||
current.removeSubscriber(record.getSubscriber(), false);
|
||||
} else {
|
||||
this._subscriberRoot.removeSubscriber(record.getSubscriber(), true);
|
||||
}
|
||||
break;
|
||||
while (_pendingActions.size() > 0) {
|
||||
record = _pendingActions.remove(0);
|
||||
switch (record.getType()) {
|
||||
case Subscribe: {
|
||||
SubscriptionNode current = locate(record.getSubject(), null, true);
|
||||
assert (current != null);
|
||||
current.addSubscriber(record.getSubscriber());
|
||||
}
|
||||
break;
|
||||
|
||||
case Unsubscribe:
|
||||
if (record.getSubject() != null) {
|
||||
SubscriptionNode current = locate(record.getSubject(), null, false);
|
||||
if (current != null)
|
||||
current.removeSubscriber(record.getSubscriber(), false);
|
||||
} else {
|
||||
_subscriberRoot.removeSubscriber(record.getSubscriber(), true);
|
||||
}
|
||||
break;
|
||||
|
||||
case ClearAll:
|
||||
_subscriberRoot.clearAll();
|
||||
break;
|
||||
|
||||
case ClearAll :
|
||||
_subscriberRoot.clearAll();
|
||||
break;
|
||||
|
||||
case Prune :
|
||||
doPrune();
|
||||
break;
|
||||
|
||||
default :
|
||||
assert(false);
|
||||
break;
|
||||
case Prune:
|
||||
doPrune();
|
||||
break;
|
||||
|
||||
}
|
||||
default:
|
||||
assert (false);
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -202,7 +200,7 @@ public class MessageBusBase implements MessageBus {
|
|||
return locate(subjectPathTokens, _subscriberRoot, chainFromTop, createPath);
|
||||
}
|
||||
|
||||
private static SubscriptionNode locate(String[] subjectPathTokens,
|
||||
private static SubscriptionNode locate(String[] subjectPathTokens,
|
||||
SubscriptionNode current, List<SubscriptionNode> chainFromTop, boolean createPath) {
|
||||
|
||||
assert(current != null);
|
||||
|
|
@ -223,7 +221,7 @@ public class MessageBusBase implements MessageBus {
|
|||
}
|
||||
|
||||
if(subjectPathTokens.length > 1) {
|
||||
return locate((String[])Arrays.copyOfRange(subjectPathTokens, 1, subjectPathTokens.length),
|
||||
return locate(Arrays.copyOfRange(subjectPathTokens, 1, subjectPathTokens.length),
|
||||
next, chainFromTop, createPath);
|
||||
} else {
|
||||
return next;
|
||||
|
|
@ -242,9 +240,9 @@ public class MessageBusBase implements MessageBus {
|
|||
}
|
||||
|
||||
private static class ActionRecord {
|
||||
private ActionType _type;
|
||||
private String _subject;
|
||||
private MessageSubscriber _subscriber;
|
||||
private final ActionType _type;
|
||||
private final String _subject;
|
||||
private final MessageSubscriber _subscriber;
|
||||
|
||||
public ActionRecord(ActionType type, String subject, MessageSubscriber subscriber) {
|
||||
_type = type;
|
||||
|
|
@ -252,8 +250,8 @@ public class MessageBusBase implements MessageBus {
|
|||
_subscriber = subscriber;
|
||||
}
|
||||
|
||||
public ActionType getType() {
|
||||
return _type;
|
||||
public ActionType getType() {
|
||||
return _type;
|
||||
}
|
||||
|
||||
public String getSubject() {
|
||||
|
|
@ -320,10 +318,10 @@ public class MessageBusBase implements MessageBus {
|
|||
}
|
||||
|
||||
private static class SubscriptionNode {
|
||||
private String _nodeKey;
|
||||
private List<MessageSubscriber> _subscribers;
|
||||
private Map<String, SubscriptionNode> _children;
|
||||
private SubscriptionNode _parent;
|
||||
private final String _nodeKey;
|
||||
private final List<MessageSubscriber> _subscribers;
|
||||
private final Map<String, SubscriptionNode> _children;
|
||||
private final SubscriptionNode _parent;
|
||||
|
||||
public SubscriptionNode(SubscriptionNode parent, String nodeKey, MessageSubscriber subscriber) {
|
||||
assert(nodeKey != null);
|
||||
|
|
@ -338,7 +336,7 @@ public class MessageBusBase implements MessageBus {
|
|||
}
|
||||
|
||||
public SubscriptionNode getParent() {
|
||||
return _parent;
|
||||
return _parent;
|
||||
}
|
||||
|
||||
public String getNodeKey() {
|
||||
|
|
|
|||
Loading…
Reference in New Issue