Search in sources :

Example 26 with DestinationUID

use of com.sun.messaging.jmq.jmsserver.core.DestinationUID in project openmq by eclipse-ee4j.

the class MessageDAOImpl method getDebugInfo.

/**
 * Get debug information about the store.
 *
 * @param conn database connection
 * @return A HashMap of name value pair of information
 */
@Override
public HashMap getDebugInfo(Connection conn) {
    if (!Boolean.getBoolean(getTableName())) {
        return super.getDebugInfo(conn);
    }
    HashMap map = new LinkedHashMap();
    HashMap baddata = new LinkedHashMap();
    String brokerid = null;
    Object data = null;
    try {
        brokerid = DBManager.getDBManager().getBrokerID();
        data = getMsgIDsAndDstIDsByBroker(null, brokerid);
        map.put("[" + tableName + "]RowCount(brokerID=" + brokerid + ")", String.valueOf(((Map) data).size()));
        String sysid = null;
        Iterator itr = ((Map) data).keySet().iterator();
        while (itr.hasNext()) {
            sysid = (String) itr.next();
            String dst = (String) ((Map) data).get(sysid);
            boolean bad = false;
            try {
                SysMessageID.get(sysid);
            } catch (RuntimeException e) {
                bad = true;
                baddata.put("EXCEPTION-MESSAGE_ID[" + sysid + "]", dst);
                logger.logStack(logger.ERROR, "Failed to validate SysMessageID for message ID=" + sysid + " in destination " + dst + ": " + e.getMessage(), e);
            }
            try {
                Packet pkt = getMessage(null, new DestinationUID(dst), sysid);
                if (bad) {
                    logger.logToAll(logger.INFO, "Packet for message ID=" + sysid + "[" + pkt + "]");
                }
            } catch (Exception e) {
                baddata.put("EXCEPTION-PACKET[" + sysid + "]", dst);
                logger.logStack(logger.ERROR, "Failed to retrieve mesage Packet for  message ID=" + sysid + " in destination " + dst + ": " + e.getMessage(), e);
            }
        }
    } catch (Exception e) {
        data = e.getMessage();
        logger.logStack(logger.ERROR, e.getMessage(), e);
    }
    map.put("[" + tableName + "]SysMessageID:DestinationID(brokerID=" + brokerid + ")\n", data);
    if (!baddata.isEmpty()) {
        map.put("EXCEPTION!![" + tableName + "]SysMessageID:DestinationID(brokerID=" + brokerid + ")\n", baddata);
    }
    return map;
}
Also used : Packet(com.sun.messaging.jmq.io.Packet) DestinationUID(com.sun.messaging.jmq.jmsserver.core.DestinationUID) PacketReadEOFException(com.sun.messaging.jmq.io.PacketReadEOFException) InvalidPacketException(com.sun.messaging.jmq.io.InvalidPacketException)

Example 27 with DestinationUID

use of com.sun.messaging.jmq.jmsserver.core.DestinationUID in project openmq by eclipse-ee4j.

the class DBTool method doRestore.

/*
     * Restore the JDBC store from filebased backup files.
     */
