Package com.sun.messaging.jmq.jmsserver.persist

Examples of com.sun.messaging.jmq.jmsserver.persist.Store


    // 4. write prepared txns (since last checkpoint) to prepared store
    // 5. sync prepareTxnStore
    // 6. reset txn log
    // 7. remove committed txns (since last checkpoint) from prepared store

    Store store = null;
    try {
      store = Globals.getStore();
    } catch (Throwable e) {
      logger.logStack(Logger.ERROR, "failed to getStore", e);

      // fatal
    }

    try {

      // 1. get an exclusive lock on txnLog to prevent any other updates
      // occurring
      store.txnLogExclusiveLock.lock();

      // 2. wait for all logged commits to be written to message store
      localTransactionManager.waitForPlayingToMessageStoreCompletion();
      clusterTransactionManager.waitForPlayingToMessageStoreCompletion();
      remoteTransactionManager.waitForPlayingToMessageStoreCompletion();
     
      //2.1 wait for pending removes to be completed for logged last ack on message
      loggedMessageHelper.waitForPendingRemoveCompletion();

      // 3. sync the message store
      store.syncStoreOnCheckpoint();

      // 4. write prepared transactions to prepared transaction store
      localTransactionManager
          .writePreparedTransactionsToPreparedTxnStoreOnCheckpoint();
      clusterTransactionManager
View Full Code Here


            // ok ... if setState == false, we were already
            // acked so do nothing
            if (cmp.setState(ACKED)) {
                    if (cmp.isStored()) {
                        boolean acked = false;
                        Store store = Globals.getStore();
                        if (store.isJDBCStore()) {
                            acked = store.hasMessageBeenAcked(destination, msgid);
                        }
                        if (!acked) {
                            try {
              // This test may fail to spot that this really is
              // the last ack because another thread processing an
              // ack for the same message may not have yet
              // incremented ackCnt.
              // However, it should not return a false positive so
              // should be safe
              boolean isLastAck = false;
              synchronized (this) {
                isLastAck = (ackCnt + 1 + deadCnt) >= interestCnt;
              }

              store.updateInterestState(destination, msgid,
                  storedid,
                  Store.INTEREST_STATE_ACKNOWLEDGED,
                  Destination.PERSIST_SYNC && sync, tuid,
                  isLastAck);
View Full Code Here

                   Globals.getBrokerResources().getKString(
                   BrokerResources.W_HA_MASTER_BROKER_NOT_ALLOWED,
                   CONFIG_SERVER+"="+mbroker));
        }
       // make sure store is JDBC
       Store store = Globals.getStore();
       if (!store.isJDBCStore()) {
           throw new BrokerException(
                 Globals.getBrokerResources().getKString(
                 BrokerResources.E_HA_CLUSTER_INVALID_STORE_TYPE));
       }
View Full Code Here

             this.state = state;
             this.session = session;
             this.takeoverBroker = "";
             this.brokerSessionUID = new UID();

             Store store = Globals.getStore();
             store.addBrokerInfo(brokerid, address.toString(), state,
                    this.version.intValue(), session.longValue(),
                    heartbeat);

             this.heartbeat = store.getBrokerHeartbeat(brokerid);
        }
View Full Code Here

         */
        public synchronized long updateHeartbeat(boolean reset)
            throws BrokerException
        {
            // this one always accesses the backing store
            Store store = Globals.getStore();
            Long newheartbeat  = null;

            if (reset) {
                if ((newheartbeat = store.updateBrokerHeartbeat(brokerid)) == null) {
                    throw new BrokerException(Globals.getBrokerResources().getKString(
                          BrokerResources.X_UPDATE_HEARTBEAT_TS_2_FAILED, brokerid,
                          "Failed to reset heartbeat timestamp."));
                }
            } else {

            if ((newheartbeat = store.updateBrokerHeartbeat(brokerid, heartbeat)) == null) {
                // TS is out of sync so log warning msg and force update
                logger.log(Logger.WARNING,
                    Globals.getBrokerResources().getKString(
                    BrokerResources.X_UPDATE_HEARTBEAT_TS_2_FAILED, brokerid,
                    "Reset heartbeat timestamp due to synchronization problem." ) );

                if ((newheartbeat = store.updateBrokerHeartbeat(brokerid)) == null) {
                    // We really have a problem
                    throw new BrokerException(
                        Globals.getBrokerResources().getKString(
                        BrokerResources.X_UPDATE_HEARTBEAT_TS_2_FAILED, brokerid,
                        "Failed to reset heartbeat timestamp."));
View Full Code Here

             if (!local) {
                 throw new IllegalAccessException(
                 "Can not update entry " + " for broker " + brokerid);
             }

             Store store = Globals.getStore();
             UID ssid = store.updateBrokerInfo(brokerid, updateType, oldValue, newValue);
             try {
                 heartbeat = store.getBrokerHeartbeat(brokerid);
             } catch (Exception ex) {
                 logger.logStack(logger.WARNING, ex.getMessage()+"["+brokerid+"]", ex);
             }
             return ssid;
        }
View Full Code Here

        try {
            enforceLimit = destMessages.getEnforceLimits();
            destMessages.enforceLimits(false);

            Store store = Globals.getStore();
            Enumeration msgs = null;
            try {
                msgs = store.messageEnumeration(this);
            } catch (DestinationNotFoundException e) {
                if (noerrnotfound) {
                    logger.log(Logger.INFO, br.getKString(
                           BrokerResources.I_LOAD_DST_NOTFOUND_INSTORE,
                           getName(), e.getMessage()));
                    return null;
                }
                throw e;
            }

            SortedSet s = null;
            try { // no other store access should occur in this block

            HAMonitorService haMonitor = Globals.getHAMonitorService();
            boolean takingoverCheck = (takeoverMsgs == null &&
                                 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 ) {
View Full Code Here

        synchronized(destinationList) {
            d = (Destination)destinationList.get(uid);

            if (d == null) {
                try {
                    Store pstore = Globals.getStore();
                    d = pstore.getDestination(uid);
                    if (d != null) {
                        addDestination(d, false);
                    }
                } catch (Exception ex) {
                    // ignore we want to create it
View Full Code Here

                        BrokerResources.X_DESTINATION_EXISTS,
                        duid));
        }
        // OK, check the persistent store (required for HA)
        try {
            Store pstore = Globals.getStore();
            Destination d = pstore.getDestination(duid);
            if (d != null) {
                addDestination(d, false);
                return d;
            }
        } catch (Exception ex) {
View Full Code Here

     * allow administratively repair - eg. through imqbrokerd option
     * to force set last config server info to the current master broker
     *
     */
    private void checkStoredLastConfigServer() throws BrokerException {
        Store s =  Globals.getStore();

        boolean bad = false;
        boolean potentiallyBad = false;
        LoadException le  =  s.getLoadPropertyException();
        LoadException savele = null;
        while (le != null) {
            Object o = le.getKey();
            if (o == null || ! (o instanceof String)) {
                potentiallyBad = true;
                savele = le;
                le = le.getNextException();
                continue;
            }
            if (((String)o).equals(ClusterGlobals.STORE_PROPERTY_LASTCONFIGSERVER)) {
              logger.log(Logger.ERROR, BrokerResources.E_CLUSTER_LOAD_LASTCONFIGSERVER, le);
              bad = true;           
              break;
            }
            if (((String)o).equals(ClusterGlobals.STORE_PROPERTY_LASTREFRESHTIME)) {
                logger.log(Logger.WARNING, BrokerResources.W_CLUSTER_LOAD_LASTREFRESHTIME, le);
                try {
                s.updateProperty(ClusterGlobals.STORE_PROPERTY_LASTREFRESHTIME, new Long(-1), false);
                } catch (BrokerException e) {
                logger.log(Logger.ERROR, BrokerResources.E_CLUSTER_RESET_LASTREFRESHTIME, e);
                bad = true;
                break;
                };
            }
            le = le.getNextException();
        }
        if (potentiallyBad && !bad) {
            try {
                if (s.getProperty(ClusterGlobals.STORE_PROPERTY_LASTCONFIGSERVER) == null) {
                   logger.log(Logger.ERROR, BrokerResources.E_CLUSTER_LOAD_LASTCONFIGSERVER, savele);
                   bad = true;
                }
            } catch (BrokerException e) {
                logger.log(Logger.ERROR, e.getMessage(), e);
View Full Code Here

TOP

Related Classes of com.sun.messaging.jmq.jmsserver.persist.Store

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.