Search in sources :

Example 31 with BrokerAddress

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

the class ClusterSubscriptionInfo method getConsumer.

public Consumer getConsumer() throws Exception {
    assert (pkt != null);
    short type = pkt.getType();
    assert (type == ProtocolGlobals.G_DURABLE_ATTACH);
    ByteArrayInputStream bis = new ByteArrayInputStream(pkt.getPayload().array());
    DataInputStream dis = new DataInputStream(bis);
    Consumer cs = ClusterConsumerInfo.readConsumer(dis);
    Integer prefetch = (Integer) pkt.getProp(cs.getConsumerUID().longValue() + ":" + Consumer.PREFETCH);
    if (prefetch != null) {
        cs.setRemotePrefetch(prefetch.intValue());
    }
    BrokerAddress from = c.unmarshalBrokerAddress(pkt);
    if (from != null) {
        cs.getConsumerUID().setBrokerAddress(from);
    }
    return cs;
}
Also used : Consumer(com.sun.messaging.jmq.jmsserver.core.Consumer) BrokerAddress(com.sun.messaging.jmq.jmsserver.core.BrokerAddress)

Example 32 with BrokerAddress

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

the class BrokerLink method consumeLinkInit.

/**
 * Process the LINK_INIT packet for connections initiated by this BrokerLink thread..
 *
 * @return BrokerAddressImpl for link request else LinkInfo if allowNonLinkRequest true
 */
