Search in sources :

Example 6 with BrokerAddress

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

the class TransactionInformation method setAckBrokerAddress.

public synchronized void setAckBrokerAddress(SysMessageID sysid, ConsumerUID id, BrokerAddress addr) throws BrokerException {
    BrokerAddress ba = (BrokerAddress) sysidToAddr.get(sysid);
    if (ba != null && (!ba.equals(addr) || !ba.getBrokerSessionUID().equals(addr.getBrokerSessionUID()))) {
        BrokerException bex = new BrokerException("Message requeued:" + sysid, Status.GONE);
        bex.setRemoteConsumerUIDs(String.valueOf(id.longValue()));
        bex.setRemote(true);
        throw bex;
    }
    sysidToAddr.put(sysid, addr);
}
Also used : BrokerException(com.sun.messaging.jmq.jmsserver.util.BrokerException) BrokerAddress(com.sun.messaging.jmq.jmsserver.core.BrokerAddress)

Example 7 with BrokerAddress

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

the class ClusterImpl method shutdown.

/**
 * Shutdown the cluster.
 */
@Override
public void shutdown(boolean force, BrokerAddress excludedBroker) {
    if (listener != null && excludedBroker == null) {
        // Stop accepting connections.
        listener.shutdown();
    }
    if (brokerList == null) {
        return;
    }
    synchronized (fileTransferExecutors) {
        fileTransferShutdownIn = true;
        if (excludedBroker == null) {
            fileTransferShutdownOut = true;
        }
        Iterator<Map.Entry<String, ExecutorService>> itr = fileTransferExecutors.entrySet().iterator();
        Map.Entry<String, ExecutorService> entry = null;
        while (itr.hasNext()) {
            entry = itr.next();
            entry.getValue().shutdownNow();
            itr.remove();
        }
    }
    long timeout = Globals.getConfig().getIntProperty(SHUTDOWN_TIMEOUT_PROP, DEFAULT_SHUTDOWN_TIMEOUT);
    long waittime = timeout * 1000;
    long endtime = System.currentTimeMillis() + waittime;
    int pv = -1;
    try {
        pv = Globals.getClusterBroadcast().getClusterVersion();
    } catch (Exception e) {
        logger.log(logger.DEBUG, "Unable to get cluster protocol version on cluster shutdown: " + e.getMessage());
    }
    if (pv >= ClusterBroadcast.VERSION_400 && !force) {
        synchronized (brokerList) {
            while (brokerList.size() != 0) {
                if (brokerList.size() == 1 && excludedBroker != null) {
                    if (brokerList.get(excludedBroker) != null) {
                        break;
                    }
                }
                logger.log(logger.INFO, br.getKString(br.I_CLUSTER_SERVICE_SHUTDOWN_WAITING, Integer.valueOf(brokerList.size())));
                try {
                    brokerList.wait(waittime);
                } catch (Exception e) {
                }
                long curtime = System.currentTimeMillis();
                if (curtime >= endtime) {
                    if (brokerList.size() > 0) {
                        logger.log(logger.WARNING, br.getKString(br.W_CLUSTER_SERVICE_SHUTDOWN_TIMEOUT));
                    }
                    break;
                }
                waittime = endtime - curtime;
            }
        }
    }
    BrokerAddress remote = null;
    BrokerLink l = null;
    synchronized (brokerList) {
        Iterator itr = brokerList.keySet().iterator();
        while (itr.hasNext()) {
            remote = (BrokerAddress) itr.next();
            if (excludedBroker != null && remote.equals(excludedBroker)) {
                continue;
            }
            l = (BrokerLink) brokerList.get(remote);
            logger.log(logger.WARNING, br.getKString(br.W_CLUSTER_FORCE_CLOSE_LINK, remote, br.getString(br.M_LINK_SHUTDOWN)));
            l.shutdown();
            itr.remove();
        }
    }
    synchronized (connectList) {
        Collection values = connectList.values();
        Iterator itr = values.iterator();
        while (itr.hasNext()) {
            BrokerLink link = (BrokerLink) itr.next();
            if (excludedBroker != null) {
                BrokerAddress addr = link.getRemote();
                if (addr != null && addr.equals(excludedBroker)) {
                    continue;
                }
            }
            link.shutdown();
        }
    }
    if (warningTask != null) {
        try {
            warningTask.cancel();
        } catch (Exception e) {
        }
        warningTask = null;
    }
    if (pingTimer != null) {
        try {
            pingTimer.cancel();
        } catch (Exception e) {
        }
        pingTimer = null;
    }
}
Also used : LoopbackAddressException(com.sun.messaging.jmq.jmsserver.util.LoopbackAddressException) LoadException(com.sun.messaging.jmq.jmsserver.persist.api.LoadException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) BrokerException(com.sun.messaging.jmq.jmsserver.util.BrokerException) BrokerAddress(com.sun.messaging.jmq.jmsserver.core.BrokerAddress) ExecutorService(java.util.concurrent.ExecutorService)

