org.apache.activemq.command.BrokerId - java examples

Here are the examples of the java api org.apache.activemq.command.BrokerId taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

24 Examples 7

19 View Complete Implementation : BrokerIdTest.java
Copyright Apache License 2.0
Author : apache
@Override
protected void populateObject(Object object) throws Exception {
    super.populateObject(object);
    BrokerId info = (BrokerId) object;
    info.setValue("Value:1");
}

19 View Complete Implementation : BrokerIdTest.java
Copyright Apache License 2.0
Author : apache
@Override
public Object createObject() throws Exception {
    BrokerId info = new BrokerId();
    populateObject(info);
    return info;
}

17 View Complete Implementation : OpenWireMessageConverter.java
Copyright Apache License 2.0
Author : apache
private static void setAMQMsgClusterPath(final ActiveMQMessage amqMsg, final String clusterPath) {
    String[] cluster = clusterPath.split(",");
    BrokerId[] bids = new BrokerId[cluster.length];
    for (int i = 0; i < bids.length; i++) {
        bids[i] = new BrokerId(cluster[i]);
    }
    amqMsg.setCluster(bids);
}

17 View Complete Implementation : OpenWireMessageConverter.java
Copyright Apache License 2.0
Author : apache
private static void putMsgBrokerPath(final BrokerId[] brokers, final CoreMessage coreMessage) {
    final StringBuilder builder = new StringBuilder();
    for (int i = 0, size = brokers.length; i < size; i++) {
        builder.append(brokers[i].getValue());
        if (i != (size - 1)) {
            // is this separator safe?
            builder.append(',');
        }
    }
    coreMessage.putStringProperty(AMQ_MSG_BROKER_PATH, new SimpleString(builder.toString()));
}

17 View Complete Implementation : OpenWireMessageConverter.java
Copyright Apache License 2.0
Author : apache
private static void putMsgCluster(final BrokerId[] cluster, final CoreMessage coreMessage) {
    final StringBuilder builder = new StringBuilder();
    for (int i = 0, size = cluster.length; i < size; i++) {
        builder.append(cluster[i].getValue());
        if (i != (size - 1)) {
            // is this separator safe?
            builder.append(',');
        }
    }
    coreMessage.putStringProperty(AMQ_MSG_CLUSTER, new SimpleString(builder.toString()));
}

17 View Complete Implementation : OpenWireMessageConverter.java
Copyright Apache License 2.0
Author : apache
private static void setAMQMsgBrokerPath(final ActiveMQMessage amqMsg, final String brokerPath) {
    String[] brokers = brokerPath.split(",");
    BrokerId[] bids = new BrokerId[brokers.length];
    for (int i = 0; i < bids.length; i++) {
        bids[i] = new BrokerId(brokers[i]);
    }
    amqMsg.setBrokerPath(bids);
}

