Package com.sun.messaging.jmq.jmsserver.core

Examples of com.sun.messaging.jmq.jmsserver.core.PacketReference


    while (iter.hasNext()) {
      Map.Entry<SysMessageID, List<ConsumerUID>> entry = iter.next();
      SysMessageID mid = entry.getKey();
      List<ConsumerUID> consumers = entry.getValue();

      PacketReference packRef = Destination.get(mid);
      if (packRef == null) {
        String msg = getPrefix()
            + " convertLocalToTxnLogFormat: can not find packet for consumed msg"
            + mid + " in txn " + txnInfo;
        logger.log(Logger.WARNING, msg);
      } else {
        DestinationUID destUID = packRef.getDestination()
            .getDestinationUID();
        if (consumers != null) {
          for (int i = 0; i < consumers.size(); i++) {
            ConsumerUID cid = consumers.get(i);
            ConsumerUID storedcid = (ConsumerUID) cuidToStored
View Full Code Here


                                 Globals.getHAEnabled() && haMonitor != null &&
                                 haMonitor.checkTakingoverDestination(this));
            s = new TreeSet(new RefCompare());
            while (msgs.hasMoreElements()) {
                Packet p = (Packet)msgs.nextElement();
                PacketReference pr =PacketReference.createReference(p, uid, null);
                if (takeoverMsgs != null && takeoverMsgs.contains(pr)) {
                    pr = null;
                    continue;
                }
                if (takingoverCheck && haMonitor.checkTakingoverMessage(p)) {
                    pr = null;
                    continue;
                }
                if (neverExpire)
                    pr.overrideExpireTime(0);
                // mark already stored and make packet a SoftReference to
                // prevent running out of memory if dest has lots of msgs
                pr.setLoaded();
                if (DEBUG) {
                    logger.log(Logger.INFO,"Loaded Message " + p +
                         " into destination " + this);
                }
                try {
                    if (!isDMQ && !addNewMessage(false, pr)) {
                        // expired
                        deadMsgs.add(pr);
                    }
                } catch (Exception ex) {
                    String args[] = { pr.getSysMessageID().toString(),
                        pr.getDestinationUID().toString(),
                        ex.getMessage() };
                    logger.logStack(Logger.WARNING,
                              BrokerResources.W_CAN_NOT_LOAD_MSG,
                              args, ex);
                    continue;
                }
                s.add(pr);
                packetlistAdd(pr.getSysMessageID(), pr.getDestinationUID());

                curcnt ++;
                if (curcnt > 0 && (curcnt % LOAD_COUNT == 0
                    || (curcnt > LOAD_COUNT && curcnt == size))) {
                    String args[] = { toString(),
                       String.valueOf(curcnt),
                       String.valueOf(maxloadcnt),
                       String.valueOf((curcnt*100)/maxloadcnt) };
                    logger.log(Logger.INFO,
                        BrokerResources.I_LOADING_DEST_IN_PROCESS,
                       args);
               }

            }

            } finally {
            store.closeEnumeration(msgs);
            }
              
            // now we're sorted, process
            Iterator itr = s.iterator();
            while (itr.hasNext()) {
   
                PacketReference pr = (PacketReference)itr.next();

                // ok .. see if we need to remove the message
                ConsumerUID[] consumers = store.
                    getConsumerUIDs(getDestinationUID(),
                          pr.getSysMessageID());

                if (consumers == null) consumers = new ConsumerUID[0];

                if (consumers.length == 0 &&
                    store.hasMessageBeenAcked(uid,pr.getSysMessageID())) {
                    if (DEBUG) {
                    logger.log(Logger.INFO,"Message " +
                    pr.getSysMessageID()+"["+this+"] has been acked, destory..");
                    }
                    decrementDestinationSize(pr);
                    removePacketList(pr.getSysMessageID(), pr.getDestinationUID());
                    pr.destroy();
                    continue;
                }

                if (consumers.length > 0) {
                    pr.setStoredWithInterest(true);
                } else {
                    pr.setStoredWithInterest(false);
                }

                // first producer side transactions

                boolean dontRoute = false;
                if (pr.getTransactionID() != null) {
                    // if unrouted and not in rollback -> remove
                    Boolean state = (Boolean) (transactionStates == null ?
                             null : transactionStates.get(
                                  pr.getTransactionID()));

                    // at this point, we should be down to 3 states
                    if (state == null ) // committed
                    {
                        if (consumers.length == 0) {
                            // route the message, it depends on the type of
                            // message
                            try {
                                consumers = routeLoadedTransactionMessage(pr);
                            } catch (Exception ex) {
                                logger.log(Logger.INFO,"Internal Error "
                                   + "loading/routing transacted message, "
                                   + "throwing out message " +
                                   pr.getSysMessageID(), ex);
                            }
                            if (consumers.length > 0) {
                                int[] states = new int[consumers.length];
                                for (int i=0; i < states.length; i ++
                                    states[i] = Store.INTEREST_STATE_ROUTED;
                                try {
                                    Globals.getStore().storeInterestStates(
                                          getDestinationUID(),
                                          pr.getSysMessageID(),
                                          consumers, states, true, null);
                                    pr.setStoredWithInterest(true);
                                } catch (Exception ex) {
                                      // ok .. maybe weve already been routed
                                }
                            } else {
                                if (DEBUG) {
                                logger.log(Logger.INFO, "Message "+pr.getSysMessageID()+
                                " [TUID="+pr.getTransactionID()+", "+this+"] no interest" +", destroy...");
                                }
                                decrementDestinationSize(pr);
                                removePacketList(pr.getSysMessageID(), pr.getDestinationUID());
                                pr.destroy();
                                continue;
                            }
                        }
                    } else if (state == Boolean.TRUE) // prepared
                    {
                        if (preparedTrans == null)
                            preparedTrans = new LinkedHashMap();
                        preparedTrans.put(pr.getSysMessageID(),
                              pr.getTransactionID());
                        dontRoute = true;
                    } else { // rolledback
                        if (DEBUG) {
                        logger.log(Logger.INFO, "Message "+pr.getSysMessageID()+
                        " [TUID="+pr.getTransactionID()+", "+this+"] to be rolled back" +", destroy...");
                        }
                        decrementDestinationSize(pr);
                        removePacketList(pr.getSysMessageID(), pr.getDestinationUID());
                        pr.destroy();
                        continue;
                    }
                }
                    

                // if the message has a transactionID AND there are
                // no consumers, we never had time to route it
                //

                if (consumers.length == 0 && !dontRoute) {  
                    logger.log(Logger.DEBUG,"Unrouted packet " + pr+", "+this);
                    decrementDestinationSize(pr);
                    removePacketList(pr.getSysMessageID(), pr.getDestinationUID());
                    pr.destroy();
                    continue;
                }
   
                int states[] = new int[consumers.length];
   
                for (int i = 0; i < consumers.length; i ++) {
                    states[i] = store.getInterestState(
                        getDestinationUID(),
                        pr.getSysMessageID(), consumers[i]);
                }

                if (consumers.length > 0 ) {
                    pr.update(consumers, states);
                }
                try {
                    putMessage(pr, AddReason.LOADED);
                } catch (IllegalStateException ex) {
                    String args[] = { pr.getSysMessageID().toString(),
                        pr.getDestinationUID().toString(),
                        ex.getMessage() };
                    logger.logStack(Logger.WARNING,
                              BrokerResources.W_CAN_NOT_LOAD_MSG,
                              args, ex);
                    continue;
                } catch (OutOfLimitsException ex) {
                    String args[] = { pr.getSysMessageID().toString(),
                        pr.getDestinationUID().toString(),
                        ex.getMessage() };
                    logger.logStack(Logger.WARNING,
                              BrokerResources.W_CAN_NOT_LOAD_MSG,
                              args, ex);
                    continue;
                }
                ExpirationInfo ei = pr.getExpiration();
                if (ei != null && expireReaper != null) {
                    expireReaper.addExpiringMessage(ei);
                }


                List consumerList = Arrays.asList(consumers);

                // now, deal with consumer side transactions
                Map transCidToState = (Map)(preparedAcks == null ? null :
                        preparedAcks.get(pr.getSysMessageID()));

                if (transCidToState != null) {
                    // ok .. this isnt code focused on performance, but
                    // its rarely called and only once

                    // new a new list that allows itr.remove()
                    consumerList = new ArrayList(consumerList);
                   
                    Iterator citr = consumerList.iterator();
                    while (citr.hasNext()) {
                        ConsumerUID cuid = (ConsumerUID)citr.next();
                        TransactionUID tid = (TransactionUID)
                                  transCidToState.get(cuid);
                        Boolean state = (Boolean) (transactionStates == null ?
                             null : transactionStates.get(
                                  tid));
                        // OK for committed transactions, acknowledge
                        if (state == null) {
                            // acknowledge
                            if (pr.acknowledged(cuid,
                                 cuid, false, true)) {
                                 if (committingTrans != null && committingTrans.get(tid) != null) {
                                 unputMessage(pr, RemoveReason.ACKNOWLEDGED);
                                 }
                                 decrementDestinationSize(pr);
                                 removePacketList(pr.getSysMessageID(), pr.getDestinationUID());
                                 pr.destroy();
                                 continue;
                             }
                             citr.remove();
                             continue;
                        } else if (state == Boolean.TRUE) {
                            // for prepared transactions, dont route
                             citr.remove();
                        } else if (state == Boolean.FALSE) {
                            // for rolled back transactions, do nothing
                            if (DEBUG) {
                                logger.log(Logger.INFO, "Redeliver message "+
                                pr.getSysMessageID()+" [TUID="+tid+", "+this+"]" +" to consumer "+cuid);
                            }
                        }
                    }
                    // done processing acks                           
                      
                }
                loaded = true; // dont recurse
                if (!dontRoute) {
                    routeLoadedMessage(pr, consumerList);
                }
            }
        } catch (Throwable ex) {
            logger.logStack(Logger.ERROR, BrokerResources.W_LOAD_DST_FAIL,
                     getName(), ex);
            unload(true);
        }
        destMessages.enforceLimits(enforceLimit);
        loaded = true;
           
        // clean up dead messages
        Iterator deaditr = deadMsgs.iterator();
        while (deaditr.hasNext()) {
            PacketReference pr = (PacketReference)deaditr.next();
            try {
                if (preparedTrans != null)
                    preparedTrans.remove(pr.getSysMessageID());
                removeMessage(pr.getSysMessageID(), RemoveReason.EXPIRED);
            } catch (Exception ex) {
                logger.logStack(Logger.INFO,
                    BrokerResources.E_INTERNAL_BROKER_ERROR,
                    "Processing " + pr + " while loading destination " + this, ex);
            }
View Full Code Here

          .toArray(new TransactionAcknowledgement[0]);

      DestinationUID[] destIds = new DestinationUID[txnAcks.length];
      for (int i = 0; i < txnAcks.length; i++) {
        SysMessageID sid = txnAcks[i].getSysMessageID();
        PacketReference p = Destination.get(sid);
        DestinationUID destID = null;
        if (p != null) {
          destID = p.getDestinationUID();
        } else {
          logger.log(Logger.WARNING, "Could not find packet for "
              + sid);
        }
        destIds[i] = destID;
View Full Code Here

    {
        if (selector == null) {
            return false;
        }
        if (o instanceof PacketReference) {
            PacketReference ref = (PacketReference) o;
            Map props = null;
            Map headers = null;
            try {
                // As an optimization, only extract these if the
                // selector needs them.
                if (selector.usesProperties()) {
                   props = ref.getProperties();
                }
                if (selector.usesFields()) {
                    headers = ref.getHeaders();
                }
            } catch (ClassNotFoundException ex) {
                // this is not a valid error
                assert false : ref;
                throw new RuntimeException("error with properties",
View Full Code Here

{
    public int compare(Object o1, Object o2)
    {
        if (o1 instanceof PacketReference &&
            o2 instanceof PacketReference) {
            PacketReference ref1 = (PacketReference) o1;
            PacketReference ref2 = (PacketReference) o2;
            // compare priority
            long dif = ref2.getPriority() - ref1.getPriority();

            // then timestamp
            if (dif == 0)
                dif = ref1.getTimestamp() - ref2.getTimestamp();

            // then sequence
            if (dif == 0)
                dif = ref1.getSequence() - ref2.getSequence();

            if (dif < 0) return -1;
            if (dif > 0) return 1;
            return 0;
        }
View Full Code Here

            // unload them
            if (refs) {
                // remove the refs
                Iterator i = m.values().iterator();
                while (i.hasNext()) {
                    PacketReference ref = (PacketReference)i.next();
                    destMessages.remove(ref.getSysMessageID(),RemoveReason.UNLOADED);
                    ref.clear();
                }
                destMessages = new SimpleNFLHashMap();
                remoteSize = 0;
                remoteBytes = 0;
                loaded = false;
                initialize();
            } else { // clear the ref
                Iterator itr = destMessages.values().iterator();
                while (itr.hasNext()) {
                    PacketReference ref = (PacketReference)itr.next();
                    ref.unload();
                }
            }
            // technically we are still loaded so
        } catch (Throwable thr) {
            logger.logStack(Logger.WARNING,
View Full Code Here

    {
        DestinationUID uid = (DestinationUID)getPacketListFirst(id);
        if (uid == null) return null;
        Destination d = (Destination)destinationList.get(uid);
        if (d == null) return null;
        PacketReference ref = (PacketReference)d.destMessages.get(id);
        if (ref == null) return null;
        return ref.checkLock(wait);
    }
View Full Code Here

                    remoteConsumerUIDs.append(((BrokerException)thr).getRemoteConsumerUIDs());
                    remoteConsumerUIDs.append(" ");
                    String cidstr = null;
                    ArrayList remoteConsumerUIDa = new ArrayList();
                    for (int i = 0; i < ids.length; i++) {
                        PacketReference ref = Destination.get(ids[i]);
                        Consumer c = Consumer.getConsumer(cids[i]);
                        if (c == null) continue;
                        ConsumerUID sid = c.getStoredConsumerUID();
                        if (sid == null || sid.equals(cids[i])) {
                            continue;
                        }
                        BrokerAddress ba = (ref == null ? null: ref.getAddress());
                        BrokerAddress rba = ((BrokerException)thr).getRemoteBrokerAddress();
                        if (c != null && ref != null &&
                            ba != null && rba != null && ba.equals(rba)) {
                            cidstr = String.valueOf(c.getConsumerUID().longValue());
                            if (!remoteConsumerUIDa.contains(cidstr)) {
View Full Code Here

    public void cleanUp(List cleanList)
    {
        if (cleanList != null && !cleanList.isEmpty()) {
            Iterator itr = cleanList.iterator();
            while (itr.hasNext()) {
                PacketReference ref = (PacketReference)itr.next();
                Destination d= ref.getDestination();
                try {
                    if (ref.isDead()) {
                        d.removeDeadMessage(ref);
                    } else {
                        d.removeMessage(ref.getSysMessageID(),
                           RemoveReason.ACKNOWLEDGED);
                    }
                } catch (Exception ex) {
                    Object[] eparam = {(ref == null ? "null":ref.toString()),
                                       (d == null ? "null":d.getUniqueName()), ex.getMessage()};
                    String emsg = Globals.getBrokerResources().getKString(
                                      BrokerResources.E_CLEANUP_MSG_AFTER_ACK, eparam);
                    if (DEBUG) {
                    logger.logStack(Logger.INFO, emsg, ex);
View Full Code Here

    {
        DestinationUID uid = (DestinationUID)getPacketListFirst(id);
        if (uid == null) return false;
        Destination d = (Destination)destinationList.get(uid);
        if (d == null) return false;
        PacketReference ref = (PacketReference)d.destMessages.get(id);
        if (ref == null) return false;
        return (ref.checkLock(false) == null);
    }
View Full Code Here

TOP

Related Classes of com.sun.messaging.jmq.jmsserver.core.PacketReference

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.