Examples of PacketReference


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

        delivered.addAll(s);

       // automatically ack any remote  or ack On Destroy messages
        Iterator itr = delivered.iterator();
        while (itr.hasNext()) {
                PacketReference r = (PacketReference)itr.next();
                if (r == null) continue;
                if (ackMsgsOnDestroy || !r.isLocal()) {
                    itr.remove();
                     try {
                         if (r.acknowledged(getConsumerUID(),
                                 getStoredConsumerUID(),
                                 !uid.isUnsafeAck(), r.isLocal())) {
                             Destination d = Destination.getDestination(r.getDestinationUID());
                             if (d != null) {
                                 if (r.isLocal()) {
                                 d.removeMessage(r.getSysMessageID(),
                                      RemoveReason.ACKNOWLEDGED);
                                 } else {
                                 d.removeRemoteMessage(r.getSysMessageID(),
                                              RemoveReason.ACKNOWLEDGED, r);
                                 }
                             }
                         }
                     } catch(Exception ex) {
                         logger.log(Logger.DEBUG,"Broker down Unable to acknowlege"
                            + r.getSysMessageID() + ":" + uid, ex);
                     }
                }
        }
               
     
View Full Code Here

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

        try {
            synchronized (s) {
                Iterator itr = s.iterator();
                while (itr.hasNext()) {
                    PacketReference pr = (PacketReference)itr.next();
                    if (ackMsgsOnDestroy && pr.acknowledged(getConsumerUID(),
                              getStoredConsumerUID(),
                             !uid.isUnsafeAck(), true))
                    {
                        Destination d=Destination.getDestination(pr.getDestinationUID());
                        d.removeMessage(pr.getSysMessageID(),
                            cleanupReason);
                    }
                }
            }
            msgs.removeAll(s, cleanupReason);
View Full Code Here

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

class LoadComparator implements Comparator
{
    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();

                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;
        } else {
            assert false;
View Full Code Here

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

            if (duids.size() == 0) {
                route = false; // nothing to do
            } else {
                Iterator itr = duids.iterator();
                while (itr.hasNext()) {
                    PacketReference ref = null;
                    Exception lastthr = null;
                    boolean isLast = false;
                    DestinationUID duid = (DestinationUID)itr.next();
                    isLast = !itr.hasNext();


                    Destination d = Destination.getDestination(duid);
                    try {

                        if (d == null) {
                            throw new BrokerException("Unknown Destination:" + msg.getDestination());
                        }
                        if (realduid.isWildcard() && d.isTemporary()) {
                            logger.log(Logger.DEBUG,"L10N-XXX: Wildcard production with destination name of "
                                         + realduid +  " to temporary destination " +
                                         d.getUniqueName() + " is not supported, ignoring");
                             continue;
                        }
                        if (realduid.isWildcard() && d.isInternal()) {
                            logger.log(Logger.DEBUG,"L10N-XXX: Wildcard production with destination name of "
                                         + realduid +  " to internal destination " +
                                         d.getUniqueName() + " is not supported, ignoring");
                             continue;
                        }

                        if (realduid.isWildcard() && d.isDMQ() ) {
                            logger.log(Logger.DEBUG,"L10N-XXX: Wildcard production with destination name of "
                                         + realduid +  " to the DeadMessageQueue" +
                                         d.getUniqueName() + " is not supported, ignoring");
                             continue;
                        }
                        if (pausedProducer != null) {
                             pauseProducer(d, duid, pausedProducer, con);
                             pausedProducer = null;
                        }
   
                        if (packetUsed) {
                            // create a new Packet for the message
                            // we need a new sysmsgid with it
                            Packet newp = new Packet();
                            newp.fill(msg);
                            newp.generateSequenceNumber(true);
                            newp.generateTimestamp(true);
                            newp.prepareToSend();
                            newp.generateSequenceNumber(false);
                            newp.generateTimestamp(false);
                            msg = newp;
                        }
                        packetUsed = true;
   
                        // OK generate a ref. This checks message size and
                        // will be needed for later operations
                        ref = createReference(msg, duid, con, isadmin);
   
                        // dont bother calling route if there are no messages
                        //
                        // to improve performance, we route and later forward
                        route |= queueMessage(d, ref, transacted);
   
                        // ok ...
                        if (isLast && route && ack && !ref.isPersistent()) {
                            sendAcknowledge(refid, cid, status, con, reason, props, transacted);
                            ack = false;
                        }
   
   
                        Set s = routeMessage(transacted, ref, route, d);
                      
                        if (s != null && ! s.isEmpty()) {
                           if (routedSet == null)
                               routedSet = new HashMap();
                            routedSet.put(ref, s);
                        }

                        // handle producer flow control
                        pauseProducer(d, duid, pausedProducer, con);
                    } catch (Exception ex) {
                        if (ref != null) {
                            if (failedrefs == null)
                                failedrefs = new ArrayList();
                            failedrefs.add(ref);
                        }
                        lastthr = ex;
                        logger.log(Logger.DEBUG, BrokerResources.W_MESSAGE_STORE_FAILED,
                              con.toString(), ex);
                    } finally {
                        if (pausedProducer != null) {
                            pauseProducer(d, duid, pausedProducer, con);
                            pausedProducer = null;
                        }
                        if (isLast && lastthr != null) {
                            throw lastthr;
                        }
                    }
                } //while
            }

        } catch (BrokerException ex) {

            // dont log on dups if indemponent
            int loglevel = (isIndemp && ex.getStatusCode()
                   == Status.NOT_MODIFIED) ? Logger.DEBUG
                      : Logger.WARNING;
            logger.log(loglevel,
                      BrokerResources.W_MESSAGE_STORE_FAILED,
                      con.toString(), ex);
            reason =  ex.getMessage();

            //LKS - we may want an improved error message in the wildcard case

            status = ex.getStatusCode();
        } catch (IOException ex) {
            logger.log(Logger.WARNING, BrokerResources.W_MESSAGE_STORE_FAILED,
                      con.toString(), ex);
            reason =  ex.getMessage();
            status = Status.ERROR;
        } catch (SecurityException ex) {
            logger.log(Logger.WARNING, BrokerResources.W_MESSAGE_STORE_FAILED,
                      con.toString(), ex);
            reason =  ex.getMessage();
            status = Status.FORBIDDEN;
        } catch (OutOfMemoryError err) {
            logger.logStack(Logger.WARNING, BrokerResources.W_MESSAGE_STORE_FAILED,
                      con.toString() + ":" + msg.getPacketSize(), err);
            reason =  err.getMessage();
            status = Status.ERROR;
        } catch (Exception ex) {

            logger.logStack(Logger.WARNING, BrokerResources.W_MESSAGE_STORE_FAILED,
                      con.toString(), ex);
             reason =  ex.getMessage();
             status = Status.ERROR;
        }

        if (status == Status.ERROR && failedrefs != null ) {
            // make sure we remove the message
            //
            // NOTE: we only want to remove the last failure (its too late
            // for the rest).  In the non-wildcard case, this will be the
            // only entry. In the wildcard cause, it will be the one that had an issue
            Iterator itr = failedrefs.iterator();
            while (itr.hasNext()) {
                PacketReference ref = (PacketReference)itr.next();
                Destination d = Destination.getDestination(ref.getDestinationUID());
                if (d != null)
                    cleanupOnError(d, ref);

            }
        }

        if (ack)
            sendAcknowledge(refid, cid, status, con, reason, props, transacted);

        if (route && routedSet != null) {
            Iterator itr = routedSet.keySet().iterator();
            while (itr.hasNext()) {
                PacketReference pktref = (PacketReference)itr.next();
                DestinationUID duid = pktref.getDestinationUID();
                Destination dest = Destination.getDestination(duid);
                Set s = (Set)routedSet.get(pktref);
                forwardMessage(dest, pktref, s);
            }
        }
View Full Code Here

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

    public PacketReference createReference(Packet msg, DestinationUID duid, IMQConnection con,
             boolean isadmin) throws BrokerException
    {
            // OK generate a ref. This checks message size and
            // will be needed for later operations
            PacketReference ref = PacketReference.createReference(msg,duid, con);
            if (isadmin) {
                ref.overridePersistence(false);
            }
            return ref;
    }
View Full Code Here

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

            for (int i = 0; i < ids.length; i ++ ) {
                ConsumerUID id = ids[i];
                id.setConnectionUID(con.getConnectionUID());
                sysid = sysids[i];

                PacketReference ref = Destination.get(sysid, false);

 
                if (ref == null || ref.isInvalid()) {
                    continue;
                }
                Session s= Session.getSession(id);
                Consumer c = null;
                if (s != null) {
                    if (!sessions.contains(s)) {
                        s.pause("redeliver");
                        sessions.add(s);
                    }
                    c = s.getConsumerOnSession(id);
                }

                if (c == null) {
                    //ok, make sure the consumer has really gone away
                    //if not, something is really wrong
                    // otherwise ...
                    // consumer has gone away but session is still
                    // valid ->
                    c = Consumer.getConsumer(id);
                   
                    if (c != null) {
                        logger.log(Logger.WARNING,"Internal Error " +
                           " consumer with id of " + id + " is unavailable "
                           + " on session " + s + "[conuid,sess conuid] ="
                           + "[" + con.getConnectionUID().longValue() +
                             "," + (s == null ? 0 : s.getConnectionUID().longValue())
                           + "] consumer session is : " +c.getSessionUID()) ;
                        continue;
                    } else {
                        if (s != null && s.isClientAck(id) && !s.isTransacted() &&
                            redeliver && tid == null) {

                            ConsumerUID storedID = s.getStoredIDForDetatchedConsumer(id);
                            if (storedID != null && !storedID.equals(id)) {
                                storedIDToConsumerUIDMap.put(id, storedID);
                                SortedSet refset = (SortedSet)noConsumerMap.get(id);
                                if (refset == null) {
                                    refset = new TreeSet(new RefCompare());
                                    noConsumerMap.put(id, refset);
                                }
                                ref.removeInDelivery(storedID);
                                refset.add(ref);
                            }
                        }
                        // the consumer for this message has been
                        // closed before the redeliver was requested
                        // (this means the message has not been acked and
                        // the session is open)
                        // we dont need to deliver this message, ignore it
                        logger.log(Logger.DEBUG,
                           " consumer with id of " + id + " is unavailable "
                           + " on session " + s + "[conuid,sess conuid] ="
                           + "[" + con.getConnectionUID().longValue() +
                             "," + (s == null ? 0 : s.getConnectionUID().longValue())
                           + "] it has been closed") ;
                        continue;
                    }
                }

                //for client < 4.1, need check 'redeliver' as well
                if (redeliver && (tid != null || s.isTransacted())) {
                    if (tid == null) tid = s.getCurrentTransactionID();
                    TransactionList translist = Globals.getTransactionList();
                    HashMap cmap = translist.retrieveRemovedConsumedMessages(tid);
                    if (cmap != null && cmap.size() > 0) {
                        List interests = (List) cmap.get(sysid);
                        if (interests != null && interests.size() > 0) {
                            boolean found = false;
                            for (int j = 0; j < interests.size(); j++) {
                                ConsumerUID intid = (ConsumerUID)interests.get(j);
                                if (intid.equals(id)) {
                                    TransactionState ts = translist.retrieveState(tid);
                                    if (ts != null && ts.getState() == TransactionState.FAILED) {
                                        found = true;
                                        break;
                                    }
                                }
                            }
                            if (found) {
                               if (DEBUG_CLUSTER_TXN) {
                                   logger.log(logger.INFO,
                                   "Ignore redeliver request for ["+sysid+ ":"+id+
                                   "], removed with transaction "+tid);
                               }
                               continue;
                            }
                        }
                    }
                }
                     
                Set set = (Set)cToM.get(c);
                if (set == null) {
                    set = new LinkedHashSet();
                    cToM.put(c, set);
                }
                if (!set.contains(ref)) {
                    ref.removeInDelivery((c.getStoredConsumerUID() == null ? c.getConsumerUID():c.getStoredConsumerUID()));
                    set.add(ref);
                } else if (DEBUG_CLUSTER_TXN) {
                    logger.log(logger.INFO, "Ignore duplicated redeliver request ["+sysid+ ":"+id+"]" );
                }
                if (redeliver) {
                    ref.consumed(c.getStoredConsumerUID(),
                        s.isDupsOK(c.getConsumerUID()), false);
                } else {
                    ref.removeDelivered(c.getStoredConsumerUID(), true);
                }
            }
            Iterator itr = cToM.entrySet().iterator();
            while (itr.hasNext()) {
                Map.Entry entry = (Map.Entry)itr.next();
View Full Code Here

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

            }
            while (!isFailover && isActive() &&  !isPaused() && isValid() && ss != null
               && !ss.isEmpty() && count < num && (parent == null ||
                  !parent.isPaused()))
            {
                    PacketReference mm = (PacketReference)ss.removeNext();
                    if (mm == null)  {
                        continue;
                    }
                    msgs.add(11-mm.getPriority(), mm);
                    count ++;
                    busy = true;
            }
        }