17 View Complete Implementation : ArtemisBrokerBase.java
Copyright Apache License 2.0
Author : apache
public abstract clreplaced ArtemisBrokerBase implements Broker {

    private static final Logger LOG = LoggerFactory.getLogger(ArtemisBrokerBase.clreplaced);

    public static final String INVM_ACCEPTOR_FACTORY = InVMAcceptorFactory.clreplaced.getCanonicalName();

    public static final String NETTY_ACCEPTOR_FACTORY = NettyAcceptorFactory.clreplaced.getCanonicalName();

    public static final String NETTY_CONNECTOR_FACTORY = NettyConnectorFactory.clreplaced.getCanonicalName();

    protected static final String CLUSTER_PreplacedWORD = "UnitTestsClusterPreplacedword";

    protected volatile boolean stopped;

    protected BrokerId brokerId = new BrokerId("Artemis Broker");

    protected BrokerService bservice;

    protected final File temporaryFolder;

    protected final String testDir;

    protected boolean realStore = false;

    protected ActiveMQServer server;

    protected boolean enableSecurity = false;

    public ArtemisBrokerBase(File temporaryFolder) {
        this.temporaryFolder = temporaryFolder;
        this.testDir = temporaryFolder.getAbsolutePath();
    }

    @Override
    public Destination addDestination(ConnectionContext context, ActiveMQDestination destination, boolean createIfTemporary) throws Exception {
        throw new RuntimeException("Don't call me!");
    }

    @Override
    public void removeDestination(ConnectionContext context, ActiveMQDestination destination, long timeout) throws Exception {
        throw new RuntimeException("Don't call me!");
    }

    @Override
    public Map<ActiveMQDestination, Destination> getDestinationMap() {
        throw new RuntimeException("Don't call me!");
    }

    @Override
    public Subscription addConsumer(ConnectionContext context, ConsumerInfo info) throws Exception {
        throw new RuntimeException("Don't call me!");
    }

    @Override
    public void removeConsumer(ConnectionContext context, ConsumerInfo info) throws Exception {
        throw new RuntimeException("Don't call me!");
    }

    @Override
    public void removeSubscription(ConnectionContext context, RemoveSubscriptionInfo info) throws Exception {
        throw new RuntimeException("Don't call me!");
    }

    @Override
    public void send(ProducerBrokerExchange producerExchange, Message message) throws Exception {
        throw new RuntimeException("Don't call me!");
    }

    @Override
    public void acknowledge(ConsumerBrokerExchange consumerExchange, MessageAck ack) throws Exception {
        throw new RuntimeException("Don't call me!");
    }

    @Override
    public Response messagePull(ConnectionContext context, MessagePull pull) throws Exception {
        throw new RuntimeException("Don't call me!");
    }

    @Override
    public void processDispatchNotification(MessageDispatchNotification messageDispatchNotification) throws Exception {
        throw new RuntimeException("Don't call me!");
    }

    @Override
    public void gc() {
        throw new RuntimeException("Don't call me!");
    }

    @Override
    public Set<Destination> getDestinations(ActiveMQDestination destination) {
        throw new RuntimeException("Don't call me!");
    }

    @Override
    public void processConsumerControl(ConsumerBrokerExchange consumerExchange, ConsumerControl control) {
        throw new RuntimeException("Don't call me!");
    }

    @Override
    public void reapplyInterceptor() {
        throw new RuntimeException("Don't call me!");
    }

    @Override
    public Broker getAdaptor(Clreplaced type) {
        throw new RuntimeException("Don't call me!");
    }

    @Override
    public BrokerId getBrokerId() {
        return brokerId;
    }

    @Override
    public String getBrokerName() {
        return "Artemis Broker";
    }

    @Override
    public void addBroker(Connection connection, BrokerInfo info) {
        throw new RuntimeException("Don't call me!");
    }

    @Override
    public void removeBroker(Connection connection, BrokerInfo info) {
        throw new RuntimeException("Don't call me!");
    }

    @Override
    public void addConnection(ConnectionContext context, ConnectionInfo info) throws Exception {
        throw new RuntimeException("Don't call me!");
    }

    @Override
    public void removeConnection(ConnectionContext context, ConnectionInfo info, Throwable error) throws Exception {
        throw new RuntimeException("Don't call me!");
    }

    @Override
    public void addSession(ConnectionContext context, SessionInfo info) throws Exception {
        throw new RuntimeException("Don't call me!");
    }

    @Override
    public void removeSession(ConnectionContext context, SessionInfo info) throws Exception {
        throw new RuntimeException("Don't call me!");
    }

    @Override
    public void addProducer(ConnectionContext context, ProducerInfo info) throws Exception {
        throw new RuntimeException("Don't call me!");
    }

    @Override
    public void removeProducer(ConnectionContext context, ProducerInfo info) throws Exception {
        throw new RuntimeException("Don't call me!");
    }

    @Override
    public Connection[] getClients() throws Exception {
        throw new RuntimeException("Don't call me!");
    }

    @Override
    public ActiveMQDestination[] getDestinations() throws Exception {
        throw new RuntimeException("Don't call me!");
    }

    @Override
    public Map<ActiveMQDestination, Destination> getDestinationMap(ActiveMQDestination destination) {
        throw new RuntimeException("Don't call me!");
    }

    @Override
    public TransactionId[] getPreparedTransactions(ConnectionContext context) throws Exception {
        throw new RuntimeException("Don't call me!");
    }

    @Override
    public void beginTransaction(ConnectionContext context, TransactionId xid) throws Exception {
        throw new RuntimeException("Don't call me!");
    }

    @Override
    public int prepareTransaction(ConnectionContext context, TransactionId xid) throws Exception {
        throw new RuntimeException("Don't call me!");
    }

    @Override
    public void rollbackTransaction(ConnectionContext context, TransactionId xid) throws Exception {
        throw new RuntimeException("Don't call me!");
    }

    @Override
    public void commitTransaction(ConnectionContext context, TransactionId xid, boolean onePhase) throws Exception {
        throw new RuntimeException("Don't call me!");
    }

    @Override
    public void forgetTransaction(ConnectionContext context, TransactionId transactionId) throws Exception {
        throw new RuntimeException("Don't call me!");
    }

    @Override
    public BrokerInfo[] getPeerBrokerInfos() {
        return null;
    }

    @Override
    public void preProcessDispatch(MessageDispatch messageDispatch) {
        throw new RuntimeException("Don't call me!");
    }

    @Override
    public void postProcessDispatch(MessageDispatch messageDispatch) {
        throw new RuntimeException("Don't call me!");
    }

    @Override
    public boolean isStopped() {
        return stopped;
    }

    @Override
    public Set<ActiveMQDestination> getDurableDestinations() {
        throw new RuntimeException("Don't call me!");
    }

    @Override
    public void addDestinationInfo(ConnectionContext context, DestinationInfo info) throws Exception {
        throw new RuntimeException("Don't call me!");
    }

    @Override
    public void removeDestinationInfo(ConnectionContext context, DestinationInfo info) throws Exception {
        throw new RuntimeException("Don't call me!");
    }

    @Override
    public boolean isFaultTolerantConfiguration() {
        return false;
    }

    @Override
    public ConnectionContext getAdminConnectionContext() {
        return null;
    }

    @Override
    public void setAdminConnectionContext(ConnectionContext adminConnectionContext) {
    // 
    }

    @Override
    public PListStore getTempDataStore() {
        throw new RuntimeException("Don't call me!");
    }

    @Override
    public URI getVmConnectorURI() {
        throw new RuntimeException("Don't call me!");
    }

    @Override
    public void brokerServiceStarted() {
        stopped = false;
    }

    @Override
    public BrokerService getBrokerService() {
        return this.bservice;
    }

    @Override
    public Broker getRoot() {
        return this;
    }

    @Override
    public boolean isExpired(MessageReference messageReference) {
        throw new RuntimeException("Don't call me!");
    }

    @Override
    public void messageExpired(ConnectionContext context, MessageReference messageReference, Subscription subscription) {
        throw new RuntimeException("Don't call me!");
    }

    @Override
    public boolean sendToDeadLetterQueue(ConnectionContext context, MessageReference messageReference, Subscription subscription, Throwable poisonCause) {
        throw new RuntimeException("Don't call me!");
    }

    @Override
    public long getBrokerSequenceId() {
        throw new RuntimeException("Don't call me!");
    }

    @Override
    public void messageConsumed(ConnectionContext context, MessageReference messageReference) {
        throw new RuntimeException("Don't call me!");
    }

    @Override
    public void messageDelivered(ConnectionContext context, MessageReference messageReference) {
        throw new RuntimeException("Don't call me!");
    }

    @Override
    public void messageDiscarded(ConnectionContext context, Subscription sub, MessageReference messageReference) {
        throw new RuntimeException("Don't call me!");
    }

    @Override
    public void slowConsumer(ConnectionContext context, Destination destination, Subscription subs) {
        throw new RuntimeException("Don't call me!");
    }

    @Override
    public void fastProducer(ConnectionContext context, ProducerInfo producerInfo, ActiveMQDestination destination) {
        throw new RuntimeException("Don't call me!");
    }

    @Override
    public void isFull(ConnectionContext context, Destination destination, Usage usage) {
        throw new RuntimeException("Don't call me!");
    }

    @Override
    public void nowMasterBroker() {
    }

    @Override
    public Scheduler getScheduler() {
        throw new RuntimeException("Don't call me!");
    }

    @Override
    public ThreadPoolExecutor getExecutor() {
        throw new RuntimeException("Don't call me!");
    }

    @Override
    public void networkBridgeStarted(BrokerInfo brokerInfo, boolean createdByDuplex, String remoteIp) {
        throw new RuntimeException("Don't call me!");
    }

    @Override
    public void networkBridgeStopped(BrokerInfo brokerInfo) {
        throw new RuntimeException("Don't call me!");
    }

    protected final ActiveMQServer createServer(final boolean realFiles, final boolean netty) throws Exception {
        return createServer(realFiles, createDefaultConfig(netty), -1, -1, new HashMap<String, AddressSettings>());
    }

    protected final ActiveMQServer createServer(final boolean realFiles, final Configuration configuration, final int pageSize, final int maxAddressSize, final Map<String, AddressSettings> settings) {
        return createServer(realFiles, configuration, pageSize, maxAddressSize, AddressFullMessagePolicy.PAGE, settings);
    }

    protected final ActiveMQServer createServer(final boolean realFiles, final Configuration configuration, final int pageSize, final int maxAddressSize, final AddressFullMessagePolicy fullPolicy, final Map<String, AddressSettings> settings) {
        ActiveMQServer server = ActiveMQServers.newActiveMQServer(configuration, realFiles);
        if (settings != null) {
            for (Map.Entry<String, AddressSettings> setting : settings.entrySet()) {
                server.getAddressSettingsRepository().addMatch(setting.getKey(), setting.getValue());
            }
        }
        AddressSettings defaultSetting = new AddressSettings();
        defaultSetting.setPageSizeBytes(pageSize);
        defaultSetting.setMaxSizeBytes(maxAddressSize);
        defaultSetting.setAddressFullMessagePolicy(fullPolicy);
        server.getAddressSettingsRepository().addMatch("#", defaultSetting);
        return server;
    }

    protected Configuration createDefaultConfig(final boolean netty) throws Exception {
        if (netty) {
            return createDefaultConfig(new HashMap<String, Object>(), NETTY_ACCEPTOR_FACTORY);
        } else {
            return createDefaultConfig(new HashMap<String, Object>(), INVM_ACCEPTOR_FACTORY);
        }
    }

    protected Configuration createDefaultConfig(final Map<String, Object> params, final String... acceptors) throws Exception {
        ConfigurationImpl configuration = createBasicConfig(-1).setJMXManagementEnabled(false).clearAcceptorConfigurations();
        for (String acceptor : acceptors) {
            TransportConfiguration transportConfig = new TransportConfiguration(acceptor, params);
            configuration.addAcceptorConfiguration(transportConfig);
        }
        return configuration;
    }

    protected final ConfigurationImpl createBasicConfig(final int serverID) {
        ConfigurationImpl configuration = new ConfigurationImpl().setSecurityEnabled(false).setJournalMinFiles(2).setJournalFileSize(100 * 1024).setJournalType(getDefaultJournalType()).setJournalDirectory(getJournalDir(serverID, false)).setBindingsDirectory(getBindingsDir(serverID, false)).setPagingDirectory(getPageDir(serverID, false)).setLargeMessagesDirectory(getLargeMessagesDir(serverID, false)).setJournalCompactMinFiles(0).setJournalCompactPercentage(0).setClusterPreplacedword(CLUSTER_PreplacedWORD);
        return configuration;
    }

    protected String getLargeMessagesDir(final int index, final boolean backup) {
        return getLargeMessagesDir(testDir, index, backup);
    }

    protected static String getLargeMessagesDir(final String testDir, final int index, final boolean backup) {
        return getLargeMessagesDir(testDir) + directoryNameSuffix(index, backup);
    }

    protected String getPageDir(final int index, final boolean backup) {
        return getPageDir(testDir, index, backup);
    }

    protected static String getPageDir(final String testDir, final int index, final boolean backup) {
        return getPageDir(testDir) + directoryNameSuffix(index, backup);
    }

    protected String getBindingsDir(final int index, final boolean backup) {
        return getBindingsDir(testDir, index, backup);
    }

    protected static String getBindingsDir(final String testDir, final int index, final boolean backup) {
        return getBindingsDir(testDir) + directoryNameSuffix(index, backup);
    }

    protected String getJournalDir(final int index, final boolean backup) {
        return getJournalDir(testDir, index, backup);
    }

    protected static String getJournalDir(final String testDir, final int index, final boolean backup) {
        return getJournalDir(testDir) + directoryNameSuffix(index, backup);
    }

    private static String directoryNameSuffix(int index, boolean backup) {
        if (index == -1)
            return "";
        return index + "-" + (backup ? "B" : "L");
    }

    protected static JournalType getDefaultJournalType() {
        if (LibaioContext.isLoaded()) {
            return JournalType.ASYNCIO;
        } else {
            return JournalType.NIO;
        }
    }

    protected final void clearDataRecreateServerDirs() {
        clearDataRecreateServerDirs(testDir);
    }

    protected void clearDataRecreateServerDirs(final String testDir1) {
        // Need to delete the root
        File file = new File(testDir1);
        deleteDirectory(file);
        file.mkdirs();
        recreateDirectory(getJournalDir(testDir1));
        recreateDirectory(getBindingsDir(testDir1));
        recreateDirectory(getPageDir(testDir1));
        recreateDirectory(getLargeMessagesDir(testDir1));
        recreateDirectory(getClientLargeMessagesDir(testDir1));
        recreateDirectory(getTemporaryDir(testDir1));
    }

    protected String getTemporaryDir(final String testDir1) {
        return testDir1 + "/temp";
    }

    protected String getClientLargeMessagesDir(final String testDir1) {
        return testDir1 + "/client-large-msg";
    }

    protected static String getLargeMessagesDir(final String testDir1) {
        return testDir1 + "/large-msg";
    }

    protected static String getPageDir(final String testDir1) {
        return testDir1 + "/page";
    }

    protected static String getBindingsDir(final String testDir1) {
        return testDir1 + "/bindings";
    }

    protected static String getJournalDir(final String testDir1) {
        return testDir1 + "/journal";
    }

    protected static final void recreateDirectory(final String directory) {
        File file = new File(directory);
        deleteDirectory(file);
        file.mkdirs();
    }

    protected static final boolean deleteDirectory(final File directory) {
        if (directory.isDirectory()) {
            String[] files = directory.list();
            int num = 5;
            int attempts = 0;
            while (files == null && (attempts < num)) {
                try {
                    Thread.sleep(100);
                } catch (InterruptedException e) {
                }
                files = directory.list();
                attempts++;
            }
            for (String file : files) {
                File f = new File(directory, file);
                if (!deleteDirectory(f)) {
                    LOG.warn("Failed to clean up file: " + f.getAbsolutePath());
                }
            }
        }
        return directory.delete();
    }

    public ActiveMQServer getServer() {
        return server;
    }
}

16 View Complete Implementation : DestinationInfoTest.java
Copyright Apache License 2.0
Author : apache
@Override
protected void populateObject(Object object) throws Exception {
    super.populateObject(object);
    DestinationInfo info = (DestinationInfo) object;
    info.setConnectionId(createConnectionId("ConnectionId:1"));
    info.setDestination(createActiveMQDestination("Destination:2"));
    info.setOperationType((byte) 1);
    info.setTimeout(1);
    {
        BrokerId[] value = new BrokerId[2];
        for (int i = 0; i < 2; i++) {
            value[i] = createBrokerId("BrokerPath:3");
        }
        info.setBrokerPath(value);
    }
}

16 View Complete Implementation : ProducerInfoTest.java
Copyright Apache License 2.0
Author : apache
@Override
protected void populateObject(Object object) throws Exception {
    super.populateObject(object);
    ProducerInfo info = (ProducerInfo) object;
    info.setProducerId(createProducerId("ProducerId:1"));
    info.setDestination(createActiveMQDestination("Destination:2"));
    {
        BrokerId[] value = new BrokerId[2];
        for (int i = 0; i < 2; i++) {
            value[i] = createBrokerId("BrokerPath:3");
        }
        info.setBrokerPath(value);
    }
}

16 View Complete Implementation : ProducerInfoTest.java
Copyright Apache License 2.0
Author : apache
@Override
protected void populateObject(Object object) throws Exception {
    super.populateObject(object);
    ProducerInfo info = (ProducerInfo) object;
    info.setProducerId(createProducerId("ProducerId:1"));
    info.setDestination(createActiveMQDestination("Destination:2"));
    {
        BrokerId[] value = new BrokerId[2];
        for (int i = 0; i < 2; i++) {
            value[i] = createBrokerId("BrokerPath:3");
        }
        info.setBrokerPath(value);
    }
    info.setDispatchAsync(true);
}