private void doRestore() throws BrokerException {
    if (!Globals.getHAEnabled()) {
        throw new BrokerException(br.getKString(BrokerResources.I_HA_NOT_ENABLE, dbmgr.getBrokerID()));
    }
    // instantiate the file store.
    Properties props = System.getProperties();
    String clusterID = Globals.getClusterID();
    String backupDir = (String) props.get(Globals.IMQ + ".backupdir") + File.separator + clusterID;
    logger.logToAll(Logger.INFO, "Restore persistent store for HA cluster " + clusterID + " from backup dir: " + backupDir);
    final FileStore fileStore = new FileStore(backupDir, false);
    // Brokers table.
    JDBCStore jdbcStore = null;
    try {
        // Re-create the jdbc store
        doRecreate();
        jdbcStore = (JDBCStore) StoreManager.getStore();
        /*
             * For data that are not broker specific, i.e. properties, change records, consumers, brokers, and sessions, we will
             * retrieve those data from the top level directory (a.k.a cluster filestore).
             */
        // Properties table
        List haBrokers = null;
        Properties properties = fileStore.getAllProperties();
        Iterator propItr = properties.entrySet().iterator();
        while (propItr.hasNext()) {
            Map.Entry entry = (Map.Entry) propItr.next();
            String name = (String) entry.getKey();
            if (name.equals(STORE_PROPERTY_HABROKERS)) {
                // Retrieve all HABrokerInfo from a property
                haBrokers = (List) entry.getValue();
            } else {
                jdbcStore.updateProperty(name, entry.getValue(), false);
            }
        }
        propItr = null;
        properties = null;
        if (haBrokers == null || haBrokers.isEmpty()) {
            throw new BrokerException(br.getKString(BrokerResources.X_LOAD_ALL_BROKERINFO_FAILED));
        }
        // Configuration Change Record table
        List<ChangeRecordInfo> records = fileStore.getAllConfigRecords();
        for (int i = 0, len = records.size(); i < len; i++) {
            jdbcStore.storeConfigChangeRecord(records.get(i).getTimestamp(), records.get(i).getRecord(), false);
        }
        records = null;
        // Consumer table
        Consumer[] consumerArray = fileStore.getAllInterests();
        for (int i = 0; i < consumerArray.length; i++) {
            jdbcStore.storeInterest(consumerArray[i], false);
        }
        consumerArray = null;
        // Broker & Session table.
        Iterator bkrItr = haBrokers.iterator();
        while (bkrItr.hasNext()) {
            HABrokerInfo bkrInfo = (HABrokerInfo) bkrItr.next();
            jdbcStore.addBrokerInfo(bkrInfo, false);
        }
        /*
             * For each broker in the cluster, we will retrieve broker specific data, destinations, messages, transactions,
             * acknowledgements from their own filestore (a.k.a broker filestore).
             */
        bkrItr = haBrokers.iterator();
        while (bkrItr.hasNext()) {
            // Backup data for each broker
            HABrokerInfo bkrInfo = (HABrokerInfo) bkrItr.next();
            String brokerID = bkrInfo.getId();
            long sessionID = bkrInfo.getSessionID();
            logger.logToAll(Logger.INFO, "Restore persistent data for broker " + brokerID);
            FileStore bkrFS = null;
            JMSBridgeStore jmsbridgeStore = null;
            try {
                String instanceRootDir = backupDir + File.separator + brokerID;
                bkrFS = new FileStore(instanceRootDir, false);
                // Destination table.
                Destination[] dstArray = bkrFS.getAllDestinations();
                for (int i = 0, len = dstArray.length; i < len; i++) {
                    DestinationUID did = dstArray[i].getDestinationUID();
                    Destination dst = jdbcStore.getDestination(did);
                    if (dst == null) {
                        // Store the destination if not found
                        jdbcStore.storeDestination(dstArray[i], sessionID);
                    }
                }
                // Retrieve messages for each destination.
                for (int i = 0, len = dstArray.length; i < len; i++) {
                    for (Enumeration e = bkrFS.messageEnumeration(dstArray[i]); e.hasMoreElements(); ) {
                        DestinationUID did = dstArray[i].getDestinationUID();
                        Packet message = (Packet) e.nextElement();
                        SysMessageID mid = message.getSysMessageID();
                        // Get interest states for the message; Consumer State table
                        HashMap stateMap = bkrFS.getInterestStates(did, mid);
                        if (stateMap == null || stateMap.isEmpty()) {
                            jdbcStore.storeMessage(did, message, null, null, sessionID, false);
                        } else {
                            int size = stateMap.size();
                            ConsumerUID[] iids = new ConsumerUID[size];
                            int[] states = new int[size];
                            Iterator stateItr = stateMap.entrySet().iterator();
                            int j = 0;
                            while (stateItr.hasNext()) {
                                Map.Entry entry = (Map.Entry) stateItr.next();
                                iids[j] = (ConsumerUID) entry.getKey();
                                states[j] = ((Integer) entry.getValue()).intValue();
                                j++;
                            }
                            jdbcStore.storeMessage(did, message, iids, states, sessionID, false);
                        }
                    }
                }
                // Transaction table
                Collection txnList = bkrFS.getTransactions(brokerID);
                Iterator txnItr = txnList.iterator();
                while (txnItr.hasNext()) {
                    TransactionUID tid = (TransactionUID) txnItr.next();
                    TransactionInfo txnInfo = bkrFS.getTransactionInfo(tid);
                    TransactionAcknowledgement[] txnAck = bkrFS.getTransactionAcks(tid);
                    jdbcStore.storeTransaction(tid, txnInfo, sessionID);
                    for (int i = 0, len = txnAck.length; i < len; i++) {
                        jdbcStore.storeTransactionAck(tid, txnAck[i], false);
                    }
                }
                /**
                 ************************************************
                 * JMSBridge
                 *************************************************
                 */
                Properties bp = new Properties();
                bp.setProperty("instanceRootDir", instanceRootDir);
                bp.setProperty("reset", "false");
                bp.setProperty("logdomain", "imqdbmgr");
                jmsbridgeStore = (JMSBridgeStore) BridgeServiceManager.getExportedService(JMSBridgeStore.class, "JMS", bp);
                if (jmsbridgeStore != null) {
                    List bnames = jmsbridgeStore.getJMSBridges(null);
                    String bname = null;
                    Iterator itr = bnames.iterator();
                    while (itr.hasNext()) {
                        bname = (String) itr.next();
                        jdbcStore.addJMSBridge(bname, true, null);
                    }
                    jmsbridgeStore.closeJMSBridgeStore();
                    jmsbridgeStore = null;
                    bname = null;
                    itr = bnames.iterator();
                    while (itr.hasNext()) {
                        bname = (String) itr.next();
                        bp.setProperty("jmsbridge", bname);
                        if (jmsbridgeStore != null) {
                            jmsbridgeStore.closeJMSBridgeStore();
                            jmsbridgeStore = null;
                        }
                        logger.logToAll(logger.INFO, "Restore JMS bridge " + bname);
                        jmsbridgeStore = (JMSBridgeStore) BridgeServiceManager.getExportedService(JMSBridgeStore.class, "JMS", bp);
                        List xids = jmsbridgeStore.getTMLogRecordKeysByName(bname, null);
                        logger.logToAll(logger.INFO, "\tRestore JMS bridge " + bname + " with " + xids.size() + " TM log records");
                        String xid = null;
                        byte[] lr = null;
                        Iterator itr1 = xids.iterator();
                        while (itr1.hasNext()) {
                            xid = (String) itr1.next();
                            lr = jmsbridgeStore.getTMLogRecord(xid, bname, null);
                            if (lr == null) {
                                logger.logToAll(Logger.INFO, "JMSBridge TM log record not found for " + xid);
                                continue;
                            }
                            jdbcStore.storeTMLogRecord(xid, lr, bname, true, null);
                        }
                    }
                }
            } finally {
                bkrFS.close();
                if (jmsbridgeStore != null) {
                    jmsbridgeStore.closeJMSBridgeStore();
                }
            }
        }
        logger.logToAll(Logger.INFO, "Restore persistent store complete.");
    } catch (Throwable ex) {
        ex.printStackTrace();
        throw new BrokerException(ex.getMessage());
    } finally {
        assert fileStore != null;
        try {
            fileStore.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
        StoreManager.releaseStore(true);
    }
}
Also used : Destination(com.sun.messaging.jmq.jmsserver.core.Destination) HABrokerInfo(com.sun.messaging.jmq.jmsserver.persist.api.HABrokerInfo) Consumer(com.sun.messaging.jmq.jmsserver.core.Consumer) TransactionInfo(com.sun.messaging.jmq.jmsserver.persist.api.TransactionInfo) JMSBridgeStore(com.sun.messaging.bridge.api.JMSBridgeStore) Packet(com.sun.messaging.jmq.io.Packet) TransactionAcknowledgement(com.sun.messaging.jmq.jmsserver.data.TransactionAcknowledgement) ConsumerUID(com.sun.messaging.jmq.jmsserver.core.ConsumerUID) TransactionUID(com.sun.messaging.jmq.jmsserver.data.TransactionUID) FileStore(com.sun.messaging.jmq.jmsserver.persist.file.FileStore) DestinationUID(com.sun.messaging.jmq.jmsserver.core.DestinationUID) SysMessageID(com.sun.messaging.jmq.io.SysMessageID) ChangeRecordInfo(com.sun.messaging.jmq.jmsserver.persist.api.ChangeRecordInfo)

Example 28 with DestinationUID

use of com.sun.messaging.jmq.jmsserver.core.DestinationUID in project openmq by eclipse-ee4j.

the class ConsumerDAOImpl method delete.

/**
 * Delete an existing entry.
 *
 * @param conn database connection
 * @param consumer the Consumer
 * @throws BrokerException if entry does not exists in the store
 */
@Override
public void delete(Connection conn, Consumer consumer) throws BrokerException {
    ConsumerUID consumerUID = consumer.getConsumerUID();
    boolean deleted = false;
    boolean myConn = false;
    PreparedStatement pstmt = null;
    Exception myex = null;
    try {
        // Get a connection
        DBManager dbMgr = DBManager.getDBManager();
        if (conn == null) {
            conn = dbMgr.getConnection(true);
            myConn = true;
        }
        pstmt = dbMgr.createPreparedStatement(conn, deleteSQL);
        pstmt.setLong(1, consumerUID.longValue());
        if (pstmt.executeUpdate() > 0) {
            deleted = true;
        }
    } catch (Exception e) {
        myex = e;
        try {
            if ((conn != null) && !conn.getAutoCommit()) {
                conn.rollback();
            }
        } catch (SQLException rbe) {
            logger.log(Logger.ERROR, BrokerResources.X_DB_ROLLBACK_FAILED, rbe);
        }
        Exception ex;
        if (e instanceof BrokerException) {
            throw (BrokerException) e;
        } else if (e instanceof SQLException) {
            ex = DBManager.wrapSQLException("[" + deleteSQL + "]", (SQLException) e);
        } else {
            ex = e;
        }
        throw new BrokerException(br.getKString(BrokerResources.X_REMOVE_INTEREST_FAILED, consumerUID), ex);
    } finally {
        if (myConn) {
            Util.close(null, pstmt, conn, myex);
        } else {
            Util.close(null, pstmt, null, myex);
        }
    }
    if (!deleted) {
        DestinationUID destinationUID = consumer.getDestinationUID();
        throw new BrokerException(br.getKString(BrokerResources.E_INTEREST_NOT_FOUND_IN_STORE, consumerUID, destinationUID), Status.NOT_FOUND);
    }
}
Also used : DestinationUID(com.sun.messaging.jmq.jmsserver.core.DestinationUID) ConsumerUID(com.sun.messaging.jmq.jmsserver.core.ConsumerUID) IOException(java.io.IOException)

Example 29 with DestinationUID

use of com.sun.messaging.jmq.jmsserver.core.DestinationUID in project openmq by eclipse-ee4j.

the class ConsumerUtil method getDestinationUID.

public static DestinationUID getDestinationUID(ConsumerUID cid) {
    Consumer con = Consumer.getConsumer(cid);
    DestinationUID id = null;
    if (con != null) {
        id = con.getDestinationUID();
    }
    return (id);
}
Also used : DestinationUID(com.sun.messaging.jmq.jmsserver.core.DestinationUID) Consumer(com.sun.messaging.jmq.jmsserver.core.Consumer)

Example 30 with DestinationUID

use of com.sun.messaging.jmq.jmsserver.core.DestinationUID in project openmq by eclipse-ee4j.

the class DestinationUtil method createDestination.

@SuppressWarnings("deprecation")
public static void createDestination(DestinationInfo info) throws BrokerException {
    String errMsg = null;
    int status = Status.OK;
    BrokerResources rb = Globals.getBrokerResources();
    Logger logger = Globals.getLogger();
    // Default attributes of the destination
    int type = DestType.DEST_TYPE_QUEUE | DestType.DEST_FLAVOR_SINGLE;
    int maxMessages = -1;
    SizeString maxMessageBytes = null;
    SizeString maxMessageSize = null;
    if (MemoryGlobals.getMEM_DISALLOW_CREATE_DEST()) {
        status = Status.ERROR;
        errMsg = rb.W_LOW_MEM_REJECT_DEST;
    } else if (info.isModified(DestinationInfo.NAME)) {
        if (info.isModified(DestinationInfo.TYPE)) {
            type = info.type;
        }
        if (info.isModified(DestinationInfo.MAX_MESSAGES)) {
            maxMessages = info.maxMessages;
        }
        if (info.isModified(DestinationInfo.MAX_MESSAGE_BYTES)) {
            maxMessageBytes = new SizeString();
            maxMessageBytes.setBytes(info.maxMessageBytes);
        }
        if (info.isModified(DestinationInfo.MAX_MESSAGE_SIZE)) {
            maxMessageSize = new SizeString();
            maxMessageSize.setBytes(info.maxMessageSize);
        }
    } else {
        status = Status.ERROR;
        errMsg = rb.X_NO_DEST_NAME_SET;
    }
    // XXX create destination
    if (status == Status.OK) {
        if (DestType.destNameIsInternal(info.name)) {
            status = Status.ERROR;
            errMsg = rb.getKString(rb.X_CANNOT_CREATE_INTERNAL_DEST, info.name, DestType.INTERNAL_DEST_PREFIX);
        } else {
            if (CreateDestinationHandler.isValidDestinationName(info.name)) {
                try {
                    Globals.getDestinationList().createDestination(null, info.name, type);
                } catch (Exception ex) {
                    status = Status.ERROR;
                    errMsg = rb.getString(rb.X_CREATE_DEST_EXCEPTION, info.name, getMessageFromException(ex));
                    if (ex instanceof ConflictException) {
                        logger.log(Logger.INFO, errMsg, ex);
                    } else {
                        logger.logStack(Logger.INFO, errMsg, ex);
                    }
                }
            } else {
                status = Status.ERROR;
                errMsg = rb.getKString(rb.X_DEST_NAME_INVALID, info.name);
            }
        }
    }
    if (status == Status.OK) {
        try {
            Destination[] ds = Globals.getDestinationList().getDestination(null, info.name, DestType.isQueue(type));
            Destination d = ds[0];
            d.setCapacity(maxMessages);
            d.setByteCapacity(maxMessageBytes);
            d.setMaxByteSize(maxMessageSize);
            if (info.isModified(info.DEST_SCOPE)) {
                int scope = info.destScope;
                d.setScope(scope);
            }
            if (info.isModified(info.DEST_LIMIT)) {
                int destlimit = info.destLimitBehavior;
                d.setLimitBehavior(destlimit);
            }
            if (info.isModified(info.DEST_PREFETCH)) {
                int prefetch = info.maxPrefetch;
                d.setMaxPrefetch(prefetch);
            }
            if (info.isModified(info.DEST_CDP)) {
                int clusterdeliverypolicy = info.destCDP;
                d.setClusterDeliveryPolicy(clusterdeliverypolicy);
            }
            if (info.isModified(info.MAX_ACTIVE_CONSUMERS)) {
                int maxcons = info.maxActiveConsumers;
                d.setMaxActiveConsumers(maxcons);
            }
            if (info.isModified(info.MAX_PRODUCERS)) {
                int maxp = info.maxProducers;
                d.setMaxProducers(maxp);
            }
            if (info.isModified(info.MAX_FAILOVER_CONSUMERS)) {
                int maxcons = info.maxFailoverConsumers;
                d.setMaxFailoverConsumers(maxcons);
            }
            if (info.isModified(info.MAX_SHARED_CONSUMERS)) {
                int maxsharedcons = info.maxNumSharedConsumers;
                d.setMaxSharedConsumers(maxsharedcons);
            }
            if (info.isModified(info.SHARE_FLOW_LIMIT)) {
                int sflowlimit = info.sharedConsumerFlowLimit;
                d.setSharedFlowLimit(sflowlimit);
            }
            if (info.isModified(info.USE_DMQ)) {
                boolean dmq = info.useDMQ;
                d.setUseDMQ(dmq);
            }
            d.update();
        /*
                 * // audit logging for create destination Globals.getAuditSession().destinationOperation( con.getUserName(),
                 * con.remoteHostString(), MQAuditSession.CREATE_DESTINATION, d.isQueue()?MQAuditSession.QUEUE:MQAuditSession.TOPIC,
                 * d.getDestinationName());
                 */
        } catch (Exception ex) {
            // remove the destination
            try {
                DestinationUID duid = DestinationUID.getUID(info.name, DestType.isQueue(type));
                Globals.getDestinationList().removeDestination(null, duid, false, ex.toString());
            } catch (Exception ex1) {
            // if we cant destroy .. its ok .. ignore the exception
            }
            status = Status.ERROR;
            errMsg = rb.getString(rb.X_UPDATE_DEST_EXCEPTION, info.name, getMessageFromException(ex));
            logger.log(Logger.WARNING, errMsg, ex);
        }
    }
    if (status != Status.OK) {
        throw new BrokerException(errMsg);
    }
}
Also used : Destination(com.sun.messaging.jmq.jmsserver.core.Destination) SizeString(com.sun.messaging.jmq.util.SizeString) DestinationUID(com.sun.messaging.jmq.jmsserver.core.DestinationUID) BrokerException(com.sun.messaging.jmq.jmsserver.util.BrokerException) ConflictException(com.sun.messaging.jmq.jmsserver.util.ConflictException) SizeString(com.sun.messaging.jmq.util.SizeString) Logger(com.sun.messaging.jmq.util.log.Logger) BrokerResources(com.sun.messaging.jmq.jmsserver.resources.BrokerResources) ConflictException(com.sun.messaging.jmq.jmsserver.util.ConflictException) BrokerException(com.sun.messaging.jmq.jmsserver.util.BrokerException)

Aggregations

DestinationUID (com.sun.messaging.jmq.jmsserver.core.DestinationUID)61 Destination (com.sun.messaging.jmq.jmsserver.core.Destination)25 ConsumerUID (com.sun.messaging.jmq.jmsserver.core.ConsumerUID)20 BrokerException (com.sun.messaging.jmq.jmsserver.util.BrokerException)20 Iterator (java.util.Iterator)18 SysMessageID (com.sun.messaging.jmq.io.SysMessageID)16 Consumer (com.sun.messaging.jmq.jmsserver.core.Consumer)16 PacketReference (com.sun.messaging.jmq.jmsserver.core.PacketReference)10 Producer (com.sun.messaging.jmq.jmsserver.core.Producer)9 ArrayList (java.util.ArrayList)9 Packet (com.sun.messaging.jmq.io.Packet)8 SelectorFormatException (com.sun.messaging.jmq.util.selector.SelectorFormatException)8 IOException (java.io.IOException)8 ProducerUID (com.sun.messaging.jmq.jmsserver.core.ProducerUID)6 PartitionedStore (com.sun.messaging.jmq.jmsserver.persist.api.PartitionedStore)6 HashMap (java.util.HashMap)6 BrokerAddress (com.sun.messaging.jmq.jmsserver.core.BrokerAddress)5 DestinationList (com.sun.messaging.jmq.jmsserver.core.DestinationList)5 Session (com.sun.messaging.jmq.jmsserver.core.Session)5 SessionUID (com.sun.messaging.jmq.jmsserver.core.SessionUID)5