protected static Object consumeLinkInit(Socket s, BrokerLink l, ClusterImpl cl, boolean allowNonLinkRequest) throws IOException {
    if (DEBUG) {
        logger.log(logger.INFO, "BrokerLink.consumeLinkInit(" + allowNonLinkRequest + ")");
    }
    BrokerAddressImpl b = null;
    InputStream is = s.getInputStream();
    Packet p = new Packet();
    p.readPacket(is);
    if (ClusterManagerImpl.isDEBUG_CLUSTER_PACKET() || (ClusterManagerImpl.isDEBUG_CLUSTER_PING() && p.getPacketType() == Packet.PING) || ClusterManagerImpl.isDEBUG_CLUSTER_PACKET()) {
        logger.log(Logger.INFO, "RECEIVING PACKET : " + (l == null ? "from " + s.getInetAddress() : l) + "\nPacket = " + p);
    }
    if (p.getPacketType() != Packet.LINK_INIT) {
        if (DEBUG) {
            logger.log(logger.INFO, ((l == null) ? ("Socket=" + s.getInetAddress()) : "Link=" + l) + ", expect LINK_INIT but got:" + p.getPacketType());
        }
        s.close();
        return null;
    }
    LinkInfo li = null;
    try {
        li = ClusterImpl.processLinkInit(p);
        b = li.getAddress();
        if (l != null && b.getMQAddress().equals(l.self.getMQAddress())) {
            String[] args = { b.getHost().toString(), s.getInetAddress().toString(), l.self.toString() + " <---> " + b.toString() };
            throw new BrokerException(br.getString(br.E_MBUS_BAD_ADDRESS, args));
        }
        if (l != null && b.equals(l.self)) {
            String[] args = { b.toShortString(), s.getInetAddress().toString(), l.self.toString() + " <---> " + b.toString() };
            logger.log(Logger.ERROR, br.getKString(br.E_MBUS_SAME_ADDRESS_AS_ME, args));
            Broker.getBroker().exit(1, br.getString(br.E_MBUS_SAME_ADDRESS_AS_ME, args), BrokerEvent.Type.FATAL_ERROR, null, false, true, false);
            throw new BrokerException(br.getString(br.E_MBUS_SAME_ADDRESS_AS_ME, args));
        }
    } catch (BrokerException e) {
        logger.log(Logger.ERROR, br.getKString(br.E_CLUSTER_BAD_LINK_INIT, s.getInetAddress().toString()), e);
        if (l == null) {
            s.close();
        } else {
            l.shutdown();
        }
        return null;
    } catch (Exception e) {
        if (DEBUG) {
            logger.logStack(Logger.ERROR, s.getInetAddress().toString(), e);
        }
        s.close();
        return null;
    }
    if (DEBUG) {
        logger.log(logger.INFO, "Return from processLinkInit()");
    }
    if (!li.isLinkRequest()) {
        if (!allowNonLinkRequest) {
            logger.log(Logger.ERROR, br.getKString(br.E_CLUSTER_UNEXPECTED_PACKET_FROM, "LINK_INIT[" + li.getAddress().getClusterVersion() + "]", s.getInetAddress().toString()));
            if (l == null) {
                s.close();
            } else {
                l.shutdown();
            }
            return null;
        }
        return li;
    }
    if (l != null) {
        l.setRemote(b);
    }
    if (cl.checkConfigServer(b) == false) {
        BrokerAddressImpl master = (BrokerAddressImpl) cl.getConfiguredConfigServer();
        if (master != null) {
            Integer lognum = (Integer) waitingMasterLogs.get(b.getMQAddress());
            if (lognum == null || lognum.intValue() % 30 == 0) {
                logger.log(Logger.INFO, br.I_CLUSTER_WAITING_MASTER, b, master);
            } else {
                logger.log(Logger.DEBUG, br.I_CLUSTER_WAITING_MASTER, b, master);
            }
            synchronized (waitingMasterLogs) {
                Integer num = (Integer) waitingMasterLogs.get(b.getMQAddress());
                if (num == null) {
                    waitingMasterLogs.put(b.getMQAddress(), Integer.valueOf(1));
                } else {
                    waitingMasterLogs.put(b.getMQAddress(), Integer.valueOf(num.intValue() + 1));
                }
            }
        } else {
            // should never happen
            logger.log(Logger.ERROR, BrokerResources.E_INTERNAL_BROKER_ERROR, "No master broker. Closing cluster connection with " + b);
        }
        // Not ready yet.
        // Need to sync with config server first.
        s.close();
        return null;
    }
    /*
         * Make sure that remote broker is using the same 'config server'. If not, something is very wrong with the
         * configuration. Log an error and stop talking to that broker (i.e. kill this BrokerLink).
         */
    try {
        BrokerAddress mymaster = cl.getConfigServer();
        BrokerAddress remotemaster = li.getConfigServer();
        if (((mymaster == null || remotemaster == null) && mymaster != remotemaster) || ((mymaster != null && remotemaster != null) && !(mymaster.getMQAddress().equals(remotemaster.getMQAddress())))) {
            String[] args = new String[] { b.toString(), (mymaster == null ? "null" : mymaster.getMQAddress().toString()), (remotemaster == null ? "null" : remotemaster.getMQAddress().toString()) };
            logger.log(Logger.ERROR, br.getKString(BrokerResources.E_MBUS_CONFIG_MISMATCH1, args));
            if (l == null) {
                s.close();
            } else {
                l.shutdown();
            }
            return null;
        }
    } catch (Exception e) {
        logger.logStack(Logger.DEBUG, e.getMessage() + ((l == null) ? ("Socket " + s.getInetAddress()) : ("Link " + l)), e);
        if (l == null) {
            s.close();
        } else {
            l.linkDown();
        }
        return null;
    }
    if (DEBUG) {
        logger.log(Logger.INFO, "remote.matchProps = " + li.getMatchProps());
        logger.log(Logger.INFO, "local.matchProps = " + cl.getMatchProps());
    }
    Properties remoteProps = li.getMatchProps();
    Properties myProps = cl.getMatchProps();
    String diff = BrokerLink.compareProps(myProps, remoteProps);
    if (diff != null) {
        logger.log(Logger.ERROR, br.E_MBUS_CONFIG_MISMATCH2, b, diff);
        if (l == null) {
            s.close();
        } else {
            l.shutdown();
        }
        return null;
    }
    if (DEBUG) {
        logger.log(logger.INFO, "BrokerLink.consumeLinkInit() finished");
    }
    assert (b != null);
    return b;
}
Also used : BrokerException(com.sun.messaging.jmq.jmsserver.util.BrokerException) HandshakeInProgressException(com.sun.messaging.jmq.jmsserver.multibroker.HandshakeInProgressException) BrokerException(com.sun.messaging.jmq.jmsserver.util.BrokerException) BrokerAddress(com.sun.messaging.jmq.jmsserver.core.BrokerAddress)