Example 8 with BrokerAddress

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

the class ClusterImpl method closeLink.

private void closeLink(String brokerID, UID storeSession) {
    if (!Globals.getHAEnabled()) {
        return;
    }
    BrokerAddress remote = null;
    BrokerLink l = null;
    synchronized (brokerList) {
        Iterator itr = brokerList.keySet().iterator();
        while (itr.hasNext()) {
            remote = (BrokerAddress) itr.next();
            l = (BrokerLink) brokerList.get(remote);
            if (remote.getBrokerID().equals(brokerID) && (storeSession == null || remote.getStoreSessionUID().equals(storeSession))) {
                logger.log(logger.WARNING, br.getKString(br.W_CLUSTER_CLOSE_DOWN_BROKER_LINK, remote));
                l.closeConn(false);
            }
        }
    }
}
Also used : BrokerAddress(com.sun.messaging.jmq.jmsserver.core.BrokerAddress)

Example 9 with BrokerAddress

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

the class RemoteTxnConverter method convert.

void convert(TransactionInformation txnInfo) throws BrokerException {
    if (ToTxnLogConverter.DEBUG) {
        logger.log(Logger.DEBUG, getPrefix() + " convert " + txnInfo);
    }
    // should be a prepared transaction
    int state = txnInfo.getState().getState();
    if (state != TransactionState.PREPARED) {
        String msg = getPrefix() + " convert: unknown state  " + state + " for " + txnInfo;
        logger.log(Logger.ERROR, msg);
    }
    TransactionUID txid = txnInfo.getTID();
    TransactionState newState = new TransactionState(txnInfo.getState());
    RemoteTransactionAckEntry[] rtaes = transactionList.getRecoveryRemoteTransactionAcks(txid);
    if (rtaes != null) {
        ArrayList<TransactionAcknowledgement> al = new ArrayList<>();
        for (int i = 0; i < rtaes.length; i++) {
            RemoteTransactionAckEntry rtae = rtaes[i];
            TransactionAcknowledgement[] txnAcks = rtae.getAcks();
            for (int j = 0; j < txnAcks.length; j++) {
                al.add(txnAcks[j]);
            }
        }
        TransactionAcknowledgement[] txnAcks = al.toArray(new TransactionAcknowledgement[al.size()]);
        DestinationUID[] destIds = new DestinationUID[txnAcks.length];
        for (int i = 0; i < txnAcks.length; i++) {
            SysMessageID sid = txnAcks[i].getSysMessageID();
            PacketReference p = DL.get((PartitionedStore) store, sid);
            DestinationUID destID = null;
            if (p != null) {
                destID = p.getDestinationUID();
            } else {
                logger.log(Logger.WARNING, "Could not find packet for " + sid);
            }
            destIds[i] = destID;
        }
        TransactionBroker txnBroker = transactionList.getRemoteTransactionHomeBroker(txid);
        BrokerAddress txnHomeBroker = txnBroker.getBrokerAddress();
        RemoteTransaction remoteTxn = new RemoteTransaction(txid, newState, txnAcks, destIds, txnHomeBroker);
        store.logTxn(remoteTxn);
    } else {
        logger.log(Logger.ERROR, "Could not find RemoteTransactionAckEntry for " + txid);
    }
}
Also used : ArrayList(java.util.ArrayList) BrokerAddress(com.sun.messaging.jmq.jmsserver.core.BrokerAddress) DestinationUID(com.sun.messaging.jmq.jmsserver.core.DestinationUID) PacketReference(com.sun.messaging.jmq.jmsserver.core.PacketReference) SysMessageID(com.sun.messaging.jmq.io.SysMessageID) RemoteTransactionAckEntry(com.sun.messaging.jmq.jmsserver.cluster.api.RemoteTransactionAckEntry)