16 View Complete Implementation : ProducerInfoTest.java
Copyright Apache License 2.0
Author : apache
@Override
protected void populateObject(Object object) throws Exception {
    super.populateObject(object);
    ProducerInfo info = (ProducerInfo) object;
    info.setProducerId(createProducerId("ProducerId:1"));
    info.setDestination(createActiveMQDestination("Destination:2"));
    {
        BrokerId[] value = new BrokerId[2];
        for (int i = 0; i < 2; i++) {
            value[i] = createBrokerId("BrokerPath:3");
        }
        info.setBrokerPath(value);
    }
    info.setDispatchAsync(true);
    info.setWindowSize(1);
}

15 View Complete Implementation : BrokerService.java
Copyright Apache License 2.0
Author : apache
/**
 * Manages the life-cycle of an ActiveMQ Broker. A BrokerService consists of a
 * number of transport connectors, network connectors and a bunch of properties
 * which can be used to configure the broker as its lazily created.
 */
public clreplaced BrokerService implements Service {

    public static final String DEFAULT_PORT = "61616";

    public static final AtomicInteger RANDOM_PORT_BASE = new AtomicInteger(51616);

    public static final String DEFAULT_BROKER_NAME = "localhost";

    public static final String BROKER_VERSION;

    public static final int DEFAULT_MAX_FILE_LENGTH = 1024 * 1024 * 32;

    public static final long DEFAULT_START_TIMEOUT = 600000L;

    public static boolean disableWrapper = false;

    private SslContext sslContext;

    private static final Logger LOG = LoggerFactory.getLogger(BrokerService.clreplaced);

    @SuppressWarnings("unused")
    private static final long serialVersionUID = 7353129142305630237L;

    private String brokerName = DEFAULT_BROKER_NAME;

    private Broker broker;

    private BrokerId brokerId;

    private Throwable startException = null;

    private boolean startAsync = false;

    public Set<ConnectorInfo> extraConnectors = new HashSet<>();

    private List<TransportConnector> transportConnectors = new ArrayList<>();

    private File dataDirectoryFile;

    private PolicyMap destinationPolicy;

    private SystemUsage systemUsage;

    private final List<NetworkConnector> networkConnectors = new CopyOnWriteArrayList<>();

    private TemporaryFolder tmpfolder;

    public static WeakHashMap<Broker, Exception> map = new WeakHashMap<>();

    static {
        InputStream in;
        String version = null;
        if ((in = BrokerService.clreplaced.getResourcereplacedtream("/org/apache/activemq/version.txt")) != null) {
            BufferedReader reader = new BufferedReader(new InputStreamReader(in));
            try {
                version = reader.readLine();
            } catch (Exception e) {
            }
        }
        BROKER_VERSION = version;
    }

    @Override
    public String toString() {
        return "BrokerService[" + getBrokerName() + "]" + super.toString();
    }

    private String getBrokerVersion() {
        String version = ActiveMQConnectionMetaData.PROVIDER_VERSION;
        if (version == null) {
            version = BROKER_VERSION;
        }
        return version;
    }

    @Override
    public void start() throws Exception {
        File targetTmp = new File("./target/tmp");
        targetTmp.mkdirs();
        tmpfolder = new TemporaryFolder(targetTmp);
        tmpfolder.create();
        Exception e = new Exception();
        startBroker(startAsync);
        map.put(broker, e);
    }

    private void startBroker(boolean async) throws Exception {
        if (async) {
            new Thread("Broker Starting Thread") {

                @Override
                public void run() {
                    try {
                        doStartBroker();
                    } catch (Throwable t) {
                        startException = t;
                    }
                }
            }.start();
        } else {
            doStartBroker();
        }
    }

    private void doStartBroker() throws Exception {
        if (startException != null) {
            return;
        }
        broker = getBroker();
        brokerId = broker.getBrokerId();
        LOG.info("Apache ActiveMQ Artemis Wrapper {} ({}, {}) is starting", new Object[] { getBrokerVersion(), getBrokerName(), brokerId });
        try {
            broker.start();
        } catch (Exception e) {
            throw e;
        } catch (Throwable t) {
            throw new Exception(t);
        }
        LOG.info("Apache ActiveMQ Artemis Wrapper {} ({}, {}) started", new Object[] { getBrokerVersion(), getBrokerName(), brokerId });
        LOG.info("For help or more information please see: http://activemq.apache.org");
    }

    @Override
    public void stop() throws Exception {
        System.out.println("broker is: " + broker);
        LOG.info("Apache ActiveMQ Artemis{} ({}, {}) is shutting down", new Object[] { getBrokerVersion(), getBrokerName(), brokerId });
        if (broker != null) {
            broker.stop();
            broker = null;
        }
        tmpfolder.delete();
        LOG.info("Apache ActiveMQ Artemis {} ({}, {}) is shutdown", new Object[] { getBrokerVersion(), getBrokerName(), brokerId });
    }

    // Properties
    // -------------------------------------------------------------------------
    public Broker getBroker() throws Exception {
        if (broker == null) {
            broker = createBroker(tmpfolder.getRoot());
        }
        return broker;
    }

    public String getBrokerName() {
        return brokerName;
    }

    public void setBrokerName(String brokerName) {
        if (brokerName == null) {
            throw new NullPointerException("The broker name cannot be null");
        }
        String str = brokerName.replaceAll("[^a-zA-Z0-9\\.\\_\\-\\:]", "_");
        if (!str.equals(brokerName)) {
            LOG.error("Broker Name: {} contained illegal characters - replaced with {}", brokerName, str);
        }
        this.brokerName = str.trim();
    }

    protected Broker createBroker(File temporaryFile) throws Exception {
        broker = createBrokerWrapper(temporaryFile);
        return broker;
    }

    private Broker createBrokerWrapper(File temporaryFile) {
        return new ArtemisBrokerWrapper(this, temporaryFile);
    }

    public void makeSureDestinationExists(ActiveMQDestination activemqDestination) throws Exception {
        ArtemisBrokerWrapper hqBroker = (ArtemisBrokerWrapper) this.broker;
        // it can be null
        if (activemqDestination == null) {
            return;
        }
        if (activemqDestination.isQueue()) {
            String qname = activemqDestination.getPhysicalName();
            System.out.println("physical name: " + qname);
            hqBroker.makeSureQueueExists(qname);
        }
    }

    // below are methods called directly by tests
    // we don't actually implement many of these for now,
    // just to make test compile preplaced.
    public Broker getRegionBroker() {
        try {
            return RegionBrokerProxy.newRegionBroker((ArtemisBrokerWrapper) getBroker());
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    public void setPersistenceAdapter(PersistenceAdapter persistenceAdapter) throws IOException {
    }

    public File getDataDirectoryFile() {
        if (dataDirectoryFile == null) {
            dataDirectoryFile = new File(IOHelper.getDefaultDataDirectory());
        }
        return dataDirectoryFile;
    }

    public File getBrokerDataDirectory() {
        String brokerDir = getBrokerName();
        return new File(getDataDirectoryFile(), brokerDir);
    }

    public PersistenceAdapter getPersistenceAdapter() throws IOException {
        return null;
    }

    public void waitUntilStopped() {
    }

    public boolean waitUntilStarted() {
        return true;
    }

    public void setDestinationPolicy(PolicyMap policyMap) {
        this.destinationPolicy = policyMap;
    }

    public void setDeleteAllMessagesOnStartup(boolean deletePersistentMessagesOnStartup) {
    }

    public void setUseJmx(boolean useJmx) {
    }

    public ManagementContext getManagementContext() {
        return null;
    }

    public BrokerView getAdminView() throws Exception {
        return null;
    }

    public List<TransportConnector> getTransportConnectors() {
        return transportConnectors;
    }

    public TransportConnector addConnector(String bindAddress) throws Exception {
        return addConnector(new URI(bindAddress));
    }

    public void setIoExceptionHandler(IOExceptionHandler ioExceptionHandler) {
    }

    public void setPersistent(boolean persistent) {
    }

    public boolean isSlave() {
        return false;
    }

    public Destination getDestination(ActiveMQDestination destination) throws Exception {
        return null;
    }

    public void setAllowTempAutoCreationOnSend(boolean allowTempAutoCreationOnSend) {
    }

    public void setDedicatedTaskRunner(boolean dedicatedTaskRunner) {
    }

    public void setAdvisorySupport(boolean advisorySupport) {
    }

    public void setUseShutdownHook(boolean useShutdownHook) {
    }

    public void deleteAllMessages() throws IOException {
    }

    public Service[] getServices() {
        return null;
    }

    public void setPopulateUserNameInMBeans(boolean value) {
    }

    public void setDestinations(ActiveMQDestination[] destinations) {
    }

    public URI getVmConnectorURI() {
        try {
            URI subsreplaceduteUri = new URI("tcp://localhost:61616");
            return subsreplaceduteUri;
        } catch (URISyntaxException e) {
            e.printStackTrace();
        }
        return null;
    }

    public SystemUsage getSystemUsage() {
        if (systemUsage == null) {
            systemUsage = new SystemUsage();
        }
        return systemUsage;
    }

    public synchronized PListStore getTempDataStore() {
        return null;
    }

    public void setJmsBridgeConnectors(JmsConnector[] jmsConnectors) {
    }

    public void setDestinationInterceptors(DestinationInterceptor[] destinationInterceptors) {
    }

    public SslContext getSslContext() {
        return this.sslContext;
    }

    public void setDataDirectory(String dataDirectory) {
    }

    public void setPlugins(BrokerPlugin[] plugins) {
    }

    public void setKeepDurableSubsActive(boolean keepDurableSubsActive) {
    }

    public TransportConnector getConnectorByName(String connectorName) {
        return null;
    }

    public TransportConnector addConnector(TransportConnector connector) throws Exception {
        return connector;
    }

    public void setEnableStatistics(boolean enableStatistics) {
    }

    public void setSystemUsage(SystemUsage memoryManager) {
        this.systemUsage = memoryManager;
    }

    public void setManagementContext(ManagementContext managementContext) {
    }

    public void setSchedulerDirectoryFile(File schedulerDirectory) {
    }

    public NetworkConnector addNetworkConnector(String discoveryAddress) throws Exception {
        return addNetworkConnector(new URI(discoveryAddress));
    }

    public NetworkConnector addNetworkConnector(URI discoveryAddress) throws Exception {
        NetworkConnector connector = new DiscoveryNetworkConnector(discoveryAddress);
        return addNetworkConnector(connector);
    }

    public List<NetworkConnector> getNetworkConnectors() {
        return this.networkConnectors;
    }

    public void setSchedulerSupport(boolean schedulerSupport) {
    }

    public void setPopulateJMSXUserID(boolean populateJMSXUserID) {
    }

    public boolean isUseJmx() {
        return false;
    }

    public boolean isPersistent() {
        return false;
    }

    public TransportConnector getTransportConnectorByScheme(String scheme) {
        return null;
    }

    public TaskRunnerFactory getTaskRunnerFactory() {
        return null;
    }

    public boolean isStarted() {
        if (broker == null)
            return false;
        return !broker.isStopped();
    }

    public ProxyConnector addProxyConnector(ProxyConnector connector) throws Exception {
        return connector;
    }

    public void setDataDirectoryFile(File dataDirectoryFile) {
        this.dataDirectoryFile = dataDirectoryFile;
    }

    public PolicyMap getDestinationPolicy() {
        return this.destinationPolicy;
    }

    public void setTransportConnectorURIs(String[] transportConnectorURIs) {
    }

    public boolean isPopulateJMSXUserID() {
        return false;
    }

    public NetworkConnector getNetworkConnectorByName(String connectorName) {
        return null;
    }

    public boolean removeNetworkConnector(NetworkConnector connector) {
        return true;
    }

    public void setTransportConnectors(List<TransportConnector> transportConnectors) throws Exception {
        this.transportConnectors = transportConnectors;
        for (TransportConnector connector : transportConnectors) {
            if (sslContext instanceof SpringSslContext) {
                this.extraConnectors.add(new ConnectorInfo(connector.getUri(), (SpringSslContext) sslContext));
            } else {
                this.extraConnectors.add(new ConnectorInfo(connector.getUri()));
            }
        }
    }

    public NetworkConnector addNetworkConnector(NetworkConnector connector) throws Exception {
        connector.setBrokerService(this);
        System.out.println("------------------------ this broker uri: " + this.getConnectURI());
        connector.setLocalUri(this.getConnectURI());
        // Set a connection filter so that the connector does not establish loop
        // back connections.
        connector.setConnectionFilter(new ConnectionFilter() {

            @Override
            public boolean connectTo(URI location) {
                List<TransportConnector> transportConnectors = getTransportConnectors();
                for (Iterator<TransportConnector> iter = transportConnectors.iterator(); iter.hasNext(); ) {
                    try {
                        TransportConnector tc = iter.next();
                        if (location.equals(tc.getConnectUri())) {
                            return false;
                        }
                    } catch (Throwable e) {
                    }
                }
                return true;
            }
        });
        networkConnectors.add(connector);
        return connector;
    }

    public void setTempDataStore(PListStore tempDataStore) {
    }

    public void setJobSchedulerStore(JobSchedulerStore jobSchedulerStore) {
    }

    public ObjectName getBrokerObjectName() throws MalformedObjectNameException {
        return null;
    }

    public TransportConnector addConnector(URI bindAddress) throws Exception {
        Integer port = bindAddress.getPort();
        String host = bindAddress.getHost();
        FakeTransportConnector connector = null;
        host = (host == null || host.length() == 0) ? "localhost" : host;
        if ("0.0.0.0".equals(host)) {
            host = "localhost";
        }
        if (port == 0) {
            // In actual impl in amq5, after connector has been added the socket
            // is bound already. This means in case of 0 port uri, the random
            // port is available after this call. With artemis wrapper however
            // the real binding happens during broker start. To work around this
            // we use manually calculated port for that.
            port = getPseudoRandomPort();
        }
        bindAddress = new URI(bindAddress.getScheme(), bindAddress.getUserInfo(), host, port, bindAddress.getPath(), bindAddress.getQuery(), bindAddress.getFragment());
        connector = new FakeTransportConnector(bindAddress);
        this.transportConnectors.add(connector);
        if (sslContext instanceof SpringSslContext) {
            this.extraConnectors.add(new ConnectorInfo(bindAddress, (SpringSslContext) sslContext));
        } else {
            this.extraConnectors.add(new ConnectorInfo(bindAddress));
        }
        return connector;
    }

    private static int getPseudoRandomPort() {
        int currentRandomPort = RANDOM_PORT_BASE.getAndIncrement();
        int maxTry = 20;
        while (!checkPort(currentRandomPort)) {
            currentRandomPort = RANDOM_PORT_BASE.getAndIncrement();
            System.out.println("for port: " + currentRandomPort);
            maxTry--;
            if (maxTry == 0) {
                LOG.error("Too many port used");
                break;
            }
            try {
                TimeUnit.SECONDS.sleep(5);
            } catch (InterruptedException e) {
            }
        }
        return currentRandomPort;
    }

    public static boolean checkPort(final int port) {
        ServerSocket ssocket = null;
        try {
            ssocket = new ServerSocket(port);
        } catch (Exception e) {
            LOG.info("port " + port + " is being used.");
            return false;
        } finally {
            if (ssocket != null) {
                try {
                    ssocket.close();
                } catch (IOException e) {
                }
            }
        }
        return true;
    }

    public void setCacheTempDestinations(boolean cacheTempDestinations) {
    }

    public void setOfflineDurableSubscriberTimeout(long offlineDurableSubscriberTimeout) {
    }

    public void setOfflineDurableSubscriberTaskSchedule(long offlineDurableSubscriberTaskSchedule) {
    }

    public boolean isStopped() {
        return broker != null ? broker.isStopped() : true;
    }

    public void setBrokerId(String brokerId) {
    }

    public BrokerPlugin[] getPlugins() {
        return null;
    }

    public void stopAllConnectors(ServiceStopper stopper) {
    }

    public void setMessageAuthorizationPolicy(MessageAuthorizationPolicy messageAuthorizationPolicy) {
    }

    public void setNetworkConnectorStartAsync(boolean networkConnectorStartAsync) {
    }

    public boolean isRestartAllowed() {
        return true;
    }

    public void setTaskRunnerFactory(TaskRunnerFactory taskRunnerFactory) {
    }

    public void start(boolean force) throws Exception {
        this.start();
    }

    public void setMonitorConnectionSplits(boolean monitorConnectionSplits) {
    }

    public void setUseMirroredQueues(boolean useMirroredQueues) {
    }

    public File getTmpDataDirectory() {
        return null;
    }

    public boolean isUseShutdownHook() {
        return true;
    }

    public boolean isDeleteAllMessagesOnStartup() {
        return false;
    }

    public void setUseVirtualTopics(boolean useVirtualTopics) {
    }

    public boolean isUseLoggingForShutdownErrors() {
        return true;
    }

    public TransportConnector addConnector(TransportServer transport) throws Exception {
        return null;
    }

    public synchronized JobSchedulerStore getJobSchedulerStore() {
        return null;
    }

    public boolean removeConnector(TransportConnector connector) throws Exception {
        return true;
    }

    public ConnectionContext getAdminConnectionContext() throws Exception {
        return null;
    }

    public void setUseAuthenticatedPrincipalForJMSXUserID(boolean useAuthenticatedPrincipalForJMSXUserID) {
    }

    public void setSchedulePeriodForDestinationPurge(int schedulePeriodForDestinationPurge) {
    }

    public void setMbeanInvocationTimeout(long mbeanInvocationTimeout) {
    }

    public void setNetworkConnectors(List<?> networkConnectors) throws Exception {
    }

    public void removeDestination(ActiveMQDestination destination) throws Exception {
    }

    public void setMaxPurgedDestinationsPerSweep(int maxPurgedDestinationsPerSweep) {
    }

    public void setBrokerObjectName(ObjectName brokerObjectName) {
    }

    public Map<String, String> getTransportConnectorURIsAsMap() {
        return null;
    }

    public void setSslContext(SslContext sslContext) {
        this.sslContext = sslContext;
    }

    public void setPersistenceFactory(PersistenceAdapterFactory persistenceFactory) {
    }

    protected TransportConnector createTransportConnector(URI brokerURI) throws Exception {
        return null;
    }

    public String getDefaultUri() {
        return "tcp://localhost:61616";
    }

    public static boolean checkStopped() {
        boolean runningBrokers = false;
        for (Map.Entry<Broker, Exception> brokerExceptionEntry : map.entrySet()) {
            Broker b = brokerExceptionEntry.getKey();
            if (!b.isStopped()) {
                try {
                    b.stop();
                } catch (Exception e) {
                    e.printStackTrace();
                }
                brokerExceptionEntry.getValue().printStackTrace();
                runningBrokers = true;
            }
        }
        map.clear();
        return runningBrokers;
    }

    public URI getConnectURI() {
        URI uri = null;
        try {
            if (this.extraConnectors.size() > 0) {
                ConnectorInfo info = extraConnectors.iterator().next();
                Integer port = info.uri.getPort();
                String schema = info.ssl ? "ssl" : "tcp";
                uri = new URI(schema + "://localhost:" + port);
            } else {
                uri = new URI(this.getDefaultUri());
            }
        } catch (URISyntaxException e) {
        // ignore
        }
        return uri;
    }

    public static clreplaced ConnectorInfo {

        public static final String defaultKeyStore = "server.keystore";

        public static final String defaultKeyStorePreplacedword = "preplacedword";

        public static final String defaultKeyStoreType = "jks";

        public static final String defaultTrustStore = "client.keystore";

        public static final String defaultTrustStorePreplacedword = "preplacedword";

        public static final String defaultTrustStoreType = "jks";

        public URI uri;

        public boolean ssl;

        public boolean clientAuth;

        public ConnectorInfo(URI bindAddress) throws URISyntaxException {
            this(bindAddress, null);
        }

        // bindAddress must be Artemis compliant, except
        // scheme
        public ConnectorInfo(URI bindAddress, SpringSslContext context) throws URISyntaxException {
            Integer port = bindAddress.getPort();
            String host = bindAddress.getHost();
            this.ssl = "ssl".equals(bindAddress.getScheme());
            host = (host == null || host.length() == 0) ? "localhost" : host;
            if ("0.0.0.0".equals(host)) {
                host = "localhost";
            }
            if (port == 0) {
                port = getPseudoRandomPort();
            }
            String query = bindAddress.getQuery();
            if (!ssl || query != null && query.contains(TransportConstants.SSL_ENABLED_PROP_NAME)) {
                // it means the uri is already configured ssl
                uri = new URI("tcp", bindAddress.getUserInfo(), host, port, bindAddress.getPath(), bindAddress.getQuery(), bindAddress.getFragment());
            } else {
                String baseUri = "tcp://" + host + ":" + port + "?" + TransportConstants.SSL_ENABLED_PROP_NAME + "=true&" + TransportConstants.KEYSTORE_PATH_PROP_NAME + "=" + (context == null ? defaultKeyStore : context.getKeyStore()) + "&" + TransportConstants.KEYSTORE_PreplacedWORD_PROP_NAME + "=" + (context == null ? defaultKeyStorePreplacedword : context.getKeyStorePreplacedword()) + "&" + TransportConstants.KEYSTORE_PROVIDER_PROP_NAME + "=" + (context == null ? defaultKeyStoreType : context.getKeyStoreType());
                if (clientAuth) {
                    baseUri = baseUri + "&" + TransportConstants.NEED_CLIENT_AUTH_PROP_NAME + "=true" + "&" + TransportConstants.TRUSTSTORE_PATH_PROP_NAME + "=" + (context == null ? defaultTrustStore : context.getTrustStore()) + "&" + TransportConstants.TRUSTSTORE_PreplacedWORD_PROP_NAME + "=" + (context == null ? defaultTrustStorePreplacedword : context.getTrustStorePreplacedword()) + "&" + TransportConstants.TRUSTSTORE_PROVIDER_PROP_NAME + "=" + (context == null ? defaultTrustStoreType : context.getTrustStoreType());
                }
                uri = new URI(baseUri);
            }
            System.out.println("server uri:::::::::::: " + uri.toString());
        }

        @Override
        public int hashCode() {
            return uri.getPort();
        }

        @Override
        public boolean equals(Object obj) {
            if (obj instanceof ConnectorInfo) {
                return uri.getPort() == ((ConnectorInfo) obj).uri.getPort();
            }
            return false;
        }
    }
}

15 View Complete Implementation : ConnectionInfoTest.java
Copyright Apache License 2.0
Author : apache
@Override
protected void populateObject(Object object) throws Exception {
    super.populateObject(object);
    ConnectionInfo info = (ConnectionInfo) object;
    info.setConnectionId(createConnectionId("ConnectionId:1"));
    info.setClientId("ClientId:2");
    info.setPreplacedword("Preplacedword:3");
    info.setUserName("UserName:4");
    {
        BrokerId[] value = new BrokerId[2];
        for (int i = 0; i < 2; i++) {
            value[i] = createBrokerId("BrokerPath:5");
        }
        info.setBrokerPath(value);
    }
    info.setBrokerMasterConnector(true);
    info.setManageable(false);
}

15 View Complete Implementation : ConnectionInfoTest.java
Copyright Apache License 2.0
Author : apache
@Override
protected void populateObject(Object object) throws Exception {
    super.populateObject(object);
    ConnectionInfo info = (ConnectionInfo) object;
    info.setConnectionId(createConnectionId("ConnectionId:1"));
    info.setClientId("ClientId:2");
    info.setPreplacedword("Preplacedword:3");
    info.setUserName("UserName:4");
    {
        BrokerId[] value = new BrokerId[2];
        for (int i = 0; i < 2; i++) {
            value[i] = createBrokerId("BrokerPath:5");
        }
        info.setBrokerPath(value);
    }
    info.setBrokerMasterConnector(true);
    info.setManageable(false);
    info.setClientMaster(true);
}

12 View Complete Implementation : OpenWireProtocolManager.java
Copyright Apache License 2.0
Author : apache
public clreplaced OpenWireProtocolManager implements ProtocolManager<Interceptor>, ClusterTopologyListener {

    private static final List<String> websocketRegistryNames = Collections.EMPTY_LIST;

    private static final IdGenerator BROKER_ID_GENERATOR = new IdGenerator();

    private static final IdGenerator ID_GENERATOR = new IdGenerator();

    private final LongSequenceGenerator messageIdGenerator = new LongSequenceGenerator();

    private final ActiveMQServer server;

    private final OpenWireProtocolManagerFactory factory;

    private OpenWireFormatFactory wireFactory;

    private boolean prefixPacketSize = true;

    private BrokerId brokerId;

    protected final ProducerId advisoryProducerId = new ProducerId();

    private final CopyOnWriteArrayList<OpenWireConnection> connections = new CopyOnWriteArrayList<>();

    private final Map<String, AMQConnectionContext> clientIdSet = new HashMap<>();

    private String brokerName;

    private final Map<String, TopologyMember> topologyMap = new ConcurrentHashMap<>();

    private final LinkedList<TopologyMember> members = new LinkedList<>();

    private final ScheduledExecutorService scheduledPool;

    // bean properties
    // http://activemq.apache.org/failover-transport-reference.html
    private boolean rebalanceClusterClients = false;

    private boolean updateClusterClients = false;

    private boolean updateClusterClientsOnRemove = false;

    // http://activemq.apache.org/activemq-inactivitymonitor.html
    private long maxInactivityDuration = 30 * 1000L;

    private long maxInactivityDurationInitalDelay = 10 * 1000L;

    private boolean useKeepAlive = true;

    private boolean supportAdvisory = true;

    // prevents advisory addresses/queues to be registered
    // to management service
    private boolean suppressInternalManagementObjects = true;

    private final OpenWireFormat wireFormat;

    private final Map<SimpleString, RoutingType> prefixes = new HashMap<>();

    private final Map<DestinationFilter, Integer> vtConsumerDestinationMatchers = new HashMap<>();

    protected final LRUCache<ActiveMQDestination, ActiveMQDestination> vtDestMapCache = new LRUCache();

    public OpenWireProtocolManager(OpenWireProtocolManagerFactory factory, ActiveMQServer server) {
        this.factory = factory;
        this.server = server;
        this.wireFactory = new OpenWireFormatFactory();
        // preferred prop, should be done via config
        wireFactory.setCacheEnabled(false);
        advisoryProducerId.setConnectionId(ID_GENERATOR.generateId());
        scheduledPool = server.getScheduledPool();
        this.wireFormat = (OpenWireFormat) wireFactory.createWireFormat();
        final ClusterManager clusterManager = this.server.getClusterManager();
        ClusterConnection cc = clusterManager.getDefaultConnection(null);
        if (cc != null) {
            cc.addClusterTopologyListener(this);
        }
    }

    @Override
    public void nodeUP(TopologyMember member, boolean last) {
        if (topologyMap.put(member.getNodeId(), member) == null) {
            updateClientClusterInfo();
        }
    }

    @Override
    public void nodeDown(long eventUID, String nodeID) {
        if (topologyMap.remove(nodeID) != null) {
            updateClientClusterInfo();
        }
    }

    public void removeConnection(ConnectionInfo info, Throwable error) throws InvalidClientIDException {
        synchronized (clientIdSet) {
            String clientId = info.getClientId();
            if (clientId != null) {
                AMQConnectionContext context = this.clientIdSet.get(clientId);
                if (context != null && context.decRefCount() == 0) {
                    // connection is still there and need to close
                    context.getConnection().disconnect(error != null);
                    this.connections.remove(context.getConnection());
                    this.clientIdSet.remove(clientId);
                }
            } else {
                throw new InvalidClientIDException("No clientID specified for connection disconnect request");
            }
        }
    }

    public ScheduledExecutorService getScheduledPool() {
        return scheduledPool;
    }

    public ActiveMQServer getServer() {
        return server;
    }

    private void updateClientClusterInfo() {
        synchronized (members) {
            members.clear();
            members.addAll(topologyMap.values());
        }
        for (OpenWireConnection c : this.connections) {
            ConnectionControl control = newConnectionControl();
            try {
                c.updateClient(control);
            } catch (Exception e) {
                ActiveMQServerLogger.LOGGER.warn(e.getMessage(), e);
                c.sendException(e);
            }
        }
    }

    @Override
    public boolean acceptsNoHandshake() {
        return false;
    }

    @Override
    public ProtocolManagerFactory<Interceptor> getFactory() {
        return factory;
    }

    @Override
    public void updateInterceptors(List<BaseInterceptor> incomingInterceptors, List<BaseInterceptor> outgoingInterceptors) {
    // NO-OP
    }

    @Override
    public ConnectionEntry createConnectionEntry(Acceptor acceptorUsed, Connection connection) {
        OpenWireFormat wf = (OpenWireFormat) wireFactory.createWireFormat();
        OpenWireConnection owConn = new OpenWireConnection(connection, server, this, wf, server.getExecutorFactory().getExecutor());
        owConn.sendHandshake();
        // first we setup ttl to -1
        // then when negotiation, we handle real ttl and delay
        ConnectionEntry entry = new ConnectionEntry(owConn, null, System.currentTimeMillis(), -1);
        owConn.setConnectionEntry(entry);
        return entry;
    }

    @Override
    public void removeHandler(String name) {
    }

    @Override
    public void handleBuffer(RemotingConnection connection, ActiveMQBuffer buffer) {
    }

    @Override
    public void addChannelHandlers(ChannelPipeline pipeline) {
        // each read will have a full packet with this
        pipeline.addLast("packet-decipher", new LengthFieldBasedFrameDecoder(Integer.MAX_VALUE, 0, DataConstants.SIZE_INT));
    }

    @Override
    public boolean isProtocol(byte[] array) {
        if (array.length < 8) {
            throw new IllegalArgumentException("Protocol header length changed " + array.length);
        }
        int start = this.prefixPacketSize ? 4 : 0;
        int j = 0;
        // type
        if (array[start] != WireFormatInfo.DATA_STRUCTURE_TYPE) {
            return false;
        }
        start++;
        WireFormatInfo info = new WireFormatInfo();
        final byte[] magic = info.getMagic();
        int remainingLen = array.length - start;
        int useLen = remainingLen > magic.length ? magic.length : remainingLen;
        useLen += start;
        // magic
        for (int i = start; i < useLen; i++) {
            if (array[i] != magic[j]) {
                return false;
            }
            j++;
        }
        return true;
    }

    @Override
    public void handshake(NettyServerConnection connection, ActiveMQBuffer buffer) {
    }

    @Override
    public List<String> websocketSubprotocolIdentifiers() {
        return websocketRegistryNames;
    }

    public void addConnection(OpenWireConnection connection, ConnectionInfo info) throws Exception {
        String username = info.getUserName();
        String preplacedword = info.getPreplacedword();
        try {
            validateUser(username, preplacedword, connection);
        } catch (ActiveMQSecurityException e) {
            // We need to send an exception used by the openwire
            SecurityException ex = new SecurityException("User name [" + username + "] or preplacedword is invalid.");
            ex.initCause(e);
            throw ex;
        }
        String clientId = info.getClientId();
        if (clientId == null) {
            throw new InvalidClientIDException("No clientID specified for connection request");
        }
        synchronized (clientIdSet) {
            AMQConnectionContext context;
            context = clientIdSet.get(clientId);
            if (context != null) {
                if (info.isFailoverReconnect()) {
                    OpenWireConnection oldConnection = context.getConnection();
                    oldConnection.disconnect(true);
                    connections.remove(oldConnection);
                    connection.reconnect(context, info);
                } else {
                    throw new InvalidClientIDException("Broker: " + getBrokerName() + " - Client: " + clientId + " already connected from " + context.getConnection().getRemoteAddress());
                }
            } else {
                // new connection
                context = connection.initContext(info);
                clientIdSet.put(clientId, context);
            }
            connections.add(connection);
            ActiveMQTopic topic = AdvisorySupport.getConnectionAdvisoryTopic();
            // do not distribute preplacedwords in advisory messages. usernames okay
            ConnectionInfo copy = info.copy();
            copy.setPreplacedword("");
            fireAdvisory(context, topic, copy);
            // init the conn
            context.getConnection().addSessions(context.getConnectionState().getSessionIds());
        }
    }

    public void fireAdvisory(AMQConnectionContext context, ActiveMQTopic topic, Command copy) throws Exception {
        this.fireAdvisory(context, topic, copy, null, null);
    }

    public BrokerId getBrokerId() {
        // TODO: Use the Storage ID here...
        if (brokerId == null) {
            brokerId = new BrokerId(BROKER_ID_GENERATOR.generateId());
        }
        return brokerId;
    }

    /*
    * See AdvisoryBroker.fireAdvisory()
    */
    public void fireAdvisory(AMQConnectionContext context, ActiveMQTopic topic, Command command, ConsumerId targetConsumerId, String originalConnectionId) throws Exception {
        if (!this.isSupportAdvisory()) {
            return;
        }
        ActiveMQMessage advisoryMessage = new ActiveMQMessage();
        if (originalConnectionId == null) {
            originalConnectionId = context.getConnectionId().getValue();
        }
        advisoryMessage.setStringProperty(MessageUtil.CONNECTION_ID_PROPERTY_NAME.toString(), originalConnectionId);
        advisoryMessage.setStringProperty(AdvisorySupport.MSG_PROPERTY_ORIGIN_BROKER_NAME, getBrokerName());
        String id = getBrokerId() != null ? getBrokerId().getValue() : "NOT_SET";
        advisoryMessage.setStringProperty(AdvisorySupport.MSG_PROPERTY_ORIGIN_BROKER_ID, id);
        String url = context.getConnection().getLocalAddress();
        advisoryMessage.setStringProperty(AdvisorySupport.MSG_PROPERTY_ORIGIN_BROKER_URL, url);
        // set the data structure
        advisoryMessage.setDataStructure(command);
        advisoryMessage.setPersistent(false);
        advisoryMessage.setType(AdvisorySupport.ADIVSORY_MESSAGE_TYPE);
        advisoryMessage.setMessageId(new MessageId(advisoryProducerId, messageIdGenerator.getNextSequenceId()));
        advisoryMessage.setTargetConsumerId(targetConsumerId);
        advisoryMessage.setDestination(topic);
        advisoryMessage.setResponseRequired(false);
        advisoryMessage.setProducerId(advisoryProducerId);
        boolean originalFlowControl = context.isProducerFlowControl();
        final AMQProducerBrokerExchange producerExchange = new AMQProducerBrokerExchange();
        producerExchange.setConnectionContext(context);
        producerExchange.setProducerState(new ProducerState(new ProducerInfo()));
        try {
            context.setProducerFlowControl(false);
            AMQSession sess = context.getConnection().getAdvisorySession();
            if (sess != null) {
                sess.send(producerExchange.getProducerState().getInfo(), advisoryMessage, false);
            }
        } finally {
            context.setProducerFlowControl(originalFlowControl);
        }
    }

    public String getBrokerName() {
        if (brokerName == null) {
            try {
                brokerName = InetAddressUtil.getLocalHostName().toLowerCase(Locale.ENGLISH);
            } catch (Exception e) {
                brokerName = server.getNodeID().toString();
            }
        }
        return brokerName;
    }

    protected ConnectionControl newConnectionControl() {
        ConnectionControl control = new ConnectionControl();
        String uri = generateMembersURI(rebalanceClusterClients);
        control.setConnectedBrokers(uri);
        control.setRebalanceConnection(rebalanceClusterClients);
        return control;
    }

    private String generateMembersURI(boolean flip) {
        String uri;
        StringBuffer connectedBrokers = new StringBuffer();
        String separator = "";
        synchronized (members) {
            if (members.size() > 0) {
                for (TopologyMember member : members) {
                    connectedBrokers.append(separator).append(member.toURI());
                    separator = ",";
                }
                // The flip exists to guarantee even distribution of URIs when sent to the client
                // in case of failures you won't get all the connections failing to a single server.
                if (flip && members.size() > 1) {
                    members.addLast(members.removeFirst());
                }
            }
        }
        uri = connectedBrokers.toString();
        return uri;
    }

    public boolean isFaultTolerantConfiguration() {
        return false;
    }

    public void postProcessDispatch(MessageDispatch md) {
    // TODO Auto-generated method stub
    }

    public boolean isStopped() {
        // TODO Auto-generated method stub
        return false;
    }

    public void preProcessDispatch(MessageDispatch messageDispatch) {
    // TODO Auto-generated method stub
    }

    public boolean isStopping() {
        return false;
    }

    public void validateUser(String login, String preplacedcode, OpenWireConnection connection) throws Exception {
        server.getSecurityStore().authenticate(login, preplacedcode, connection);
    }

    public void sendBrokerInfo(OpenWireConnection connection) throws Exception {
        BrokerInfo brokerInfo = new BrokerInfo();
        brokerInfo.setBrokerName(getBrokerName());
        brokerInfo.setBrokerId(new BrokerId("" + server.getNodeID()));
        brokerInfo.setPeerBrokerInfos(null);
        brokerInfo.setFaultTolerantConfiguration(false);
        brokerInfo.setBrokerURL(connection.getLocalAddress());
        // cluster support yet to support
        brokerInfo.setPeerBrokerInfos(null);
        connection.dispatch(brokerInfo);
    }

    public void configureInactivityParams(OpenWireConnection connection, WireFormatInfo command) throws IOException {
        long inactivityDurationToUse = command.getMaxInactivityDuration() > this.maxInactivityDuration ? this.maxInactivityDuration : command.getMaxInactivityDuration();
        long inactivityDurationInitialDelayToUse = command.getMaxInactivityDurationInitalDelay() > this.maxInactivityDurationInitalDelay ? this.maxInactivityDurationInitalDelay : command.getMaxInactivityDurationInitalDelay();
        boolean useKeepAliveToUse = this.maxInactivityDuration == 0L ? false : this.useKeepAlive;
        connection.setUpTtl(inactivityDurationToUse, inactivityDurationInitialDelayToUse, useKeepAliveToUse);
    }

    /**
     * URI property
     */
    @SuppressWarnings("unused")
    public void setRebalanceClusterClients(boolean rebalance) {
        this.rebalanceClusterClients = rebalance;
    }

    /**
     * URI property
     */
    @SuppressWarnings("unused")
    public boolean isRebalanceClusterClients() {
        return this.rebalanceClusterClients;
    }

    /**
     * URI property
     */
    @SuppressWarnings("unused")
    public void setUpdateClusterClients(boolean updateClusterClients) {
        this.updateClusterClients = updateClusterClients;
    }

    public boolean isUpdateClusterClients() {
        return this.updateClusterClients;
    }

    /**
     * URI property
     */
    @SuppressWarnings("unused")
    public void setUpdateClusterClientsOnRemove(boolean updateClusterClientsOnRemove) {
        this.updateClusterClientsOnRemove = updateClusterClientsOnRemove;
    }

    /**
     * URI property
     */
    @SuppressWarnings("unused")
    public boolean isUpdateClusterClientsOnRemove() {
        return this.updateClusterClientsOnRemove;
    }

    public void setBrokerName(String name) {
        this.brokerName = name;
    }

    public boolean isUseKeepAlive() {
        return useKeepAlive;
    }

    @SuppressWarnings("unused")
    public void setUseKeepAlive(boolean useKeepAlive) {
        this.useKeepAlive = useKeepAlive;
    }

    public long getMaxInactivityDuration() {
        return maxInactivityDuration;
    }

    public void setMaxInactivityDuration(long maxInactivityDuration) {
        this.maxInactivityDuration = maxInactivityDuration;
    }

    @SuppressWarnings("unused")
    public long getMaxInactivityDurationInitalDelay() {
        return maxInactivityDurationInitalDelay;
    }

    @SuppressWarnings("unused")
    public void setMaxInactivityDurationInitalDelay(long maxInactivityDurationInitalDelay) {
        this.maxInactivityDurationInitalDelay = maxInactivityDurationInitalDelay;
    }

    @Override
    public void setAnycastPrefix(String anycastPrefix) {
        for (String prefix : anycastPrefix.split(",")) {
            prefixes.put(SimpleString.toSimpleString(prefix), RoutingType.ANYCAST);
        }
    }

    @Override
    public void setMulticastPrefix(String multicastPrefix) {
        for (String prefix : multicastPrefix.split(",")) {
            prefixes.put(SimpleString.toSimpleString(prefix), RoutingType.MULTICAST);
        }
    }

    @Override
    public Map<SimpleString, RoutingType> getPrefixes() {
        return prefixes;
    }

    public List<DestinationInfo> getTemporaryDestinations() {
        List<DestinationInfo> total = new ArrayList<>();
        for (OpenWireConnection connection : connections) {
            total.addAll(connection.getTemporaryDestinations());
        }
        return total;
    }

    public OpenWireFormat wireFormat() {
        return wireFormat;
    }

    public boolean isSupportAdvisory() {
        return supportAdvisory;
    }

    public void setSupportAdvisory(boolean supportAdvisory) {
        this.supportAdvisory = supportAdvisory;
    }

    public boolean isSuppressInternalManagementObjects() {
        return suppressInternalManagementObjects;
    }

    public void setSuppressInternalManagementObjects(boolean suppressInternalManagementObjects) {
        this.suppressInternalManagementObjects = suppressInternalManagementObjects;
    }

    public void setVirtualTopicConsumerWildcards(String virtualTopicConsumerWildcards) {
        for (String filter : virtualTopicConsumerWildcards.split(",")) {
            String[] wildcardLimitPair = filter.split(";");
            vtConsumerDestinationMatchers.put(DestinationFilter.parseFilter(new ActiveMQQueue(wildcardLimitPair[0])), Integer.valueOf(wildcardLimitPair[1]));
        }
    }

    public void setVirtualTopicConsumerLruCacheMax(int max) {
        vtDestMapCache.setMaxCacheSize(max);
    }

    public ActiveMQDestination virtualTopicConsumerToFQQN(final ActiveMQDestination destination) {
        if (vtConsumerDestinationMatchers.isEmpty()) {
            return destination;
        }
        ActiveMQDestination mappedDestination = null;
        synchronized (vtDestMapCache) {
            mappedDestination = vtDestMapCache.get(destination);
        }
        if (mappedDestination != null) {
            return mappedDestination;
        }
        for (Map.Entry<DestinationFilter, Integer> candidate : vtConsumerDestinationMatchers.entrySet()) {
            if (candidate.getKey().matches(destination)) {
                // convert to matching FQQN
                String[] paths = DestinationPath.getDestinationPaths(destination);
                StringBuilder fqqn = new StringBuilder();
                int filterPathTerminus = candidate.getValue();
                // address - ie: topic
                for (int i = filterPathTerminus; i < paths.length; i++) {
                    if (i > filterPathTerminus) {
                        fqqn.append(ActiveMQDestination.PATH_SEPERATOR);
                    }
                    fqqn.append(paths[i]);
                }
                fqqn.append(CompositeAddress.SEPARATOR);
                // consumer queue - the full vt queue
                for (int i = 0; i < paths.length; i++) {
                    if (i > 0) {
                        fqqn.append(ActiveMQDestination.PATH_SEPERATOR);
                    }
                    fqqn.append(paths[i]);
                }
                mappedDestination = new ActiveMQQueue(fqqn.toString());
                break;
            }
        }
        if (mappedDestination == null) {
            // cache the idenreplacedy mapping
            mappedDestination = destination;
        }
        synchronized (vtDestMapCache) {
            ActiveMQDestination existing = vtDestMapCache.put(destination, mappedDestination);
            if (existing != null) {
                // some one beat us to the put, revert
                vtDestMapCache.put(destination, existing);
                mappedDestination = existing;
            }
        }
        return mappedDestination;
    }

    public List<OpenWireConnection> getConnections() {
        return connections;
    }
}

11 View Complete Implementation : ConnectionInfoTest.java
Copyright Apache License 2.0
Author : apache
@Override
protected void populateObject(Object object) throws Exception {
    super.populateObject(object);
    ConnectionInfo info = (ConnectionInfo) object;
    info.setConnectionId(createConnectionId("ConnectionId:1"));
    info.setClientId("ClientId:2");
    info.setPreplacedword("Preplacedword:3");
    info.setUserName("UserName:4");
    {
        BrokerId[] value = new BrokerId[2];
        for (int i = 0; i < 2; i++) {
            value[i] = createBrokerId("BrokerPath:5");
        }
        info.setBrokerPath(value);
    }
    info.setBrokerMasterConnector(true);
    info.setManageable(false);
    info.setClientMaster(true);
    info.setFaultTolerant(false);
    info.setFailoverReconnect(true);
}

10 View Complete Implementation : ConnectionInfoTest.java
Copyright Apache License 2.0
Author : apache
@Override
protected void populateObject(Object object) throws Exception {
    super.populateObject(object);
    ConnectionInfo info = (ConnectionInfo) object;
    info.setConnectionId(createConnectionId("ConnectionId:1"));
    info.setClientId("ClientId:2");
    info.setPreplacedword("Preplacedword:3");
    info.setUserName("UserName:4");
    {
        BrokerId[] value = new BrokerId[2];
        for (int i = 0; i < 2; i++) {
            value[i] = createBrokerId("BrokerPath:5");
        }
        info.setBrokerPath(value);
    }
    info.setBrokerMasterConnector(true);
    info.setManageable(false);
    info.setClientMaster(true);
    info.setFaultTolerant(false);
    info.setFailoverReconnect(true);
    info.setClientIp("ClientIp:6");
}

8 View Complete Implementation : ConsumerInfoTest.java
Copyright Apache License 2.0
Author : apache
@Override
protected void populateObject(Object object) throws Exception {
    super.populateObject(object);
    ConsumerInfo info = (ConsumerInfo) object;
    info.setConsumerId(createConsumerId("ConsumerId:1"));
    info.setBrowser(true);
    info.setDestination(createActiveMQDestination("Destination:2"));
    info.setPrefetchSize(1);
    info.setMaximumPendingMessageLimit(2);
    info.setDispatchAsync(false);
    info.setSelector("Selector:3");
    info.setSubscriptionName("SubcriptionName:4");
    info.setNoLocal(true);
    info.setExclusive(false);
    info.setRetroactive(true);
    info.setPriority((byte) 1);
    {
        BrokerId[] value = new BrokerId[2];
        for (int i = 0; i < 2; i++) {
            value[i] = createBrokerId("BrokerPath:5");
        }
        info.setBrokerPath(value);
    }
    info.setAdditionalPredicate(createBooleanExpression("AdditionalPredicate:6"));
    info.setNetworkSubscription(false);
    info.setOptimizedAcknowledge(true);
    info.setNoRangeAcks(false);
}

8 View Complete Implementation : ConsumerInfoTest.java
Copyright Apache License 2.0
Author : apache
@Override
protected void populateObject(Object object) throws Exception {
    super.populateObject(object);
    ConsumerInfo info = (ConsumerInfo) object;
    info.setConsumerId(createConsumerId("ConsumerId:1"));
    info.setBrowser(true);
    info.setDestination(createActiveMQDestination("Destination:2"));
    info.setPrefetchSize(1);
    info.setMaximumPendingMessageLimit(2);
    info.setDispatchAsync(false);
    info.setSelector("Selector:3");
    info.setSubscriptionName("SubscriptionName:4");
    info.setNoLocal(true);
    info.setExclusive(false);
    info.setRetroactive(true);
    info.setPriority((byte) 1);
    {
        BrokerId[] value = new BrokerId[2];
        for (int i = 0; i < 2; i++) {
            value[i] = createBrokerId("BrokerPath:5");
        }
        info.setBrokerPath(value);
    }
    info.setAdditionalPredicate(createBooleanExpression("AdditionalPredicate:6"));
    info.setNetworkSubscription(false);
    info.setOptimizedAcknowledge(true);
    info.setNoRangeAcks(false);
}

7 View Complete Implementation : ConsumerInfoTest.java
Copyright Apache License 2.0
Author : apache
@Override
protected void populateObject(Object object) throws Exception {
    super.populateObject(object);
    ConsumerInfo info = (ConsumerInfo) object;
    info.setConsumerId(createConsumerId("ConsumerId:1"));
    info.setBrowser(true);
    info.setDestination(createActiveMQDestination("Destination:2"));
    info.setPrefetchSize(1);
    info.setMaximumPendingMessageLimit(2);
    info.setDispatchAsync(false);
    info.setSelector("Selector:3");
    info.setSubscriptionName("SubscriptionName:4");
    info.setNoLocal(true);
    info.setExclusive(false);
    info.setRetroactive(true);
    info.setPriority((byte) 1);
    {
        BrokerId[] value = new BrokerId[2];
        for (int i = 0; i < 2; i++) {
            value[i] = createBrokerId("BrokerPath:5");
        }
        info.setBrokerPath(value);
    }
    info.setAdditionalPredicate(createBooleanExpression("AdditionalPredicate:6"));
    info.setNetworkSubscription(false);
    info.setOptimizedAcknowledge(true);
    info.setNoRangeAcks(false);
    {
        ConsumerId[] value = new ConsumerId[2];
        for (int i = 0; i < 2; i++) {
            value[i] = createConsumerId("NetworkConsumerPath:7");
        }
        info.setNetworkConsumerPath(value);
    }
}

0 View Complete Implementation : MessageTestSupport.java
Copyright Apache License 2.0
Author : apache
@Override
protected void populateObject(Object object) throws Exception {
    super.populateObject(object);
    Message info = (Message) object;
    info.setProducerId(createProducerId("ProducerId:1"));
    info.setDestination(createActiveMQDestination("Destination:2"));
    info.setTransactionId(createTransactionId("TransactionId:3"));
    info.setOriginalDestination(createActiveMQDestination("OriginalDestination:4"));
    info.setMessageId(createMessageId("MessageId:5"));
    info.setOriginalTransactionId(createTransactionId("OriginalTransactionId:6"));
    info.setGroupID("GroupID:7");
    info.setGroupSequence(1);
    info.setCorrelationId("CorrelationId:8");
    info.setPersistent(true);
    info.setExpiration(1);
    info.setPriority((byte) 1);
    info.setReplyTo(createActiveMQDestination("ReplyTo:9"));
    info.setTimestamp(2);
    info.setType("Type:10");
    {
        byte[] data = "Content:11".getBytes();
        info.setContent(new org.apache.activemq.util.ByteSequence(data, 0, data.length));
    }
    {
        byte[] data = "MarshalledProperties:12".getBytes();
        info.setMarshalledProperties(new org.apache.activemq.util.ByteSequence(data, 0, data.length));
    }
    info.setDataStructure(createDataStructure("DataStructure:13"));
    info.setTargetConsumerId(createConsumerId("TargetConsumerId:14"));
    info.setCompressed(false);
    info.setRedeliveryCounter(2);
    {
        BrokerId[] value = new BrokerId[2];
        for (int i = 0; i < 2; i++) {
            value[i] = createBrokerId("BrokerPath:15");
        }
        info.setBrokerPath(value);
    }
    info.setArrival(3);
    info.setUserID("UserID:16");
    info.setRecievedByDFBridge(true);
    info.setDroppable(false);
    {
        BrokerId[] value = new BrokerId[2];
        for (int i = 0; i < 2; i++) {
            value[i] = createBrokerId("Cluster:17");
        }
        info.setCluster(value);
    }
    info.setBrokerInTime(4);
    info.setBrokerOutTime(5);
}

0 View Complete Implementation : MessageTestSupport.java
Copyright Apache License 2.0
Author : apache
@Override
protected void populateObject(Object object) throws Exception {
    super.populateObject(object);
    Message info = (Message) object;
    info.setProducerId(createProducerId("ProducerId:1"));
    info.setDestination(createActiveMQDestination("Destination:2"));
    info.setTransactionId(createTransactionId("TransactionId:3"));
    info.setOriginalDestination(createActiveMQDestination("OriginalDestination:4"));
    info.setMessageId(createMessageId("MessageId:5"));
    info.setOriginalTransactionId(createTransactionId("OriginalTransactionId:6"));
    info.setGroupID("GroupID:7");
    info.setGroupSequence(1);
    info.setCorrelationId("CorrelationId:8");
    info.setPersistent(true);
    info.setExpiration(1);
    info.setPriority((byte) 1);
    info.setReplyTo(createActiveMQDestination("ReplyTo:9"));
    info.setTimestamp(2);
    info.setType("Type:10");
    {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        DataOutputStream dataOut = new DataOutputStream(baos);
        MarshallingSupport.writeUTF8(dataOut, "Content:11");
        dataOut.close();
        info.setContent(baos.toByteSequence());
    }
    {
        Map<String, Object> map = new HashMap<>();
        map.put("MarshalledProperties", 12);
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        DataOutputStream os = new DataOutputStream(baos);
        MarshallingSupport.marshalPrimitiveMap(map, os);
        os.close();
        info.setMarshalledProperties(baos.toByteSequence());
    }
    info.setDataStructure(createDataStructure("DataStructure:13"));
    info.setTargetConsumerId(createConsumerId("TargetConsumerId:14"));
    info.setCompressed(false);
    info.setRedeliveryCounter(2);
    {
        BrokerId[] value = new BrokerId[2];
        for (int i = 0; i < 2; i++) {
            value[i] = createBrokerId("BrokerPath:15");
        }
        info.setBrokerPath(value);
    }
    info.setArrival(3);
    info.setUserID("UserID:16");
    info.setRecievedByDFBridge(true);
}

0 View Complete Implementation : MessageTestSupport.java
Copyright Apache License 2.0
Author : apache
@Override
protected void populateObject(Object object) throws Exception {
    super.populateObject(object);
    Message info = (Message) object;
    info.setProducerId(createProducerId("ProducerId:1"));
    info.setDestination(createActiveMQDestination("Destination:2"));
    info.setTransactionId(createTransactionId("TransactionId:3"));
    info.setOriginalDestination(createActiveMQDestination("OriginalDestination:4"));
    info.setMessageId(createMessageId("MessageId:5"));
    info.setOriginalTransactionId(createTransactionId("OriginalTransactionId:6"));
    info.setGroupID("GroupID:7");
    info.setGroupSequence(1);
    info.setCorrelationId("CorrelationId:8");
    info.setPersistent(true);
    info.setExpiration(1);
    info.setPriority((byte) 1);
    info.setReplyTo(createActiveMQDestination("ReplyTo:9"));
    info.setTimestamp(2);
    info.setType("Type:10");
    {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        DataOutputStream dataOut = new DataOutputStream(baos);
        MarshallingSupport.writeUTF8(dataOut, "Content:11");
        dataOut.close();
        info.setContent(baos.toByteSequence());
    }
    {
        Map<String, Object> map = new HashMap<>();
        map.put("MarshalledProperties", 12);
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        DataOutputStream os = new DataOutputStream(baos);
        MarshallingSupport.marshalPrimitiveMap(map, os);
        os.close();
        info.setMarshalledProperties(baos.toByteSequence());
    }
    info.setDataStructure(createDataStructure("DataStructure:13"));
    info.setTargetConsumerId(createConsumerId("TargetConsumerId:14"));
    info.setCompressed(false);
    info.setRedeliveryCounter(2);
    {
        BrokerId[] value = new BrokerId[2];
        for (int i = 0; i < 2; i++) {
            value[i] = createBrokerId("BrokerPath:15");
        }
        info.setBrokerPath(value);
    }
    info.setArrival(3);
    info.setUserID("UserID:16");
    info.setRecievedByDFBridge(true);
    info.setDroppable(false);
}

0 View Complete Implementation : OpenWireMessageConverter.java
Copyright Apache License 2.0
Author : apache
public static org.apache.activemq.artemis.api.core.Message inbound(final Message messageSend, final WireFormat marshaller, final CoreMessageObjectPools coreMessageObjectPools) throws Exception {
    final CoreMessage coreMessage = new CoreMessage(-1, messageSend.getSize(), coreMessageObjectPools);
    final String type = messageSend.getType();
    if (type != null) {
        coreMessage.putStringProperty(JMS_TYPE_PROPERTY, new SimpleString(type));
    }
    coreMessage.setDurable(messageSend.isPersistent());
    coreMessage.setExpiration(messageSend.getExpiration());
    coreMessage.setPriority(messageSend.getPriority());
    coreMessage.setTimestamp(messageSend.getTimestamp());
    final byte coreType = toCoreType(messageSend.getDataStructureType());
    coreMessage.setType(coreType);
    final ActiveMQBuffer body = coreMessage.getBodyBuffer();
    final ByteSequence contents = messageSend.getContent();
    if (contents == null && coreType == org.apache.activemq.artemis.api.core.Message.TEXT_TYPE) {
        body.writeNullableString(null);
    } else if (contents != null) {
        final boolean messageCompressed = messageSend.isCompressed();
        if (messageCompressed) {
            coreMessage.putBooleanProperty(AMQ_MSG_COMPRESSED, messageCompressed);
        }
        switch(coreType) {
            case org.apache.activemq.artemis.api.core.Message.TEXT_TYPE:
                writeTextType(contents, messageCompressed, body);
                break;
            case org.apache.activemq.artemis.api.core.Message.MAP_TYPE:
                writeMapType(contents, messageCompressed, body);
                break;
            case org.apache.activemq.artemis.api.core.Message.OBJECT_TYPE:
                writeObjectType(contents, messageCompressed, body);
                break;
            case org.apache.activemq.artemis.api.core.Message.STREAM_TYPE:
                writeStreamType(contents, messageCompressed, body);
                break;
            case org.apache.activemq.artemis.api.core.Message.BYTES_TYPE:
                writeBytesType(contents, messageCompressed, body);
                break;
            default:
                writeDefaultType(contents, messageCompressed, body);
                break;
        }
    }
    // amq specific
    coreMessage.putLongProperty(AMQ_MSG_ARRIVAL, messageSend.getArrival());
    coreMessage.putLongProperty(AMQ_MSG_BROKER_IN_TIME, messageSend.getBrokerInTime());
    final BrokerId[] brokers = messageSend.getBrokerPath();
    if (brokers != null) {
        putMsgBrokerPath(brokers, coreMessage);
    }
    final BrokerId[] cluster = messageSend.getCluster();
    if (cluster != null) {
        putMsgCluster(cluster, coreMessage);
    }
    coreMessage.putIntProperty(AMQ_MSG_COMMAND_ID, messageSend.getCommandId());
    final String corrId = messageSend.getCorrelationId();
    if (corrId != null) {
        coreMessage.putStringProperty(JMS_CORRELATION_ID_PROPERTY, new SimpleString(corrId));
    }
    final DataStructure ds = messageSend.getDataStructure();
    if (ds != null) {
        putMsgDataStructure(ds, marshaller, coreMessage);
    }
    final String groupId = messageSend.getGroupID();
    if (groupId != null) {
        coreMessage.setGroupID(groupId);
    }
    coreMessage.setGroupSequence(messageSend.getGroupSequence());
    final MessageId messageId = messageSend.getMessageId();
    final ByteSequence midBytes = marshaller.marshal(messageId);
    midBytes.compact();
    coreMessage.putBytesProperty(AMQ_MSG_MESSAGE_ID, midBytes.data);
    coreMessage.setUserID(UUIDGenerator.getInstance().generateUUID());
    final ProducerId producerId = messageSend.getProducerId();
    if (producerId != null) {
        final ByteSequence producerIdBytes = marshaller.marshal(producerId);
        producerIdBytes.compact();
        coreMessage.putBytesProperty(AMQ_MSG_PRODUCER_ID, producerIdBytes.data);
    }
    final ByteSequence propBytes = messageSend.getMarshalledProperties();
    if (propBytes != null) {
        putMsgMarshalledProperties(propBytes, messageSend, coreMessage);
    }
    final ActiveMQDestination replyTo = messageSend.getReplyTo();
    if (replyTo != null) {
        if (replyTo instanceof TemporaryQueue) {
            MessageUtil.setJMSReplyTo(coreMessage, org.apache.activemq.artemis.jms.client.ActiveMQDestination.TEMP_QUEUE_QUALIFED_PREFIX + (((TemporaryQueue) replyTo).getQueueName()));
        } else if (replyTo instanceof TemporaryTopic) {
            MessageUtil.setJMSReplyTo(coreMessage, org.apache.activemq.artemis.jms.client.ActiveMQDestination.TEMP_TOPIC_QUALIFED_PREFIX + (((TemporaryTopic) replyTo).getTopicName()));
        } else if (replyTo instanceof Queue) {
            MessageUtil.setJMSReplyTo(coreMessage, org.apache.activemq.artemis.jms.client.ActiveMQDestination.QUEUE_QUALIFIED_PREFIX + (((Queue) replyTo).getQueueName()));
        } else if (replyTo instanceof Topic) {
            MessageUtil.setJMSReplyTo(coreMessage, org.apache.activemq.artemis.jms.client.ActiveMQDestination.TOPIC_QUALIFIED_PREFIX + (((Topic) replyTo).getTopicName()));
        } else {
            // it should not happen
            MessageUtil.setJMSReplyTo(coreMessage, org.apache.activemq.artemis.jms.client.ActiveMQDestination.QUEUE_QUALIFIED_PREFIX + (((Queue) replyTo).getQueueName()));
        }
    }
    final String userId = messageSend.getUserID();
    if (userId != null) {
        coreMessage.putStringProperty(AMQ_MSG_USER_ID, new SimpleString(userId));
    }
    coreMessage.putBooleanProperty(AMQ_MSG_DROPPABLE, messageSend.isDroppable());
    final ActiveMQDestination origDest = messageSend.getOriginalDestination();
    if (origDest != null) {
        putMsgOriginalDestination(origDest, marshaller, coreMessage);
    }
    return coreMessage;
}