Example 33 with BrokerAddress

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

the class CallbackDispatcher method processCommitAck.

private boolean processCommitAck(final BrokerAddress sender, final GPacket pkt) {
    if (!ClusterMessageAckInfo.isAckAckAsync(pkt)) {
        return false;
    }
    Integer acktype = ClusterMessageAckInfo.getAckAckType(pkt);
    if (acktype == null || acktype.intValue() != ClusterGlobals.MB_MSG_CONSUMED) {
        return false;
    }
    Long transactionID = ClusterMessageAckInfo.getAckAckTransactionID(pkt);
    if (transactionID == null) {
        return false;
    }
    if (ClusterMessageAckInfo.getAckAckStatus(pkt) != Status.OK) {
        logger.log(logger.WARNING, br.getKString(br.W_CLUSTER_MSG_ACK_FAILED_FROM_HOME, sender, ClusterMessageAckInfo.toString(pkt)));
        return true;
    }
    if (DEBUG_CLUSTER_TXN || DEBUG) {
        logger.log(logger.INFO, "processCommitAck: Received " + ProtocolGlobals.getPacketTypeDisplayString(pkt.getType()) + " from " + sender + ": " + ClusterMessageAckInfo.toString(pkt));
    }
    if (fi.FAULT_INJECTION) {
        ClusterMessageAckInfo.CHECKFAULT(new HashMap(), ClusterGlobals.MB_MSG_CONSUMED, transactionID, FaultInjection.MSG_REMOTE_ACK_P, FaultInjection.STAGE_3);
    }
    try {
        final TransactionUID tuid = new TransactionUID(transactionID.longValue());
        final UID ss = ClusterMessageAckInfo.getAckAckStoreSessionUID(pkt);
        commitAckExecutor.execute(new Runnable() {

            @Override
            public void run() {
                try {
                    BrokerAddress addr = sender;
                    if (ss != null) {
                        addr = (BrokerAddress) sender.clone();
                        addr.setStoreSessionUID(ss);
                    }
                    Object[] oo = TransactionList.getTransListAndState(tuid, null, true, false);
                    if (oo == null) {
                        logger.log(logger.INFO, Globals.getBrokerResources().getKString(BrokerResources.W_TXN_NOT_FOUND_ON_UPDATE_TXN_COMPLETION_FOR_BKR, tuid, addr));
                        return;
                    }
                    TransactionList tl = (TransactionList) oo[0];
                    tl.completeClusterTransactionBrokerState(tuid, TransactionState.COMMITTED, addr, true);
                } catch (Throwable t) {
                    Object[] args = { tuid, sender + "[" + ClusterMessageAckInfo.toString(pkt) + "]", t.getMessage() };
                    String emsg = br.getKString(br.W_UNABLE_UPDATE_CLUSTER_TXN_COMPLETE_STATE, args);
                    if (t instanceof BrokerException) {
                        if (((BrokerException) t).getStatusCode() == Status.NOT_FOUND) {
                            if (DEBUG_CLUSTER_TXN || DEBUG) {
                                logger.log(logger.WARNING, emsg + " - already completed");
                            }
                            return;
                        }
                    }
                    logger.logStack(logger.WARNING, emsg, t);
                }
            }
        });
    } catch (Throwable t) {
        if (stopThread) {
            logger.log(logger.DEBUG, "Cluster shutdown, ignore event " + ClusterMessageAckInfo.toString(pkt) + " from " + sender);
        } else {
            logger.logStack(logger.WARNING, "Exception in submitting for processing " + ClusterMessageAckInfo.toString(pkt) + " from " + sender, t);
        }
    }
    return true;
}
Also used : BrokerException(com.sun.messaging.jmq.jmsserver.util.BrokerException) TransactionList(com.sun.messaging.jmq.jmsserver.data.TransactionList) BrokerAddress(com.sun.messaging.jmq.jmsserver.core.BrokerAddress) TransactionUID(com.sun.messaging.jmq.jmsserver.data.TransactionUID) ConsumerUID(com.sun.messaging.jmq.jmsserver.core.ConsumerUID) DestinationUID(com.sun.messaging.jmq.jmsserver.core.DestinationUID) UID(com.sun.messaging.jmq.util.UID) ConnectionUID(com.sun.messaging.jmq.jmsserver.service.ConnectionUID) TransactionUID(com.sun.messaging.jmq.jmsserver.data.TransactionUID)