Example 10 with BrokerAddress

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

the class TransactionDAOImpl method getTransactionInfo.

/**
 * Get the TransactionInfo object.
 *
 * @param conn database connection
 * @param txnUID the transaction ID
 * @return TransactionInfo object
 */
@Override
public TransactionInfo getTransactionInfo(Connection conn, TransactionUID txnUID) throws BrokerException {
    TransactionInfo txnInfo = null;
    long id = txnUID.longValue();
    boolean myConn = false;
    PreparedStatement pstmt = null;
    ResultSet rs = 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, selectTxnInfoSQL);
        pstmt.setLong(1, id);
        rs = pstmt.executeQuery();
        if (rs.next()) {
            int type = rs.getInt(1);
            int state = rs.getInt(2);
            TransactionState txnState = (TransactionState) Util.readObject(rs, 3);
            // update state in TransactionState object
            txnState.setState(state);
            BrokerAddress txnHomeBroker = (BrokerAddress) Util.readObject(rs, 4);
            TransactionBroker[] txnBrokers = (TransactionBroker[]) Util.readObject(rs, 5);
            txnInfo = new TransactionInfo(txnState, txnHomeBroker, txnBrokers, type);
        } else {
            throw new BrokerException(br.getKString(BrokerResources.E_TRANSACTIONID_NOT_FOUND_IN_STORE, String.valueOf(id)), Status.NOT_FOUND);
        }
    } 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("[" + selectTxnInfoSQL + "]", (SQLException) e);
        } else {
            ex = e;
        }
        BrokerException be = new BrokerException(br.getKString(BrokerResources.X_LOAD_TRANSACTION_FAILED, txnUID), ex);
        be.setSQLRecoverable(true);
        throw be;
    } finally {
        if (myConn) {
            Util.close(rs, pstmt, conn, myex);
        } else {
            Util.close(rs, pstmt, null, myex);
        }
    }
    return txnInfo;
}
Also used : TransactionState(com.sun.messaging.jmq.jmsserver.data.TransactionState) IOException(java.io.IOException) BrokerAddress(com.sun.messaging.jmq.jmsserver.core.BrokerAddress) TransactionBroker(com.sun.messaging.jmq.jmsserver.data.TransactionBroker) TransactionInfo(com.sun.messaging.jmq.jmsserver.persist.api.TransactionInfo)

Aggregations

BrokerAddress (com.sun.messaging.jmq.jmsserver.core.BrokerAddress)34 BrokerException (com.sun.messaging.jmq.jmsserver.util.BrokerException)18 ConsumerUID (com.sun.messaging.jmq.jmsserver.core.ConsumerUID)14 DestinationUID (com.sun.messaging.jmq.jmsserver.core.DestinationUID)10 SysMessageID (com.sun.messaging.jmq.io.SysMessageID)9 Consumer (com.sun.messaging.jmq.jmsserver.core.Consumer)9 PacketReference (com.sun.messaging.jmq.jmsserver.core.PacketReference)9 TransactionBroker (com.sun.messaging.jmq.jmsserver.data.TransactionBroker)9 IOException (java.io.IOException)8 HashMap (java.util.HashMap)8 UID (com.sun.messaging.jmq.util.UID)7 SelectorFormatException (com.sun.messaging.jmq.util.selector.SelectorFormatException)7 ArrayList (java.util.ArrayList)7 TransactionUID (com.sun.messaging.jmq.jmsserver.data.TransactionUID)6 CacheHashMap (com.sun.messaging.jmq.util.CacheHashMap)6 TransactionList (com.sun.messaging.jmq.jmsserver.data.TransactionList)5 AckEntryNotFoundException (com.sun.messaging.jmq.jmsserver.util.AckEntryNotFoundException)5 Iterator (java.util.Iterator)5 List (java.util.List)5 Destination (com.sun.messaging.jmq.jmsserver.core.Destination)4