use of com.sun.messaging.jmq.jmsserver.cluster.api.ClusterBroadcast in project openmq by eclipse-ee4j.
the class DestinationList method createDestination.
// XXX : The public createDestination methods can be renamed so
// that it is easier to find the right variant. (e.g.
// createTempDestination, createAutoDestination,
// createClusterDestination etc...
private Destination createDestination(String name, int type, boolean store, boolean autocreated, ConnectionUID uid, boolean notify, boolean localOnly) throws BrokerException, IOException {
DestinationUID duid = new DestinationUID(name, DestType.isQueue(type));
if (!valid) {
if (!DL.isPartitionMode()) {
throw new BrokerException(Globals.getBrokerResources().getKString(BrokerResources.X_SHUTTING_DOWN_BROKER), BrokerResources.X_SHUTTING_DOWN_BROKER, (Throwable) null, Status.ERROR);
} else {
throw new BrokerException(br.getKString(br.I_PARTITION_IS_CLOSING, logsuffix));
}
}
if (destinationList.get(duid) != null) {
throw new ConflictException(Globals.getBrokerResources().getKString(BrokerResources.X_DESTINATION_EXISTS, duid));
}
// OK, check the persistent store (required for HA)
try {
Destination d = pstore.getDestination(duid);
if (d != null) {
d.setDestinationList(this);
addDestination(d, false);
return d;
}
} catch (Exception ex) {
// ignore we want to create it
}
ClusterBroadcast mbi = Globals.getClusterBroadcast();
boolean clusterNotify = false;
Destination d = null;
try {
if (DestType.isQueue(type)) {
d = new Queue(name, type, store, uid, autocreated, this);
} else {
d = new Topic(name, type, store, uid, autocreated, this);
}
d.setClusterNotifyFlag(notify);
try {
synchronized (destinationList) {
Destination newd = (Destination) destinationList.get(duid);
if (newd != null) {
// updating existing
String emsg = Globals.getBrokerResources().getKString(BrokerResources.X_DESTINATION_EXISTS, duid.getLongString());
throw new BrokerException(emsg, Status.CONFLICT);
}
if (!autocreated) {
d.setIsLocal(localOnly);
}
if (store) {
d.store();
}
destinationList.put(duid, d);
}
} catch (BrokerException ex) {
// Conflict message
if (ex.getStatusCode() != Status.CONFLICT) {
throw new BrokerException(ex.getMessage(), ex, Status.CONFLICT);
}
throw ex;
}
clusterNotify = !d.isAutoCreated() && d.sendClusterUpdate() && notify;
if (mbi != null && clusterNotify) {
// dont worry about locking
if (!mbi.lockDestination(duid, uid)) {
throw new ConflictException("Internal Exception:" + " Destination " + duid + " is in the process" + " of being created");
}
}
if (clusterNotify && mbi != null) {
// we dont care about updating other brokers for
// autocreated, internal or admin destinations
// we may or may not update local dests (depends on version
// of cluster)
mbi.createDestination(d);
}
} finally {
if (mbi != null && clusterNotify) {
// only null in tonga test
mbi.unlockDestination(duid, uid);
}
}
// NOW ATTACH ANY WILDCARD PRODUCERS OR CONSUMERS
Iterator itr = Consumer.getWildcardConsumers();
while (itr.hasNext()) {
ConsumerUID cuid = (ConsumerUID) itr.next();
Consumer c = Consumer.getConsumer(cuid);
if (c == null) {
Globals.getLogger().log(Logger.INFO, "Consumer already destroyed");
continue;
}
DestinationUID wuid = c.getDestinationUID();
// compare the uids
if (DestinationUID.match(d.getDestinationUID(), wuid)) {
try {
// attach the consumer
if (c.getSubscription() != null) {
d.addConsumer(c.getSubscription(), false);
} else {
d.addConsumer(c, false);
}
} catch (SelectorFormatException ex) {
// LKS TBD
}
}
}
itr = Producer.getWildcardProducers();
while (itr.hasNext()) {
ProducerUID puid = (ProducerUID) itr.next();
Producer p = (Producer) Producer.getProducer(puid);
DestinationUID wuid = p.getDestinationUID();
// compare the uids
if (DestinationUID.match(d.getDestinationUID(), wuid)) {
// attach the consumer
d.addProducer(p);
}
}
Agent agent = Globals.getAgent();
if (agent != null) {
agent.registerDestination(d);
agent.notifyDestinationCreate(d);
}
return d;
}
use of com.sun.messaging.jmq.jmsserver.cluster.api.ClusterBroadcast in project openmq by eclipse-ee4j.
the class STOMPWebSocket method dispatchMessage.
protected void dispatchMessage(StompFrameMessageImpl m) throws Exception {
final StompFrameMessageImpl msg = m;
switch(msg.getCommand()) {
case CONNECT:
case STOMP:
ClusterBroadcast cbc = Globals.getClusterBroadcast();
if (cbc.waitForConfigSync()) {
String emsg = br.getKString(br.X_CLUSTER_NO_SYNC_WITH_MASTER_BROKER_RETRY_CONNECT, Globals.getClusterManager().getMasterBroker());
sendFatalError(new BrokerException("CONNECT: " + emsg + ", " + Status.RETRY));
break;
}
stompProtocolHandler.onCONNECT(msg, this, null);
break;
case SEND:
if (DEBUG) {
logger.log(logger.INFO, "StompWebSocket.processData(SEND): " + msg);
}
stompProtocolHandler.onSEND(msg, this, null);
break;
case SUBSCRIBE:
stompProtocolHandler.onSUBSCRIBE(msg, this, this, null);
break;
case UNSUBSCRIBE:
stompProtocolHandler.onUNSUBSCRIBE(msg, this, null);
break;
case BEGIN:
stompProtocolHandler.onBEGIN(msg, this, null);
break;
case COMMIT:
stompProtocolHandler.onCOMMIT(msg, this, null);
break;
case ABORT:
stompProtocolHandler.onABORT(msg, this, null);
break;
case ACK:
stompProtocolHandler.onACK(msg, this, null);
break;
case NACK:
stompProtocolHandler.onNACK(msg, this, null);
break;
case DISCONNECT:
stompProtocolHandler.onDISCONNECT(msg, this, null);
this.close(WebSocket.NORMAL_CLOSURE, "DISCONNECT");
break;
case ERROR:
sendToClient(msg, stompProtocolHandler, null);
break;
default:
Exception e = new IOException(msg.getKStringX_UNKNOWN_STOMP_CMD(msg.getCommand().toString()));
logger.log(logger.ERROR, e.getMessage());
sendFatalError(e);
}
}
Aggregations