View Full Code Here

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

    }

    public PacketReference  peekNext() {
        // ok first see if there is anything on msgs
        PacketReference ref = (PacketReference)msgs.peekNext();
        if (ref == null && parentList != null)
            ref = (PacketReference)parentList.peekNext();
        return ref;
    }
View Full Code Here

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

        delayNextFetchForRemote = millsecs;
    }

    public PacketReference getAndFillNextPacket(Packet p)
    {
        PacketReference ref = null;

        if (flowPaused || paused) {
            checkState(null);
            return null;
        }
        if (Destination.MAX_DELAY_NEXT_FETCH_MILLISECS > 0 &&
            delayNextFetchForRemote >0 && !paused && valid) {
            long delays = delayNextFetchForRemote/2;
            if (delays > 0) {
                long sleeptime = (delays > Destination.MAX_DELAY_NEXT_FETCH_MILLISECS ?
                                  Destination.MAX_DELAY_NEXT_FETCH_MILLISECS:delays);
                long sleep1 = (Destination.MAX_DELAY_NEXT_FETCH_MILLISECS < 5 ?
                               Destination.MAX_DELAY_NEXT_FETCH_MILLISECS:5);
                long slept = 0;
                while (slept < sleeptime && !paused && valid) {
                    try {
                        Thread.sleep(sleep1);
                        slept +=sleep1;
                    } catch (Exception e) {}
                    delayNextFetchForRemote = 0;
                }
            }
        }
        if (!valid) {
            return null;
        }
        if (!paused &&  msgs.isEmpty()) {
            getMoreMessages(prefetch <=0 ? 1000 : prefetch);
        }

        Packet newpkt = null;

        while (valid && !paused && !msgs.isEmpty()) {
            ref= (PacketReference)msgs.removeNext();
            if (ref == null || ref.isOverrided()) {
                int loglevel = (DEBUG_CLUSTER_MSG) ? Logger.INFO:Logger.DEBUG;
                logger.log(loglevel,  (ref == null) ?
                "Consumer ["+getConsumerUID()+"] get message null reference":
                "Consumer ["+getConsumerUID()+"] message requened: "+ref);
                continue;
            }
            newpkt = ref.getPacket();
            if (newpkt == null || !ref.checkRemovalAndSetInDelivery(getStoredConsumerUID()) ) { 
                try {
                    boolean expired = ref.isExpired();
                    String cmt = br.getKString(br.I_RM_EXPIRED_MSG_BEFORE_DELIVER_TO_CONSUMER,
                                 ref.getSysMessageID(), "["+uid+", "+uid.getAckMode()+"]"+dest);
                    String cmtr = br.getKString(br.I_RM_EXPIRED_REMOTE_MSG_BEFORE_DELIVER_TO_CONSUMER,
                                  ref.getSysMessageID(), "["+uid+", "+uid.getAckMode()+"]"+dest);
                    boolean islocal = ref.isLocal();
                    if (ref.markDead(uid, getStoredConsumerUID(), (islocal ? cmt:cmtr), null,
                        (expired ? RemoveReason.EXPIRED_ON_DELIVERY:RemoveReason.REMOVED_OTHER), -1, null)) {
                        boolean removed = false;
                        Destination d = Destination.getDestination(ref.getDestinationUID());
                        if (d != null) {
                            if (ref.isDead()) {
                                removed = d.removeDeadMessage(ref);
                            } else {
                                removed = d.removeMessage(ref.getSysMessageID(),
                                              RemoveReason.REMOVED_OTHER, !expired);
                            }
                            if (removed && expired && d.getVerbose()) {
                                logger.log(logger.INFO, (islocal ? cmt:cmtr));
                            }
                        }
                    }

                } catch (Exception ex) {
                    if (newpkt != null && DEBUG) {
                        logger.logStack(Logger.INFO,
                        "Unable to cleanup removed message "+ref+" for consumer "+this, ex);
                    }
                }
                ref = null;
                newpkt = null;
                continue;
            }

            break;
        }
        if (!valid) {
            if (DEBUG_CLUSTER_MSG) {
                logger.log(Logger.INFO, "getAndFillNextPacket(): consumer "+this+
                                        " closed, discard ref "+ref);
            }
            return null;
        }
        if (ref == null) {
            checkState(null);
            return null;
        }

        newpkt = ref.getPacket();
        if (newpkt == null) {
            assert false;
            return null;
        }

        if (p != null) {
            try {
                p.fill(newpkt);
            } catch (IOException ex) {
                logger.logStack(Logger.INFO,"Internal Exception processing packet ", ex);
                return null;
            }
            p.setConsumerID(uid.longValue());
            p.setRedelivered(ref.getRedeliverFlag(getStoredConsumerUID()));
            if (ref.isLast(uid)) {
                ref.removeIsLast(uid);
                p.setIsLast(true);
            }
            msgRetrieved();
            if (parent != null) {
                // hey, we pulled one from the durable too
                parent.msgRetrieved();
            }
        } else {
            newpkt.setRedelivered(ref.getRedeliverFlag(getStoredConsumerUID()));
        }

        if (useConsumerFlowControl) {
           if (prefetch != -1) {
              flowCount ++;
           }
           if (!flowPaused && ref.getMessageDeliveredAck(uid)) {
               BrokerAddress addr = ref.getAddress();
               if (addr != null) { // do we have a remove
                   synchronized(remotePendingResumes) {
                       remotePendingResumes.add (ref);
                   }
               } else {
               }
               if (p != null) {
                   p.setConsumerFlow(true);
                }
            }
            if (prefetch > 0 && flowCount >= prefetch ) {
                if (p != null) {
                    p.setConsumerFlow(true);
                }
                ref.addMessageDeliveredAck(uid);
                BrokerAddress addr = ref.getAddress();
                if (addr != null) { // do we have a remove
                    synchronized(remotePendingResumes) {
                       remotePendingResumes.add (ref);
                    }
                }
                pauseFlowCnt ++;
                flowPaused = true;
            }
        } else if (ref.getMessageDeliveredAck(uid)) {
            HashMap props = null;
            ConnectionUID cuid = getConnectionUID();
            if (cuid != null) {
                IMQConnection con = (IMQConnection)Globals.getConnectionManager().
                                                         getConnection(cuid);
                if (con != null) {
                    props = new HashMap();
                    props.put(Consumer.PREFETCH,
                              new Integer(con.getFlowCount()));
                }
            }
            try {
                Globals.getClusterBroadcast().acknowledgeMessage(
                    ref.getAddress(), ref.getSysMessageID(),
                    uid, ClusterBroadcast.MSG_DELIVERED, props, false);
            } catch (BrokerException ex) {
                logger.log(Logger.DEBUG,"Can not send DELIVERED ack "
                     + " received ", ex);
            }
            ref.removeMessageDeliveredAck(uid);
       }
       return ref;

    }
View Full Code Here

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

        if (set.isEmpty()) return;
        msgs.removeAll(set, cleanupReason);
        Iterator itr = set.iterator();
        while (itr.hasNext()) {
            try {
                PacketReference pr = (PacketReference)itr.next();
                if (pr.acknowledged(getConsumerUID(),
                       getStoredConsumerUID(),
                       !uid.isUnsafeAck(), true))
                {
                     Destination d = Destination.getDestination(pr.getDestinationUID());
                     d.removeMessage(pr.getSysMessageID(), cleanupReason);
                }
            } catch (IOException ex) {
                logger.log(Logger.WARNING,"Internal Error: purging consumer "
                        + this , ex);
            }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.