use of com.sun.messaging.jmq.jmsserver.persist.api.NoPersistPartitionedStoreImpl in project openmq by eclipse-ee4j.
the class Subscription method attachConsumer.
public void attachConsumer(Consumer consumer, Connection conn) throws BrokerException {
logger.log(Logger.DEBUG, "Attaching Consumer " + consumer + " to durable " + this + " with " + msgs.size() + " msgs " + getDestinationUID() + "[" + getConsumerUID() + "]");
synchronized (subLock) {
if (activeConsumers.get(consumer.getConsumerUID()) != null) {
throw new ConsumerAlreadyAddedException(Globals.getBrokerResources().getKString(BrokerResources.I_CONSUMER_ALREADY_ADDED, consumer.getConsumerUID(), consumer.getDestinationUID()));
}
if (maxNumActiveConsumers == 1) {
ConsumerUID kidc = consumer.getConsumerUID();
uid.setConnectionUID(kidc.getConnectionUID());
conuid = kidc.getConnectionUID();
} else {
if (!activeConsumers.isEmpty() && consumer.noLocal != noLocal) {
throw new IllegalStateException("nolocal must match on all consumers");
}
}
if (maxNumActiveConsumers != -1 && (activeConsumers.size() >= maxNumActiveConsumers)) {
String[] args = { getDestinations().toString(), this.toString(), String.valueOf(maxNumActiveConsumers), String.valueOf(activeConsumers.size()) };
throw new BrokerException(Globals.getBrokerResources().getKString(BrokerResources.X_TOO_MANY_SHARED, args), BrokerResources.X_TOO_MANY_SHARED, (Throwable) null, Status.CONFLICT);
}
boolean wasActive = isActive();
consumer.setStoredConsumerUID(getConsumerUID());
consumer.getConsumerUID().setShouldStore(true);
activeConsumers.put(consumer.getConsumerUID(), consumer);
if (msgsSubset == null) {
msgsSubset = msgs.subSet((Filter) null);
}
consumer.setParentList(new NoPersistPartitionedStoreImpl(getStoredConsumerUID()), msgsSubset);
consumer.setSubscription(this);
// OK - get all matching destinations
active = !activeConsumers.isEmpty();
Map<PartitionedStore, LinkedHashSet<Destination>> dmap = DestinationList.findMatchingDestinationMap(null, getDestinationUID());
LinkedHashSet dset = null;
for (Map.Entry<PartitionedStore, LinkedHashSet<Destination>> pair : dmap.entrySet()) {
dset = pair.getValue();
if (dset == null) {
continue;
}
Iterator<Destination> itr1 = dset.iterator();
while (itr1.hasNext()) {
Destination d = itr1.next();
if (d == null) {
continue;
}
if (isActive() && !wasActive) {
if (!d.isLoaded()) {
logger.log(Logger.DEBUG, "Loading " + d);
try {
d.load();
} catch (BrokerException e) {
logger.logStack(Logger.ERROR, e.getMessage() + " [" + pair.getKey() + "]", e);
}
}
}
d.notifyConsumerAdded(consumer, conn);
}
}
}
}
use of com.sun.messaging.jmq.jmsserver.persist.api.NoPersistPartitionedStoreImpl in project openmq by eclipse-ee4j.
the class Subscription method releaseConsumer.
public void releaseConsumer(ConsumerUID uid) {
logger.log(Logger.DEBUG, "Releasing Consumer " + uid + " from durable " + this);
pause("Subscription: releaseConsumer " + uid);
Consumer consumer = null;
synchronized (subLock) {
consumer = (Consumer) activeConsumers.remove(uid);
consumer.pause("Subscription: releaseConsumer B ");
consumer.setParentList(new NoPersistPartitionedStoreImpl(getStoredConsumerUID()), null);
active = !activeConsumers.isEmpty();
}
List[] ll = null;
try {
ll = DestinationList.findMatchingIDs(null, getDestinationUID());
} catch (PartitionNotFoundException e) {
ll = new List[] { new ArrayList<DestinationUID>() };
}
List l = ll[0];
Iterator itr = l.iterator();
Destination[] ds = null;
Destination d = null;
while (itr.hasNext()) {
ds = DestinationList.getDestination(null, (DestinationUID) itr.next());
d = ds[0];
if (d != null) {
d.notifyConsumerRemoved();
}
}
if (!isDurable) {
synchronized (Subscription.class) {
active = !activeConsumers.isEmpty();
if (!active) {
logger.log(Logger.DEBUG, "Cleaning up non-durable " + " subscription " + this);
String key = getNDSubKey(clientID, consumer.getDestinationUID(), selstr, getNDSubscriptionName());
nonDurableList.remove(key);
destroyConsumer(new HashSet(), (Map) null, false, true, false);
}
}
}
consumer.resume("Subscription: releaseConsumer B ");
resume("Subscription: release consumer " + uid);
}
use of com.sun.messaging.jmq.jmsserver.persist.api.NoPersistPartitionedStoreImpl in project openmq by eclipse-ee4j.
the class DestinationList method assignStorePartition.
public static PartitionedStore assignStorePartition(int serviceType, ConnectionUID connid, UID storeSession) throws BrokerException {
PartitionedStore pstore = null;
DestinationList dl = null;
if (partitionMode && serviceType == ServiceType.ADMIN) {
synchronized (destinationListList) {
if (destinationListList.size() == 0) {
throw new BrokerException("IllegalStateException: DestinationList not inited !");
}
dl = destinationListList.get(Globals.getStore().getPrimaryPartition());
dl.attachConnection(connid);
return dl.getPartitionedStore();
}
}
if (storeSession != null && Globals.getStore().getPartitionModeEnabled()) {
PartitionedStore tmpps = new NoPersistPartitionedStoreImpl(storeSession);
synchronized (destinationListList) {
dl = destinationListList.get(tmpps);
if (dl == null) {
throw new BrokerException(Globals.getBrokerResources().getKString(BrokerResources.I_CONN_REQUEST_PARTITION_NOT_FOUND, storeSession, connid), Status.NOT_FOUND);
}
dl.attachConnection(connid);
pstore = dl.getPartitionedStore();
}
Globals.getLogger().log(Logger.INFO, Globals.getBrokerResources().getKString(BrokerResources.I_ASSIGN_REQUESTED_PARTITION_TO_CONN, pstore, connid));
return pstore;
}
while (!shutdown) {
ArrayList<ConnToPartitionStrategyContext> dls = null;
synchronized (destinationListList) {
dls = new ArrayList<>(destinationListList.values());
}
if (dls.size() == 0) {
throw new BrokerException("XXXIllegalState: DestinationList not inited !");
}
if (dls.size() == 1) {
dl = (DestinationList) dls.get(0);
synchronized (destinationListList) {
dl.attachConnection(connid);
}
pstore = dl.getPartitionedStore();
if (Globals.getStore().getPartitionModeEnabled()) {
Globals.getLogger().log(Logger.INFO, Globals.getBrokerResources().getKString(BrokerResources.I_ASSIGN_CONN_PARTITION, pstore, connid));
}
return pstore;
}
if (partitionStrategy != null) {
pstore = partitionStrategy.chooseStorePartition(dls);
} else {
pstore = dls.get(0).getPartitionedStore();
}
synchronized (destinationListList) {
dl = destinationListList.get(pstore);
if (dl == null) {
continue;
}
if (!dl.isValid()) {
continue;
}
dl.attachConnection(connid);
}
pstore = dl.getPartitionedStore();
Globals.getLogger().log(Logger.INFO, Globals.getBrokerResources().getKString(BrokerResources.I_ASSIGN_CONN_PARTITION, pstore, connid));
return pstore;
}
throw new BrokerException(Globals.getBrokerResources().getKString(BrokerResources.X_SHUTTING_DOWN_BROKER), BrokerResources.X_SHUTTING_DOWN_BROKER);
}
Aggregations