use of com.sun.messaging.jmq.jmsserver.persist.api.PartitionedStore in project openmq by eclipse-ee4j.
the class TxnConverter method deleteSentMessagesFromStore.
void deleteSentMessagesFromStore(TransactionWork txnWork) throws BrokerException {
// now delete any sent messages from store ( they are stored in txn
// log or prepared msg store)
Iterator<TransactionWorkMessage> sent = txnWork.getSentMessages().iterator();
while (sent.hasNext()) {
TransactionWorkMessage twm = sent.next();
DestinationUID duid = twm.getDestUID();
SysMessageID mid = twm.getMessage().getSysMessageID();
try {
((PartitionedStore) store).removeMessage(duid, mid, true);
} catch (IOException e) {
String msg = "Could not remove transacted sent message during txn conversion";
logger.logStack(Logger.ERROR, msg, e);
}
}
}
use of com.sun.messaging.jmq.jmsserver.persist.api.PartitionedStore in project openmq by eclipse-ee4j.
the class ConsumerHandler method _createConsumer.
private Consumer[] _createConsumer(DestinationUID dest_uid, IMQConnection con, Session session, String selectorstr, String clientid, String subscriptionName, boolean durable, boolean shared, boolean jmsshare, boolean nolocal, int size, String consumerString, boolean isIndemp, boolean useFlowControl) throws BrokerException, SelectorFormatException, IOException {
Consumer c = null;
Consumer newc = null;
Subscription sub = null;
String selector = selectorstr;
if (selectorstr != null && selectorstr.trim().length() == 0) {
selector = null;
}
try {
int prefetch = -1;
if (isIndemp) {
// see if we already created it
c = Consumer.getConsumer(consumerString);
if (c != null) {
prefetch = c.getPrefetch();
}
}
if (c == null) {
c = new Consumer(dest_uid, selector, nolocal, con.getConnectionUID());
c.setCreator(consumerString);
newc = c;
newc.pause("Consumer: new consumer");
// OK, determine if we are a wildcard or not
Destination[] ds = DL.getDestination(con.getPartitionedStore(), dest_uid);
// PART
Destination d = ds[0];
boolean wildcard = dest_uid.isWildcard();
// NOTE: if d == null, wildcard == true
int cprefetch = size;
int dprefetch = (wildcard ? -1 : (!shared ? d.getMaxPrefetch() : d.getSharedConsumerFlowLimit()));
prefetch = (dprefetch == -1) ? cprefetch : (cprefetch == -1 ? cprefetch : (cprefetch > dprefetch ? dprefetch : cprefetch));
c.setPrefetch(prefetch, useFlowControl);
// actual subscription added to the destination
if (subscriptionName != null && durable) {
if (!shared) {
logger.log(Logger.INFO, br.getKString(br.I_CREATE_UNSHARED_DURA, Subscription.getDSubLogString(clientid, subscriptionName), dest_uid));
} else {
logger.log(Logger.INFO, br.getKString(br.I_CREATE_SHARED_DURA, Subscription.getDSubLogString(clientid, subscriptionName) + (jmsshare ? "jms" : "mq"), dest_uid));
}
// durable
// get the subscription ... this may throw
// an exception IF we cant
sub = Subscription.findCreateDurableSubscription(clientid, subscriptionName, shared, jmsshare, dest_uid, selector, nolocal, true);
sub.setCreator(consumerString);
sub.pause("Consumer attaching to durable");
// add the consumer .. this may throw an
// exception IF
sub.attachConsumer(c, con);
c.localConsumerCreationReady();
Map<PartitionedStore, LinkedHashSet<Destination>> dmap = DL.findMatchingDestinationMap(null, dest_uid);
LinkedHashSet dset = null;
Iterator<LinkedHashSet<Destination>> itr = dmap.values().iterator();
boolean notify = true;
while (itr.hasNext()) {
dset = itr.next();
if (dset == null) {
continue;
}
Iterator<Destination> itr1 = dset.iterator();
while (itr1.hasNext()) {
Destination dd = itr1.next();
if (dd == null) {
continue;
}
Subscription oldsub = null;
try {
oldsub = (Subscription) dd.addConsumer(sub, notify, con);
} catch (ConsumerAlreadyAddedException e) {
logger.log(logger.INFO, e.getMessage());
}
if (oldsub != null) {
oldsub.purge();
}
}
notify = false;
}
sub.sendCreateSubscriptionNotification(c);
} else if ((wildcard || !d.isQueue()) && shared) {
logger.log(Logger.INFO, br.getKString(br.I_CREATE_SHARED_NONDURA_SUB, Subscription.getNDSubLongLogString(clientid, dest_uid, selectorstr, subscriptionName, nolocal), "" + dest_uid));
sub = Subscription.createAttachNonDurableSub(c, con, subscriptionName, shared, jmsshare);
c.localConsumerCreationReady();
if (sub != null) {
sub.pause("Consumer: attaching to nondurable");
Map<PartitionedStore, LinkedHashSet<Destination>> dmap = DL.findMatchingDestinationMap(null, dest_uid);
LinkedHashSet dset = null;
Iterator<LinkedHashSet<Destination>> itr = dmap.values().iterator();
while (itr.hasNext()) {
dset = itr.next();
if (dset == null) {
continue;
}
Iterator<Destination> itr1 = dset.iterator();
while (itr1.hasNext()) {
Destination dd = itr1.next();
if (dd != null) {
dd.addConsumer(sub, true, con);
}
}
}
}
c.attachToConnection(con.getConnectionUID());
if (sub != null) {
sub.sendCreateSubscriptionNotification(c);
}
} else {
c.localConsumerCreationReady();
// non-durable
Destination dd = null;
Map<PartitionedStore, LinkedHashSet<Destination>> dmap = DL.findMatchingDestinationMap(null, dest_uid);
LinkedHashSet dset = null;
Iterator<LinkedHashSet<Destination>> itr = dmap.values().iterator();
while (itr.hasNext()) {
dset = itr.next();
if (dset == null) {
continue;
}
Iterator<Destination> itr1 = dset.iterator();
while (itr1.hasNext()) {
dd = itr1.next();
if (dd != null) {
dd.addConsumer(c, true, con);
}
}
}
c.attachToConnection(con.getConnectionUID());
c.sendCreateConsumerNotification();
}
}
if (fi.FAULT_INJECTION) {
// e.g. imqcmd debug fault -n consumer.add.1 -o selector="mqDestinationName = 'T:t0.*'" -debug
HashMap fips = new HashMap();
fips.put(FaultInjection.DST_NAME_PROP, DestinationUID.getUniqueString(dest_uid.getName(), dest_uid.isQueue()));
fi.checkFaultAndSleep(FaultInjection.FAULT_CONSUMER_ADD_1, fips);
}
session.attachConsumer(c);
if (DEBUG) {
logger.log(logger.INFO, "Attached consumer " + c + "[prefetch=" + c.getPrefetch() + ", useConsumerFlowControl=" + useFlowControl + "] to session " + session);
}
Consumer[] retc = new Consumer[3];
retc[0] = c;
retc[1] = newc;
retc[2] = sub;
return retc;
} catch (Exception e) {
Object[] args = { (durable ? Subscription.getDSubLogString(clientid, subscriptionName) : (shared ? Subscription.getNDSubLongLogString(clientid, dest_uid, selector, subscriptionName, nolocal) : "")), con, dest_uid };
String emsg = Globals.getBrokerResources().getKString(BrokerResources.W_ADD_AUTO_CONSUMER_FAILED, args);
logger.logStack(logger.ERROR, emsg, e);
try {
if (c != null) {
try {
session.detatchConsumer(c.getConsumerUID(), null, false, false, false);
} catch (Exception e1) {
try {
c.destroyConsumer((new HashSet()), null, true, false, true);
} catch (Exception e2) {
}
}
}
Map<PartitionedStore, LinkedHashSet<Destination>> dmap = DL.findMatchingDestinationMap(null, dest_uid);
LinkedHashSet dset = null;
Destination dd = null;
Iterator<LinkedHashSet<Destination>> itr = dmap.values().iterator();
while (itr.hasNext()) {
dset = itr.next();
if (dset == null) {
continue;
}
Iterator<Destination> itr1 = dset.iterator();
while (itr1.hasNext()) {
dd = itr1.next();
if (dd == null) {
continue;
}
try {
if (c != null) {
dd.removeConsumer(c.getConsumerUID(), true);
}
if (sub != null) {
dd.removeConsumer(sub.getConsumerUID(), true);
}
} catch (Exception e1) {
}
}
}
try {
if (sub != null && c != null) {
sub.releaseConsumer(c.getConsumerUID());
}
} catch (Exception e1) {
}
if (subscriptionName != null && durable) {
if (sub != null && sub.getCreator() != null && sub.getCreator().equals(consumerString)) {
try {
Subscription.unsubscribe(subscriptionName, clientid);
} catch (Exception e1) {
}
}
}
} catch (Exception e3) {
}
if (e instanceof BrokerException) {
throw (BrokerException) e;
}
if (e instanceof IOException) {
throw (IOException) e;
}
if (e instanceof SelectorFormatException) {
throw (SelectorFormatException) e;
}
throw new BrokerException(emsg, e);
}
}
use of com.sun.messaging.jmq.jmsserver.persist.api.PartitionedStore in project openmq by eclipse-ee4j.
the class TransactionList method getTransListByPartitionID.
/**
* @param pid partition id
* @return null if not found
*/
public static TransactionList getTransListByPartitionID(UID pid) {
TransactionList tl = null;
PartitionedStore ps = new NoPersistPartitionedStoreImpl(pid);
TransactionList[] tls = Globals.getDestinationList().getTransactionList(ps);
tl = tls[0];
return tl;
}
use of com.sun.messaging.jmq.jmsserver.persist.api.PartitionedStore in project openmq by eclipse-ee4j.
the class DestinationList method init.
public static void init() throws BrokerException {
if (inited) {
if (shutdown) {
throw new BrokerException(Globals.getBrokerResources().getKString(BrokerResources.X_SHUTTING_DOWN_BROKER));
}
return;
}
shutdown = false;
inited = true;
if (canAutoCreate(true)) {
Globals.getLogger().log(Logger.INFO, BrokerResources.I_QUEUE_AUTOCREATE_ENABLED);
}
if (!canAutoCreate(false)) {
Globals.getLogger().log(Logger.INFO, BrokerResources.I_TOPIC_AUTOCREATE_DISABLED);
}
BrokerConfig cfg = Globals.getConfig();
// OK add listeners for the properties
cfg.addListener(SYSTEM_MAX_SIZE, cl);
cfg.addListener(SYSTEM_MAX_COUNT, cl);
cfg.addListener(MAX_MESSAGE_SIZE, cl);
cfg.addListener(AUTO_QUEUE_STR, cl);
cfg.addListener(AUTO_TOPIC_STR, cl);
cfg.addListener(DST_REAP_STR, cl);
cfg.addListener(MSG_REAP_STR, cl);
cfg.addListener(AUTO_MAX_NUM_MSGS, cl);
cfg.addListener(AUTO_MAX_TOTAL_BYTES, cl);
cfg.addListener(AUTO_MAX_BYTES_MSG, cl);
cfg.addListener(AUTO_MAX_NUM_PRODUCERS, cl);
cfg.addListener(AUTO_LOCAL_ONLY, cl);
cfg.addListener(AUTO_LIMIT_BEHAVIOR, cl);
cfg.addListener(USE_DMQ_STR, cl);
cfg.addListener(TRUNCATE_BODY_STR, cl);
cfg.addListener(LOG_MSGS_STR, cl);
cfg.addListener(DEBUG_LISTS_PROP, cl);
cfg.addListener(CHECK_MSGS_RATE_AT_DEST_CAPACITY_RATIO_PROP, cl);
cfg.addListener(CHECK_MSGS_RATE_FOR_ALL_PROP, cl);
// now configure the system based on the properties
setMaxSize(cfg.getSizeProperty(SYSTEM_MAX_SIZE));
setMaxMessages(cfg.getIntProperty(SYSTEM_MAX_COUNT));
setIndividualMessageMax(cfg.getSizeProperty(MAX_MESSAGE_SIZE));
Queue.init();
if (Globals.getStore().getPartitionModeEnabled()) {
try {
String typ = cfg.getProperty(CONN_STRATEGY_PROP, CONN_STRATEGY_DEFAULT);
String cl = null;
if (typ.equalsIgnoreCase(MIN_CONN_STRATEGY)) {
cl = MIN_CONN_STRATEGY_CLASS;
} else if (typ.equalsIgnoreCase(RR_CONN_STRATEGY)) {
cl = RR_CONN_STRATEGY_CLASS;
} else {
Globals.getLogger().log(Logger.WARNING, "XXXIngore unknown " + typ + " for " + CONN_STRATEGY_PROP);
cl = MIN_CONN_STRATEGY_CLASS;
}
if (Globals.isNucleusManagedBroker()) {
partitionStrategy = Globals.getHabitat().getService(ConnToPartitionStrategy.class, cl);
} else {
partitionStrategy = (ConnToPartitionStrategy) Class.forName(cl).getDeclaredConstructor().newInstance();
}
} catch (Exception e) {
throw new BrokerException(e.getMessage(), e);
}
}
DestinationList dl = null;
List<PartitionedStore> partitions = Globals.getStore().getAllStorePartitions();
if (Globals.getStore().getPartitionModeEnabled()) {
partitionMode = true;
if (Globals.getStore().isPartitionMigratable()) {
partitionMigratable = true;
}
} else if (partitions.size() > 1) {
BrokerException ex = new BrokerException(Globals.getBrokerResources().getKString(BrokerResources.E_INTERNAL_BROKER_ERROR, "Unexpected " + partitions.size() + "store partitions when partition mode disabled"));
Globals.getLogger().logStack(Logger.ERROR, ex.getMessage(), ex);
throw ex;
}
partitionModeInited = true;
PartitionedStore partition = null;
Iterator<PartitionedStore> itr1 = partitions.iterator();
while (itr1.hasNext()) {
partition = itr1.next();
dl = new DestinationList(partition);
destinationListList.put(partition, dl);
}
TransactionList tl = null;
Iterator<DestinationList> itr2 = destinationListList.values().iterator();
while (itr2.hasNext()) {
dl = itr2.next();
tl = new TransactionList(dl);
dl.setTransactionList(tl);
}
Iterator<DestinationList> itr = destinationListList.values().iterator();
while (itr.hasNext()) {
dl = itr.next();
dl.loadDestinations();
addPartitionListener(dl.getTransactionList());
notifyPartitionAdded(dl.getPartitionedStore(), dl);
}
}
use of com.sun.messaging.jmq.jmsserver.persist.api.PartitionedStore in project openmq by eclipse-ee4j.
the class DestinationList method movePartition.
public static void movePartition(UID partitionID, String brokerID) throws BrokerException {
if (!isPartitionMigratable()) {
throw new BrokerException(Globals.getBrokerResources().getKString(BrokerResources.X_PARTITION_NOT_MIGRATABLE), Status.PRECONDITION_FAILED);
}
PartitionedStore pstore = null;
synchronized (destinationListList) {
pstore = new NoPersistPartitionedStoreImpl(partitionID);
DestinationList dl = destinationListList.get(pstore);
if (dl == null) {
throw new BrokerException(Globals.getBrokerResources().getKString(BrokerResources.X_PARTITION_NOT_FOUND, partitionID), Status.PRECONDITION_FAILED);
}
if (dl.getPartitionedStore().isPrimaryPartition()) {
throw new BrokerException(Globals.getBrokerResources().getKString(BrokerResources.X_MIGRATE_PRIMARY_PARTITION_NOT_ALLOWED, partitionID), Status.NOT_ALLOWED);
}
dl.valid = false;
notifyPartitionRemoved(pstore, dl, brokerID);
pstore = dl.getPartitionedStore();
dl.closeAttachedConnections(GoodbyeReason.MIGRATE_PARTITION, "XXXAdmin request to move partition: " + partitionID);
destinationListList.remove(pstore);
Consumer con = null;
Iterator itr = Consumer.getAllConsumers(true);
while (itr.hasNext()) {
con = (Consumer) itr.next();
con.setParentList(pstore, null);
}
Destination d = null;
itr = dl.getDestinations(null, ALL_DESTINATIONS_MASK);
while (itr.hasNext()) {
d = (Destination) itr.next();
d.unload(true, true);
}
pstore.close();
Globals.getStore().partitionDeparture(partitionID, brokerID);
dl.clearDestinations();
}
}
Aggregations