Example 34 with BrokerAddress

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

the class ClusterTxnInfoInfo method toString.

/**
 * To be called by sender
 */
@Override
public String toString() {
    if (pkt == null) {
        StringBuilder buf = new StringBuilder();
        buf.append("\n\tTransactionID = ").append(transactionID);
        buf.append("\n\tTransactionState = ").append(TransactionState.toString(transactionState));
        if (txnHome != null) {
            buf.append("\n\tTransactionHome = ").append(txnHome);
        }
        if (brokers != null) {
            StringBuilder bf = new StringBuilder();
            for (int i = 0; i < brokers.length; i++) {
                if (i > 0) {
                    bf.append(',');
                }
                bf.append(brokers[i].toProtocolString());
            }
            buf.append("\n\tBrokers = ").append(bf.toString());
        }
        if (waitfor != null) {
            StringBuilder bf = new StringBuilder();
            for (int i = 0; i < waitfor.length; i++) {
                if (i > 0) {
                    bf.append(',');
                }
                bf.append(waitfor[i].toProtocolString());
            }
            buf.append("\n\tWaitfor = ").append(bf.toString());
        }
        if (xid != null) {
            buf.append("\n\tXID = ").append(xid);
        }
        buf.append('\n');
        return buf.toString();
    }
    // pkt == null
    StringBuilder buf = new StringBuilder();
    buf.append("\n\tTransactionID = ").append(getTransactionID());
    buf.append("\n\tTransactionState = ").append(TransactionState.toString(getTransactionState()));
    try {
        BrokerAddress b = getTransactionHome();
        if (b != null) {
            buf.append("\n\tTransactionHome = ").append(b);
        }
    } catch (Exception e) {
        buf.append("\n\tTransactionHome = ERROR:").append(e);
    }
    BrokerAddress[] bas = null;
    try {
        bas = getBrokers();
        if (bas != null) {
            StringBuilder bf = new StringBuilder();
            for (int i = 0; i < bas.length; i++) {
                if (i > 0) {
                    bf.append(',');
                }
                bf.append(bas[i].toProtocolString());
            }
            buf.append("\n\tBrokers = ").append(bf.toString());
        }
    } catch (Exception e) {
        buf.append("\n\tBrokers = ERROR:").append(e);
    }
    try {
        List wbas = getWaitfor();
        if (wbas != null) {
            Iterator itr = wbas.iterator();
            StringBuilder bf = new StringBuilder();
            int i = 0;
            while (itr.hasNext()) {
                if (i > 0) {
                    bf.append(',');
                }
                bf.append(((BrokerAddress) itr.next()).toProtocolString());
                i++;
            }
            buf.append("\n\tWaitfor = ").append(bf.toString());
        }
    } catch (Exception e) {
        buf.append("\n\tWaitfor = ERROR:").append(e);
    }
    if (pkt.getProp("X") != null) {
        buf.append("\n\tXID = ").append(pkt.getProp("X"));
    }
    buf.append('\n');
    return buf.toString();
}
Also used : BrokerAddress(com.sun.messaging.jmq.jmsserver.core.BrokerAddress)

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