http://git-wip-us.apache.org/repos/asf/activemq-6/blob/177e6820/examples/soak/tx-restarts/src/org/hornetq/jms/example/Sender.java ---------------------------------------------------------------------- diff --git a/examples/soak/tx-restarts/src/org/hornetq/jms/example/Sender.java b/examples/soak/tx-restarts/src/org/hornetq/jms/example/Sender.java deleted file mode 100644 index dbdb5f2..0000000 --- a/examples/soak/tx-restarts/src/org/hornetq/jms/example/Sender.java +++ /dev/null @@ -1,128 +0,0 @@ -/* - * Copyright 2005-2014 Red Hat, Inc. - * Red Hat licenses this file to you under the Apache License, version - * 2.0 (the "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - * implied. See the License for the specific language governing - * permissions and limitations under the License. - */ -package org.hornetq.jms.example; - -import javax.jms.BytesMessage; -import javax.jms.DeliveryMode; -import javax.jms.MessageProducer; -import javax.jms.Queue; - - -/** - * A Sender - * - * @author <a href="mailto:[email protected]">Clebert Suconic</a> - * - * - */ -public class Sender extends ClientAbstract -{ - - // Constants ----------------------------------------------------- - - // Attributes ---------------------------------------------------- - - protected MessageProducer producer; - protected Queue queue; - - protected long msgs = TXRestartSoak.MIN_MESSAGES_ON_QUEUE; - protected int pendingMsgs = 0; - - protected final Receiver[] receivers; - - - // Static -------------------------------------------------------- - - // Constructors -------------------------------------------------- - - // Public -------------------------------------------------------- - - public Sender(final Receiver[] receivers) - { - this.receivers = receivers; - } - - @Override - protected void connectClients() throws Exception - { - queue = (Queue)ctx.lookup("/queue/inputQueue"); - producer = sess.createProducer(queue); - producer.setDeliveryMode(DeliveryMode.PERSISTENT); - } - - public void run() - { - super.run(); - while (running) - { - try - { - beginTX(); - for (int i = 0 ; i < 1000; i++) - { - BytesMessage msg = sess.createBytesMessage(); - msg.setLongProperty("count", pendingMsgs + msgs); - msg.writeBytes(new byte[10 * 1024]); - producer.send(msg); - pendingMsgs++; - } - endTX(); - } - catch (Exception e) - { - connect(); - } - } - } - - /* (non-Javadoc) - * @see org.hornetq.jms.example.ClientAbstract#onCommit() - */ - @Override - protected void onCommit() - { - this.msgs += pendingMsgs; - for (Receiver rec : receivers) - { - rec.messageProduced(pendingMsgs); - } - - pendingMsgs = 0; - System.out.println("commit on sender msgs = " + msgs ); - } - - /* (non-Javadoc) - * @see org.hornetq.jms.example.ClientAbstract#onRollback() - */ - @Override - protected void onRollback() - { - pendingMsgs = 0; - System.out.println("Rolled back msgs=" + msgs); - } - - public String toString() - { - return "Sender, msgs=" + msgs + ", pending=" + pendingMsgs; - - } - - // Package protected --------------------------------------------- - - // Protected ----------------------------------------------------- - - // Private ------------------------------------------------------- - - // Inner classes ------------------------------------------------- - -}
http://git-wip-us.apache.org/repos/asf/activemq-6/blob/177e6820/examples/soak/tx-restarts/src/org/hornetq/jms/example/TXRestartSoak.java ---------------------------------------------------------------------- diff --git a/examples/soak/tx-restarts/src/org/hornetq/jms/example/TXRestartSoak.java b/examples/soak/tx-restarts/src/org/hornetq/jms/example/TXRestartSoak.java deleted file mode 100644 index 3cbd306..0000000 --- a/examples/soak/tx-restarts/src/org/hornetq/jms/example/TXRestartSoak.java +++ /dev/null @@ -1,179 +0,0 @@ -/* - * Copyright 2005-2014 Red Hat, Inc. - * Red Hat licenses this file to you under the Apache License, version - * 2.0 (the "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - * implied. See the License for the specific language governing - * permissions and limitations under the License. - */ -package org.hornetq.jms.example; - -import java.util.concurrent.TimeUnit; -import java.util.logging.Logger; - -import javax.jms.BytesMessage; -import javax.jms.Connection; -import javax.jms.ConnectionFactory; -import javax.jms.MessageProducer; -import javax.jms.Queue; -import javax.jms.Session; -import javax.naming.InitialContext; - -import org.hornetq.common.example.HornetQExample; - -/** - * - * This is used as a soak test to verify HornetQ's capability of persistent messages over restarts. - * - * This is used as a smoke test before releases. - * - * WARNING: This is not a sample on how you should handle XA. - * You are supposed to use a TransactionManager. - * This class is doing the job of a TransactionManager that fits for the purpose of this test only, - * however there are many more pitfalls to deal with Transactions. - * - * This is just to stress and soak test Transactions with HornetQ. - * - * And this is dealing with XA directly for the purpose testing only. - * - * @author <a href="mailto:[email protected]">Clebert Suconic</a> - * - * - */ -public class TXRestartSoak extends HornetQExample -{ - - public static final int MIN_MESSAGES_ON_QUEUE = 50000; - - private static final Logger log = Logger.getLogger(TXRestartSoak.class.getName()); - - public static void main(final String[] args) - { - new TXRestartSoak().run(args); - } - - private TXRestartSoak() - { - super(); - } - - /* (non-Javadoc) - * @see org.hornetq.common.example.HornetQExample#runExample() - */ - @Override - public boolean runExample() throws Exception - { - - Connection connection = null; - InitialContext initialContext = null; - - try - { - // Step 1. Create an initial context to perform the JNDI lookup. - initialContext = getContext(0); - - ConnectionFactory cf = (ConnectionFactory)initialContext.lookup("/ConnectionFactory"); - - // Step 4. Create the JMS objects - connection = cf.createConnection(); - - // Step 2. Perfom a lookup on the queue - Queue queue = (Queue)initialContext.lookup("/queue/inputQueue"); - - Session session = connection.createSession(true, Session.SESSION_TRANSACTED); - - MessageProducer producer = session.createProducer(queue); - - for (int i = 0 ; i < MIN_MESSAGES_ON_QUEUE; i++) - { - BytesMessage msg = session.createBytesMessage(); - msg.setLongProperty("count", i); - msg.writeBytes(new byte[10 * 1024]); - producer.send(msg); - - if (i % 1000 == 0) - { - System.out.println("Sent " + i + " messages"); - session.commit(); - } - } - - session.commit(); - - Receiver rec1 = new Receiver("/queue/diverted1"); - Receiver rec2 = new Receiver("/queue/diverted2"); - - Sender send = new Sender(new Receiver[]{rec1, rec2}); - - send.start(); - rec1.start(); - rec2.start(); - - long timeEnd = System.currentTimeMillis() + TimeUnit.HOURS.toMillis(1); - - if (runServer) - { - while (timeEnd > System.currentTimeMillis()) - { - System.out.println("Letting the service run for 20 seconds"); - Thread.sleep(TimeUnit.SECONDS.toMillis(20)); - stopServers(); - - Thread.sleep(10000); - - boolean disconnected = false; - - if (send.getErrorsCount() != 0 || rec1.getErrorsCount() != 0 || rec2.getErrorsCount() != 0) - { - System.out.println("There are sequence errors in some of the clients, please look at the logs"); - break; - } - - while (!disconnected) - { - disconnected = send.getConnection() == null && rec1.getConnection() == null && rec2.getConnection() == null; - if (!disconnected) - { - System.out.println("NOT ALL THE CLIENTS ARE DISCONNECTED, NEED TO WAIT THEM"); - } - Thread.sleep(1000); - } - - startServers(); - } - } - else - { - while (timeEnd > System.currentTimeMillis()) - { - if (send.getErrorsCount() != 0 || rec1.getErrorsCount() != 0 || rec2.getErrorsCount() != 0) - { - System.out.println("There are sequence errors in some of the clients, please look at the logs"); - break; - } - Thread.sleep(10000); - } - } - - send.setRunning(false); - rec1.setRunning(false); - rec2.setRunning(false); - - send.join(); - rec1.join(); - rec2.join(); - - return send.getErrorsCount() == 0 && rec1.getErrorsCount() == 0 && rec2.getErrorsCount() == 0; - - } - finally - { - connection.close(); - } - - } -} http://git-wip-us.apache.org/repos/asf/activemq-6/blob/177e6820/hornetq-bootstrap/pom.xml ---------------------------------------------------------------------- diff --git a/hornetq-bootstrap/pom.xml b/hornetq-bootstrap/pom.xml index f450cb3..50befc1 100644 --- a/hornetq-bootstrap/pom.xml +++ b/hornetq-bootstrap/pom.xml @@ -18,6 +18,21 @@ <dependencies> <dependency> + <groupId>org.hornetq</groupId> + <artifactId>hornetq-server</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>org.hornetq</groupId> + <artifactId>hornetq-jms-server</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>org.hornetq</groupId> + <artifactId>hornetq-dto</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> <groupId>org.jboss.logging</groupId> <artifactId>jboss-logging-processor</artifactId> </dependency> @@ -26,9 +41,28 @@ <artifactId>jboss-logging</artifactId> </dependency> <dependency> - <groupId>org.jboss.microcontainer</groupId> - <artifactId>jboss-kernel</artifactId> + <groupId>io.airlift</groupId> + <artifactId>airline</artifactId> </dependency> </dependencies> + <build> + <resources> + <resource> + <directory>${project.basedir}/src/main/resources</directory> + <includes> + <include>**/*</include> + </includes> + </resource> + <resource> + <directory>${project.basedir}/src/main/filtered-resources</directory> + <filtering>true</filtering> + <includes> + <include>**/*</include> + </includes> + </resource> + </resources> + </build> + + </project> http://git-wip-us.apache.org/repos/asf/activemq-6/blob/177e6820/hornetq-bootstrap/src/main/filtered-resources/org/hornetq/cli/banner.txt ---------------------------------------------------------------------- diff --git a/hornetq-bootstrap/src/main/filtered-resources/org/hornetq/cli/banner.txt b/hornetq-bootstrap/src/main/filtered-resources/org/hornetq/cli/banner.txt new file mode 100644 index 0000000..411caec --- /dev/null +++ b/hornetq-bootstrap/src/main/filtered-resources/org/hornetq/cli/banner.txt @@ -0,0 +1,8 @@ + _ _ _ ___ + | | | | ___ _ __ _ __ ___| |_ / _ \ + | |_| |/ _ \| '__| '_ \ / _ \ __| | | | + | _ | (_) | | | | | | __/ |_| |_| | + |_| |_|\___/|_| |_| |_|\___|\__|\__\_\ + HornetQ ${project.version} + + http://git-wip-us.apache.org/repos/asf/activemq-6/blob/177e6820/hornetq-bootstrap/src/main/java/org/hornetq/cli/ConfigurationException.java ---------------------------------------------------------------------- diff --git a/hornetq-bootstrap/src/main/java/org/hornetq/cli/ConfigurationException.java b/hornetq-bootstrap/src/main/java/org/hornetq/cli/ConfigurationException.java new file mode 100644 index 0000000..5f53bbb --- /dev/null +++ b/hornetq-bootstrap/src/main/java/org/hornetq/cli/ConfigurationException.java @@ -0,0 +1,21 @@ +/* + * Copyright 2005-2014 Red Hat, Inc. + * Red Hat licenses this file to you under the Apache License, version + * 2.0 (the "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing + * permissions and limitations under the License. + */ +package org.hornetq.cli; + +public class ConfigurationException extends Exception +{ + public ConfigurationException(String message) + { + super(message); + } +} http://git-wip-us.apache.org/repos/asf/activemq-6/blob/177e6820/hornetq-bootstrap/src/main/java/org/hornetq/cli/HornetQ.java ---------------------------------------------------------------------- diff --git a/hornetq-bootstrap/src/main/java/org/hornetq/cli/HornetQ.java b/hornetq-bootstrap/src/main/java/org/hornetq/cli/HornetQ.java new file mode 100644 index 0000000..d2e260e --- /dev/null +++ b/hornetq-bootstrap/src/main/java/org/hornetq/cli/HornetQ.java @@ -0,0 +1,76 @@ +/* + * Copyright 2005-2014 Red Hat, Inc. + * Red Hat licenses this file to you under the Apache License, version + * 2.0 (the "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing + * permissions and limitations under the License. + */ +package org.hornetq.cli; + +import io.airlift.command.Cli; +import io.airlift.command.ParseArgumentsUnexpectedException; +import org.hornetq.cli.commands.Action; +import org.hornetq.cli.commands.ActionContext; +import org.hornetq.cli.commands.HelpAction; +import org.hornetq.cli.commands.Run; +import org.hornetq.cli.commands.Stop; + +import java.io.InputStream; +import java.io.OutputStream; + +public class HornetQ +{ + + public static void main(String[] args) throws Exception + { + Cli.CliBuilder<Action> builder = Cli.<Action>builder("hornetq") + .withDefaultCommand(HelpAction.class) + .withCommand(Run.class) + .withCommand(Stop.class) + .withCommand(HelpAction.class) + .withDescription("HornetQ Command Line"); + + Cli<Action> parser = builder.build(); + + try + { + parser.parse(args).execute(ActionContext.system()); + } + catch (ParseArgumentsUnexpectedException e) + { + System.err.println(e.getMessage()); + System.out.println(); + parser.parse("help").execute(ActionContext.system()); + } + catch (ConfigurationException configException) + { + System.err.println(configException.getMessage()); + System.out.println(); + System.out.println("Configuration should be specified as 'scheme:location'. Default configuration is 'xml:${HORNETQ_HOME}/config/non-clustered/bootstrap.xml'"); + } + + } + + public static void printBanner() throws Exception + { + copy(HornetQ.class.getResourceAsStream("banner.txt"), System.out); + } + + private static long copy(InputStream in, OutputStream out) throws Exception + { + byte[] buffer = new byte[1024]; + int len = in.read(buffer); + while (len != -1) + { + out.write(buffer, 0, len); + len = in.read(buffer); + } + return len; + } + +} http://git-wip-us.apache.org/repos/asf/activemq-6/blob/177e6820/hornetq-bootstrap/src/main/java/org/hornetq/cli/commands/Action.java ---------------------------------------------------------------------- diff --git a/hornetq-bootstrap/src/main/java/org/hornetq/cli/commands/Action.java b/hornetq-bootstrap/src/main/java/org/hornetq/cli/commands/Action.java new file mode 100644 index 0000000..bf79994 --- /dev/null +++ b/hornetq-bootstrap/src/main/java/org/hornetq/cli/commands/Action.java @@ -0,0 +1,20 @@ +/* + * Copyright 2005-2014 Red Hat, Inc. + * Red Hat licenses this file to you under the Apache License, version + * 2.0 (the "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing + * permissions and limitations under the License. + */ +package org.hornetq.cli.commands; + +public interface Action +{ + + Object execute(ActionContext context) throws Exception; + +} http://git-wip-us.apache.org/repos/asf/activemq-6/blob/177e6820/hornetq-bootstrap/src/main/java/org/hornetq/cli/commands/ActionContext.java ---------------------------------------------------------------------- diff --git a/hornetq-bootstrap/src/main/java/org/hornetq/cli/commands/ActionContext.java b/hornetq-bootstrap/src/main/java/org/hornetq/cli/commands/ActionContext.java new file mode 100644 index 0000000..c31bd88 --- /dev/null +++ b/hornetq-bootstrap/src/main/java/org/hornetq/cli/commands/ActionContext.java @@ -0,0 +1,37 @@ +/* + * Copyright 2005-2014 Red Hat, Inc. + * Red Hat licenses this file to you under the Apache License, version + * 2.0 (the "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing + * permissions and limitations under the License. + */ +package org.hornetq.cli.commands; + +import java.io.InputStream; +import java.io.PrintStream; + +public class ActionContext +{ + + public ActionContext(InputStream in, PrintStream out, PrintStream err) + { + this.in = in; + this.out = out; + this.err = err; + } + + InputStream in; + PrintStream out; + PrintStream err; + + public static ActionContext system() + { + return new ActionContext(System.in, System.out, System.err); + } + +} http://git-wip-us.apache.org/repos/asf/activemq-6/blob/177e6820/hornetq-bootstrap/src/main/java/org/hornetq/cli/commands/HelpAction.java ---------------------------------------------------------------------- diff --git a/hornetq-bootstrap/src/main/java/org/hornetq/cli/commands/HelpAction.java b/hornetq-bootstrap/src/main/java/org/hornetq/cli/commands/HelpAction.java new file mode 100644 index 0000000..d87e859 --- /dev/null +++ b/hornetq-bootstrap/src/main/java/org/hornetq/cli/commands/HelpAction.java @@ -0,0 +1,26 @@ +/* + * Copyright 2005-2014 Red Hat, Inc. + * Red Hat licenses this file to you under the Apache License, version + * 2.0 (the "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing + * permissions and limitations under the License. + */ +package org.hornetq.cli.commands; + +import io.airlift.command.Help; + +public class HelpAction extends Help implements Action +{ + + @Override + public Object execute(ActionContext context) throws Exception + { + super.run(); + return null; + } +} http://git-wip-us.apache.org/repos/asf/activemq-6/blob/177e6820/hornetq-bootstrap/src/main/java/org/hornetq/cli/commands/Run.java ---------------------------------------------------------------------- diff --git a/hornetq-bootstrap/src/main/java/org/hornetq/cli/commands/Run.java b/hornetq-bootstrap/src/main/java/org/hornetq/cli/commands/Run.java new file mode 100644 index 0000000..c385524 --- /dev/null +++ b/hornetq-bootstrap/src/main/java/org/hornetq/cli/commands/Run.java @@ -0,0 +1,148 @@ +/* + * Copyright 2005-2014 Red Hat, Inc. + * Red Hat licenses this file to you under the Apache License, version + * 2.0 (the "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing + * permissions and limitations under the License. + */ +package org.hornetq.cli.commands; + +import io.airlift.command.Arguments; +import io.airlift.command.Command; + +import org.hornetq.cli.HornetQ; +import org.hornetq.core.config.Configuration; +import org.hornetq.core.server.impl.HornetQServerImpl; +import org.hornetq.dto.BrokerDTO; +import org.hornetq.factory.BrokerFactory; +import org.hornetq.factory.CoreFactory; +import org.hornetq.factory.JmsFactory; +import org.hornetq.factory.SecurityManagerFactory; +import org.hornetq.integration.bootstrap.HornetQBootstrapLogger; +import org.hornetq.jms.server.JMSServerManager; +import org.hornetq.jms.server.config.JMSConfiguration; +import org.hornetq.jms.server.impl.JMSServerManagerImpl; +import org.hornetq.jms.server.impl.StandaloneNamingServer; +import org.hornetq.spi.core.security.HornetQSecurityManager; + +import javax.management.MBeanServer; + +import java.io.File; +import java.lang.management.ManagementFactory; +import java.util.Timer; +import java.util.TimerTask; + +@Command(name = "run", description = "runs the broker instance") +public class Run implements Action +{ + + @Arguments(description = "Broker Configuration URI, default 'xml:${HORNETQ_HOME}/config/non-clustered/bootstrap.xml'") + String configuration; + private StandaloneNamingServer namingServer; + private JMSServerManager jmsServerManager; + + @Override + public Object execute(ActionContext context) throws Exception + { + + HornetQ.printBanner(); + + if (configuration == null) + { + configuration = "xml:" + System.getProperty("hornetq.home").replace("\\", "/") + "/config/non-clustered/bootstrap.xml"; + } + + System.out.println("Loading configuration file: " + configuration); + + BrokerDTO broker = BrokerFactory.createBroker(configuration); + + addShutdownHook(new File(broker.core.configuration).getParentFile()); + + Configuration core = CoreFactory.create(broker.core); + + JMSConfiguration jms = JmsFactory.create(broker.jms); + + HornetQSecurityManager security = SecurityManagerFactory.create(broker.security); + + MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer(); + + HornetQServerImpl server = new HornetQServerImpl(core, mBeanServer, security); + + namingServer = new StandaloneNamingServer(server); + + namingServer.setBindAddress(broker.naming.bindAddress); + + namingServer.setPort(broker.naming.port); + + namingServer.setRmiBindAddress(broker.naming.rmiBindAddress); + + namingServer.setRmiPort(broker.naming.rmiPort); + + namingServer.start(); + + HornetQBootstrapLogger.LOGGER.startedNamingService(broker.naming.bindAddress, broker.naming.port, broker.naming.rmiBindAddress, broker.naming.rmiPort); + + if (jms != null) + { + jmsServerManager = new JMSServerManagerImpl(server, jms); + } + else + { + jmsServerManager = new JMSServerManagerImpl(server); + } + + HornetQBootstrapLogger.LOGGER.serverStarting(); + + jmsServerManager.start(); + + return null; + } + + /** + * Add a simple shutdown hook to stop the server. + * @param configurationDir + */ + private void addShutdownHook(File configurationDir) + { + final File file = new File(configurationDir,"STOP_ME"); + if (file.exists()) + { + if (!file.delete()) + { + HornetQBootstrapLogger.LOGGER.errorDeletingFile(file.getAbsolutePath()); + } + } + final Timer timer = new Timer("HornetQ Server Shutdown Timer", true); + timer.scheduleAtFixedRate(new TimerTask() + { + @Override + public void run() + { + if (file.exists()) + { + try + { + try + { + jmsServerManager.stop(); + } + catch (Exception e) + { + e.printStackTrace(); + } + timer.cancel(); + } + finally + { + Runtime.getRuntime().exit(0); + } + } + } + }, 500, 500); + } +} http://git-wip-us.apache.org/repos/asf/activemq-6/blob/177e6820/hornetq-bootstrap/src/main/java/org/hornetq/cli/commands/Stop.java ---------------------------------------------------------------------- diff --git a/hornetq-bootstrap/src/main/java/org/hornetq/cli/commands/Stop.java b/hornetq-bootstrap/src/main/java/org/hornetq/cli/commands/Stop.java new file mode 100644 index 0000000..1478507 --- /dev/null +++ b/hornetq-bootstrap/src/main/java/org/hornetq/cli/commands/Stop.java @@ -0,0 +1,45 @@ +/* + * Copyright 2005-2014 Red Hat, Inc. + * Red Hat licenses this file to you under the Apache License, version + * 2.0 (the "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing + * permissions and limitations under the License. + */ +package org.hornetq.cli.commands; + +import io.airlift.command.Arguments; +import io.airlift.command.Command; +import org.hornetq.dto.BrokerDTO; +import org.hornetq.factory.BrokerFactory; + +import java.io.File; + +@Command(name = "stop", description = "stops the broker instance") +public class Stop implements Action +{ + @Arguments(description = "Broker Configuration URI, default 'xml:${HORNETQ_HOME}/config/non-clustered/bootstrap.xml'") + String configuration; + + @Override + public Object execute(ActionContext context) throws Exception + { + if (configuration == null) + { + configuration = "xml:" + System.getProperty("hornetq.home").replace("\\", "/") + "/config/non-clustered/bootstrap.xml"; + } + BrokerDTO broker = BrokerFactory.createBroker(configuration); + + File file = new File(broker.core.configuration).getParentFile(); + + File stopFile = new File(file, "STOP_ME"); + + stopFile.createNewFile(); + + return null; + } +} http://git-wip-us.apache.org/repos/asf/activemq-6/blob/177e6820/hornetq-bootstrap/src/main/java/org/hornetq/factory/BrokerFactory.java ---------------------------------------------------------------------- diff --git a/hornetq-bootstrap/src/main/java/org/hornetq/factory/BrokerFactory.java b/hornetq-bootstrap/src/main/java/org/hornetq/factory/BrokerFactory.java new file mode 100644 index 0000000..723b8f4 --- /dev/null +++ b/hornetq-bootstrap/src/main/java/org/hornetq/factory/BrokerFactory.java @@ -0,0 +1,52 @@ +/* + * Copyright 2005-2014 Red Hat, Inc. + * Red Hat licenses this file to you under the Apache License, version + * 2.0 (the "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing + * permissions and limitations under the License. + */ +package org.hornetq.factory; + +import org.hornetq.cli.ConfigurationException; +import org.hornetq.dto.BrokerDTO; +import org.hornetq.utils.FactoryFinder; + +import java.io.IOException; +import java.net.URI; + +public class BrokerFactory +{ + + public static BrokerDTO createBroker(URI configURI) throws Exception + { + if (configURI.getScheme() == null) + { + throw new ConfigurationException("Invalid configuration URI, no scheme specified: " + configURI); + } + + BrokerFactoryHandler factory = null; + try + { + FactoryFinder finder = new FactoryFinder("META-INF/services/org/hornetq/broker/"); + factory = (BrokerFactoryHandler)finder.newInstance(configURI.getScheme()); + } + catch (IOException ioe ) + { + throw new ConfigurationException("Invalid configuration URI, can't find configuration scheme: " + configURI.getScheme()); + } + + + return factory.createBroker(configURI); + } + + public static BrokerDTO createBroker(String configuration) throws Exception + { + return createBroker(new URI(configuration)); + } + +} http://git-wip-us.apache.org/repos/asf/activemq-6/blob/177e6820/hornetq-bootstrap/src/main/java/org/hornetq/factory/BrokerFactoryHandler.java ---------------------------------------------------------------------- diff --git a/hornetq-bootstrap/src/main/java/org/hornetq/factory/BrokerFactoryHandler.java b/hornetq-bootstrap/src/main/java/org/hornetq/factory/BrokerFactoryHandler.java new file mode 100644 index 0000000..68afb4b --- /dev/null +++ b/hornetq-bootstrap/src/main/java/org/hornetq/factory/BrokerFactoryHandler.java @@ -0,0 +1,22 @@ +/* + * Copyright 2005-2014 Red Hat, Inc. + * Red Hat licenses this file to you under the Apache License, version + * 2.0 (the "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing + * permissions and limitations under the License. + */ +package org.hornetq.factory; + +import org.hornetq.dto.BrokerDTO; + +import java.net.URI; + +public interface BrokerFactoryHandler +{ + BrokerDTO createBroker(URI brokerURI) throws Exception; +} http://git-wip-us.apache.org/repos/asf/activemq-6/blob/177e6820/hornetq-bootstrap/src/main/java/org/hornetq/factory/CoreFactory.java ---------------------------------------------------------------------- diff --git a/hornetq-bootstrap/src/main/java/org/hornetq/factory/CoreFactory.java b/hornetq-bootstrap/src/main/java/org/hornetq/factory/CoreFactory.java new file mode 100644 index 0000000..d03cc97 --- /dev/null +++ b/hornetq-bootstrap/src/main/java/org/hornetq/factory/CoreFactory.java @@ -0,0 +1,47 @@ +/* + * Copyright 2005-2014 Red Hat, Inc. + * Red Hat licenses this file to you under the Apache License, version + * 2.0 (the "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing + * permissions and limitations under the License. + */ +package org.hornetq.factory; + +import org.hornetq.cli.ConfigurationException; +import org.hornetq.core.config.Configuration; +import org.hornetq.core.config.impl.ConfigurationImpl; +import org.hornetq.dto.CoreDTO; +import org.hornetq.utils.FactoryFinder; + +import java.io.IOException; +import java.net.URI; + +public class CoreFactory +{ + public static Configuration create(CoreDTO core) throws Exception + { + if (core.configuration != null) + { + CoreFactoryHandler factory = null; + URI configURI = new URI(core.configuration.replace("\\", "/")); + try + { + FactoryFinder finder = new FactoryFinder("META-INF/services/org/hornetq/broker/core/"); + factory = (CoreFactoryHandler)finder.newInstance(configURI.getScheme()); + } + catch (IOException ioe ) + { + throw new ConfigurationException("Invalid configuration URI, can't find configuration scheme: " + configURI.getScheme()); + } + + return factory.createConfiguration(configURI); + } + return new ConfigurationImpl(); + } + +} http://git-wip-us.apache.org/repos/asf/activemq-6/blob/177e6820/hornetq-bootstrap/src/main/java/org/hornetq/factory/CoreFactoryHandler.java ---------------------------------------------------------------------- diff --git a/hornetq-bootstrap/src/main/java/org/hornetq/factory/CoreFactoryHandler.java b/hornetq-bootstrap/src/main/java/org/hornetq/factory/CoreFactoryHandler.java new file mode 100644 index 0000000..bec7c85 --- /dev/null +++ b/hornetq-bootstrap/src/main/java/org/hornetq/factory/CoreFactoryHandler.java @@ -0,0 +1,22 @@ +/* + * Copyright 2005-2014 Red Hat, Inc. + * Red Hat licenses this file to you under the Apache License, version + * 2.0 (the "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing + * permissions and limitations under the License. + */ +package org.hornetq.factory; + +import org.hornetq.core.config.Configuration; + +import java.net.URI; + +public interface CoreFactoryHandler +{ + Configuration createConfiguration(URI configuration) throws Exception; +} http://git-wip-us.apache.org/repos/asf/activemq-6/blob/177e6820/hornetq-bootstrap/src/main/java/org/hornetq/factory/FileCoreFactoryHandler.java ---------------------------------------------------------------------- diff --git a/hornetq-bootstrap/src/main/java/org/hornetq/factory/FileCoreFactoryHandler.java b/hornetq-bootstrap/src/main/java/org/hornetq/factory/FileCoreFactoryHandler.java new file mode 100644 index 0000000..76edad7 --- /dev/null +++ b/hornetq-bootstrap/src/main/java/org/hornetq/factory/FileCoreFactoryHandler.java @@ -0,0 +1,29 @@ +/* + * Copyright 2005-2014 Red Hat, Inc. + * Red Hat licenses this file to you under the Apache License, version + * 2.0 (the "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing + * permissions and limitations under the License. + */ +package org.hornetq.factory; + +import org.hornetq.core.config.Configuration; +import org.hornetq.core.config.impl.FileConfiguration; + +import java.net.URI; + +public class FileCoreFactoryHandler implements CoreFactoryHandler +{ + @Override + public Configuration createConfiguration(URI configuration) throws Exception + { + FileConfiguration fileConfiguration = new FileConfiguration(configuration.toURL().toExternalForm()); + fileConfiguration.start(); + return fileConfiguration; + } +} http://git-wip-us.apache.org/repos/asf/activemq-6/blob/177e6820/hornetq-bootstrap/src/main/java/org/hornetq/factory/FileJmsFactoryHandler.java ---------------------------------------------------------------------- diff --git a/hornetq-bootstrap/src/main/java/org/hornetq/factory/FileJmsFactoryHandler.java b/hornetq-bootstrap/src/main/java/org/hornetq/factory/FileJmsFactoryHandler.java new file mode 100644 index 0000000..dc28036 --- /dev/null +++ b/hornetq-bootstrap/src/main/java/org/hornetq/factory/FileJmsFactoryHandler.java @@ -0,0 +1,32 @@ +/* + * Copyright 2005-2014 Red Hat, Inc. + * Red Hat licenses this file to you under the Apache License, version + * 2.0 (the "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing + * permissions and limitations under the License. + */ +package org.hornetq.factory; + +import org.hornetq.jms.server.config.JMSConfiguration; +import org.hornetq.jms.server.impl.JMSServerConfigParserImpl; + +import java.io.FileInputStream; +import java.io.InputStream; +import java.net.URI; + +public class FileJmsFactoryHandler implements JmsFactoryHandler +{ + @Override + public JMSConfiguration createConfiguration(URI configuration) throws Exception + { + try (InputStream configIn = new FileInputStream(configuration.getSchemeSpecificPart())) + { + return new JMSServerConfigParserImpl().parseConfiguration(configIn); + } + } +} http://git-wip-us.apache.org/repos/asf/activemq-6/blob/177e6820/hornetq-bootstrap/src/main/java/org/hornetq/factory/JmsFactory.java ---------------------------------------------------------------------- diff --git a/hornetq-bootstrap/src/main/java/org/hornetq/factory/JmsFactory.java b/hornetq-bootstrap/src/main/java/org/hornetq/factory/JmsFactory.java new file mode 100644 index 0000000..755ce58 --- /dev/null +++ b/hornetq-bootstrap/src/main/java/org/hornetq/factory/JmsFactory.java @@ -0,0 +1,46 @@ +/* + * Copyright 2005-2014 Red Hat, Inc. + * Red Hat licenses this file to you under the Apache License, version + * 2.0 (the "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing + * permissions and limitations under the License. + */ +package org.hornetq.factory; + +import java.io.IOException; +import java.net.URI; + +import org.hornetq.cli.ConfigurationException; +import org.hornetq.dto.JmsDTO; +import org.hornetq.jms.server.config.JMSConfiguration; +import org.hornetq.utils.FactoryFinder; + +public class JmsFactory +{ + public static JMSConfiguration create(JmsDTO jms) throws Exception + { + if (jms != null && jms.configuration != null) + { + JmsFactoryHandler factory = null; + URI configURI = new URI(jms.configuration.replace("\\", "/")); + try + { + FactoryFinder finder = new FactoryFinder("META-INF/services/org/hornetq/broker/jms/"); + factory = (JmsFactoryHandler)finder.newInstance(configURI.getScheme()); + } + catch (IOException ioe ) + { + throw new ConfigurationException("Invalid configuration URI, can't find configuration scheme: " + configURI.getScheme()); + } + + return factory.createConfiguration(configURI); + } + + return null; + } +} http://git-wip-us.apache.org/repos/asf/activemq-6/blob/177e6820/hornetq-bootstrap/src/main/java/org/hornetq/factory/JmsFactoryHandler.java ---------------------------------------------------------------------- diff --git a/hornetq-bootstrap/src/main/java/org/hornetq/factory/JmsFactoryHandler.java b/hornetq-bootstrap/src/main/java/org/hornetq/factory/JmsFactoryHandler.java new file mode 100644 index 0000000..0a1bbd5 --- /dev/null +++ b/hornetq-bootstrap/src/main/java/org/hornetq/factory/JmsFactoryHandler.java @@ -0,0 +1,22 @@ +/* + * Copyright 2005-2014 Red Hat, Inc. + * Red Hat licenses this file to you under the Apache License, version + * 2.0 (the "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing + * permissions and limitations under the License. + */ +package org.hornetq.factory; + +import org.hornetq.jms.server.config.JMSConfiguration; + +import java.net.URI; + +public interface JmsFactoryHandler +{ + JMSConfiguration createConfiguration(URI configuration) throws Exception; +} http://git-wip-us.apache.org/repos/asf/activemq-6/blob/177e6820/hornetq-bootstrap/src/main/java/org/hornetq/factory/SecurityManagerFactory.java ---------------------------------------------------------------------- diff --git a/hornetq-bootstrap/src/main/java/org/hornetq/factory/SecurityManagerFactory.java b/hornetq-bootstrap/src/main/java/org/hornetq/factory/SecurityManagerFactory.java new file mode 100644 index 0000000..c1ad221 --- /dev/null +++ b/hornetq-bootstrap/src/main/java/org/hornetq/factory/SecurityManagerFactory.java @@ -0,0 +1,38 @@ +/* + * Copyright 2005-2014 Red Hat, Inc. + * Red Hat licenses this file to you under the Apache License, version + * 2.0 (the "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing + * permissions and limitations under the License. + */ +package org.hornetq.factory; + +import org.hornetq.dto.SecurityDTO; +import org.hornetq.spi.core.security.HornetQSecurityManager; +import org.hornetq.utils.FactoryFinder; + +import javax.xml.bind.annotation.XmlRootElement; + +public class SecurityManagerFactory +{ + + public static HornetQSecurityManager create(SecurityDTO config) throws Exception + { + if (config != null) + { + FactoryFinder finder = new FactoryFinder("META-INF/services/org/hornetq/security/"); + HornetQSecurityManager manager = (HornetQSecurityManager)finder.newInstance(config.getClass().getAnnotation(XmlRootElement.class).name()); + return manager; + } + else + { + throw new Exception("No security manager configured!"); + } + } + +} http://git-wip-us.apache.org/repos/asf/activemq-6/blob/177e6820/hornetq-bootstrap/src/main/java/org/hornetq/factory/XmlBrokerFactoryHandler.java ---------------------------------------------------------------------- diff --git a/hornetq-bootstrap/src/main/java/org/hornetq/factory/XmlBrokerFactoryHandler.java b/hornetq-bootstrap/src/main/java/org/hornetq/factory/XmlBrokerFactoryHandler.java new file mode 100644 index 0000000..ffb37b9 --- /dev/null +++ b/hornetq-bootstrap/src/main/java/org/hornetq/factory/XmlBrokerFactoryHandler.java @@ -0,0 +1,34 @@ +/* + * Copyright 2005-2014 Red Hat, Inc. + * Red Hat licenses this file to you under the Apache License, version + * 2.0 (the "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing + * permissions and limitations under the License. + */ +package org.hornetq.factory; + +import org.hornetq.cli.ConfigurationException; +import org.hornetq.dto.BrokerDTO; +import org.hornetq.dto.XmlUtil; + +import java.io.File; +import java.net.URI; + +public class XmlBrokerFactoryHandler implements BrokerFactoryHandler +{ + @Override + public BrokerDTO createBroker(URI brokerURI) throws Exception + { + File file = new File(brokerURI.getSchemeSpecificPart()); + if (!file.exists()) + { + throw new ConfigurationException("Invalid configuration URI, can't find file: " + file.getName()); + } + return XmlUtil.decode(BrokerDTO.class, file); + } +} http://git-wip-us.apache.org/repos/asf/activemq-6/blob/177e6820/hornetq-bootstrap/src/main/java/org/hornetq/integration/bootstrap/HornetQBootstrapLogger.java ---------------------------------------------------------------------- diff --git a/hornetq-bootstrap/src/main/java/org/hornetq/integration/bootstrap/HornetQBootstrapLogger.java b/hornetq-bootstrap/src/main/java/org/hornetq/integration/bootstrap/HornetQBootstrapLogger.java index f85b78c..a426752 100644 --- a/hornetq-bootstrap/src/main/java/org/hornetq/integration/bootstrap/HornetQBootstrapLogger.java +++ b/hornetq-bootstrap/src/main/java/org/hornetq/integration/bootstrap/HornetQBootstrapLogger.java @@ -53,6 +53,10 @@ public interface HornetQBootstrapLogger extends BasicLogger @Message(id = 101001, value = "Stopping HornetQ Server", format = Message.Format.MESSAGE_FORMAT) void serverStopping(); + @LogMessage(level = Logger.Level.INFO) + @Message(id = 101002, value = "Starting Naming server on {0}:{1,number,#} (rmi {2}:{3,number,#})", format = Message.Format.MESSAGE_FORMAT) + void startedNamingService(String bindAddress, int port, String rmiBindAddress, int rmiPort); + @LogMessage(level = Logger.Level.WARN) @Message(id = 102000, value = "Error during undeployment: {0}", format = Message.Format.MESSAGE_FORMAT) void errorDuringUndeployment(@Cause Throwable t, String name); http://git-wip-us.apache.org/repos/asf/activemq-6/blob/177e6820/hornetq-bootstrap/src/main/java/org/hornetq/integration/bootstrap/HornetQBootstrapServer.java ---------------------------------------------------------------------- diff --git a/hornetq-bootstrap/src/main/java/org/hornetq/integration/bootstrap/HornetQBootstrapServer.java b/hornetq-bootstrap/src/main/java/org/hornetq/integration/bootstrap/HornetQBootstrapServer.java deleted file mode 100644 index 34a8246..0000000 --- a/hornetq-bootstrap/src/main/java/org/hornetq/integration/bootstrap/HornetQBootstrapServer.java +++ /dev/null @@ -1,284 +0,0 @@ -/* - * Copyright 2005-2014 Red Hat, Inc. - * Red Hat licenses this file to you under the Apache License, version - * 2.0 (the "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - * implied. See the License for the specific language governing - * permissions and limitations under the License. - */ -package org.hornetq.integration.bootstrap; - -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.File; -import java.io.PrintStream; -import java.net.URL; -import java.util.List; -import java.util.ListIterator; -import java.util.Properties; -import java.util.Timer; -import java.util.TimerTask; -import java.util.concurrent.CopyOnWriteArrayList; - -import org.jboss.kernel.plugins.bootstrap.basic.BasicBootstrap; -import org.jboss.kernel.plugins.deployment.xml.BeanXMLDeployer; -import org.jboss.kernel.spi.config.KernelConfig; -import org.jboss.kernel.spi.deployment.KernelDeployment; - -/** - * This is the method in which the HornetQ server can be deployed externally outside of jBoss. - * Alternatively a user can embed by using the same code as in main - * @author <a href="[email protected]">Andy Taylor</a> - */ -public class HornetQBootstrapServer extends BasicBootstrap -{ - /** - * The deployer - */ - protected BeanXMLDeployer deployer; - - /** - * The deployments - */ - protected List<KernelDeployment> deployments = new CopyOnWriteArrayList<KernelDeployment>(); - - /** - * The arguments - */ - private final String[] args; - - private Properties properties; - - /** - * Bootstrap the kernel from the command line - * - * @param args the command line arguments - * @throws Exception for any error - */ - public static void main(final String[] args) throws Exception - { - HornetQBootstrapLogger.LOGGER.serverStarting(); - - final HornetQBootstrapServer bootstrap = new HornetQBootstrapServer(args); - - bootstrap.run(); - - bootstrap.addShutdownHook(); - } - - /** - * Add a simple shutdown hook to stop the server. - */ - private void addShutdownHook() - { - String dirName = System.getProperty("hornetq.config.dir", "."); - final File file = new File(dirName + "/STOP_ME"); - if (file.exists()) - { - if (!file.delete()) - { - HornetQBootstrapLogger.LOGGER.errorDeletingFile(file.getAbsolutePath()); - } - } - final Timer timer = new Timer("HornetQ Server Shutdown Timer", true); - timer.scheduleAtFixedRate(new TimerTask() - { - @Override - public void run() - { - if (file.exists()) - { - try - { - shutDown(); - timer.cancel(); - } - finally - { - Runtime.getRuntime().exit(0); - } - } - } - }, 500, 500); - } - - @Override - public void run() - { - try - { - super.run(); - } - catch (RuntimeException e) - { - HornetQBootstrapLogger.LOGGER.errorStartingServer(e); - - throw e; - } - } - - /** - * JBoss 1.0.0 final - * Standalone - * Create a new bootstrap - * - * @param args the arguments - * @throws Exception for any error - */ - public HornetQBootstrapServer(final String... args) throws Exception - { - super(); - this.args = args; - } - - public HornetQBootstrapServer(final KernelConfig kernelConfig, final String... args) throws Exception - { - super(kernelConfig); - this.args = args; - } - - @Override - public void bootstrap() throws Throwable - { - super.bootstrap(); - deployer = new BeanXMLDeployer(getKernel()); - Runtime.getRuntime().addShutdownHook(new Shutdown()); - - for (String arg : args) - { - deploy(arg); - } - - deployer.validate(); - } - - /** - * Undeploy a deployment - * - * @param deployment the deployment - */ - public void undeploy(final KernelDeployment deployment) throws Throwable - { - HornetQBootstrapLogger.LOGGER.debug("Undeploying " + deployment.getName()); - deployments.remove(deployment); - try - { - deployer.undeploy(deployment); - HornetQBootstrapLogger.LOGGER.debug("Undeployed " + deployment.getName()); - } - catch (Throwable t) - { - HornetQBootstrapLogger.LOGGER.errorDuringUndeployment(t, deployment.getName()); - HornetQBootstrapLogger.LOGGER.warn("Error during undeployment: " + deployment.getName(), t); - } - } - - public KernelDeployment deploy(final String arg) throws Throwable - { - ClassLoader cl = Thread.currentThread().getContextClassLoader(); - URL url = cl.getResource(arg); - if (url == null) - { - url = cl.getResource("META-INF/" + arg); - } - // try the system classpath - if (url == null) - { - url = getClass().getClassLoader().getResource(arg); - } - if (url == null) - { - File file = new File(arg); - if (file.exists()) - { - url = file.toURI().toURL(); - } - } - if (url == null) - { - throw new RuntimeException("Unable to find resource:" + arg); - } - return deploy(url); - } - - /** - * Deploys a XML on the container - */ - public KernelDeployment deploy(final String name, final String xml) throws Throwable - { - ByteArrayOutputStream byteOut = new ByteArrayOutputStream(); - PrintStream printOut = new PrintStream(byteOut); - printOut.print(xml); - printOut.flush(); - ByteArrayInputStream is = new ByteArrayInputStream(byteOut.toByteArray()); - - KernelDeployment deployment = deployer.deploy(name, is); - - deployments.add(deployment); - - return deployment; - } - - /** - * Deploy a url - * - * @param url the deployment url - * @throws Throwable for any error - */ - private KernelDeployment deploy(final URL url) throws Throwable - { - HornetQBootstrapLogger.LOGGER.debug("Deploying " + url); - KernelDeployment deployment = deployer.deploy(url); - deployments.add(deployment); - HornetQBootstrapLogger.LOGGER.debug("Deployed " + url); - return deployment; - } - - public void shutDown() - { - HornetQBootstrapLogger.LOGGER.serverStopping(); - - ListIterator<KernelDeployment> iterator = deployments.listIterator(deployments.size()); - while (iterator.hasPrevious()) - { - KernelDeployment deployment = iterator.previous(); - try - { - undeploy(deployment); - } - catch (Throwable t) - { - HornetQBootstrapLogger.LOGGER.errorDuringUndeployment(t, deployment.getName()); - } - } - } - - @Override - protected Properties getConfigProperties() - { - return properties; - } - - public void setProperties(final Properties props) - { - properties = props; - } - - private final class Shutdown extends Thread - { - public Shutdown() - { - super("hornetq-shutdown-thread"); - } - - @Override - public void run() - { - shutDown(); - } - } -} http://git-wip-us.apache.org/repos/asf/activemq-6/blob/177e6820/hornetq-bootstrap/src/main/resources/META-INF/services/org/hornetq/broker/core/file ---------------------------------------------------------------------- diff --git a/hornetq-bootstrap/src/main/resources/META-INF/services/org/hornetq/broker/core/file b/hornetq-bootstrap/src/main/resources/META-INF/services/org/hornetq/broker/core/file new file mode 100644 index 0000000..3fc5087 --- /dev/null +++ b/hornetq-bootstrap/src/main/resources/META-INF/services/org/hornetq/broker/core/file @@ -0,0 +1,13 @@ +## --------------------------------------------------------------------------- +## Copyright 2005-2014 Red Hat, Inc. +## Red Hat licenses this file to you under the Apache License, version +## 2.0 (the "License"); you may not use this file except in compliance +## with the License. You may obtain a copy of the License at +## http://www.apache.org/licenses/LICENSE-2.0 +## Unless required by applicable law or agreed to in writing, software +## distributed under the License is distributed on an "AS IS" BASIS, +## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or +## implied. See the License for the specific language governing +## permissions and limitations under the License. +## --------------------------------------------------------------------------- +class=org.hornetq.factory.FileCoreFactoryHandler \ No newline at end of file http://git-wip-us.apache.org/repos/asf/activemq-6/blob/177e6820/hornetq-bootstrap/src/main/resources/META-INF/services/org/hornetq/broker/jms/file ---------------------------------------------------------------------- diff --git a/hornetq-bootstrap/src/main/resources/META-INF/services/org/hornetq/broker/jms/file b/hornetq-bootstrap/src/main/resources/META-INF/services/org/hornetq/broker/jms/file new file mode 100644 index 0000000..e3a9587 --- /dev/null +++ b/hornetq-bootstrap/src/main/resources/META-INF/services/org/hornetq/broker/jms/file @@ -0,0 +1,13 @@ +## --------------------------------------------------------------------------- +## Copyright 2005-2014 Red Hat, Inc. +## Red Hat licenses this file to you under the Apache License, version +## 2.0 (the "License"); you may not use this file except in compliance +## with the License. You may obtain a copy of the License at +## http://www.apache.org/licenses/LICENSE-2.0 +## Unless required by applicable law or agreed to in writing, software +## distributed under the License is distributed on an "AS IS" BASIS, +## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or +## implied. See the License for the specific language governing +## permissions and limitations under the License. +## --------------------------------------------------------------------------- +class=org.hornetq.factory.FileJmsFactoryHandler \ No newline at end of file http://git-wip-us.apache.org/repos/asf/activemq-6/blob/177e6820/hornetq-bootstrap/src/main/resources/META-INF/services/org/hornetq/broker/xml ---------------------------------------------------------------------- diff --git a/hornetq-bootstrap/src/main/resources/META-INF/services/org/hornetq/broker/xml b/hornetq-bootstrap/src/main/resources/META-INF/services/org/hornetq/broker/xml new file mode 100644 index 0000000..9501c92 --- /dev/null +++ b/hornetq-bootstrap/src/main/resources/META-INF/services/org/hornetq/broker/xml @@ -0,0 +1,13 @@ +## --------------------------------------------------------------------------- +## Copyright 2005-2014 Red Hat, Inc. +## Red Hat licenses this file to you under the Apache License, version +## 2.0 (the "License"); you may not use this file except in compliance +## with the License. You may obtain a copy of the License at +## http://www.apache.org/licenses/LICENSE-2.0 +## Unless required by applicable law or agreed to in writing, software +## distributed under the License is distributed on an "AS IS" BASIS, +## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or +## implied. See the License for the specific language governing +## permissions and limitations under the License. +## --------------------------------------------------------------------------- +class=org.hornetq.factory.XmlBrokerFactoryHandler \ No newline at end of file http://git-wip-us.apache.org/repos/asf/activemq-6/blob/177e6820/hornetq-commons/src/main/java/org/hornetq/utils/ByteUtil.java ---------------------------------------------------------------------- diff --git a/hornetq-commons/src/main/java/org/hornetq/utils/ByteUtil.java b/hornetq-commons/src/main/java/org/hornetq/utils/ByteUtil.java new file mode 100644 index 0000000..20285e1 --- /dev/null +++ b/hornetq-commons/src/main/java/org/hornetq/utils/ByteUtil.java @@ -0,0 +1,82 @@ +/* + * Copyright 2005-2014 Red Hat, Inc. + * Red Hat licenses this file to you under the Apache License, version + * 2.0 (the "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing + * permissions and limitations under the License. + */ + +package org.hornetq.utils; + +import io.netty.buffer.ByteBuf; +import io.netty.buffer.UnpooledByteBufAllocator; + +/** + * @author Clebert Suconic + */ + +public class ByteUtil +{ + + private static final char[] hexArray = "0123456789ABCDEF".toCharArray(); + + public static String maxString(String value, int size) + { + if (value.length() < size) + { + return value; + } + else + { + return value.substring(0, size / 2) + " ... " + value.substring(value.length() - size / 2); + } + } + public static String bytesToHex(byte[] bytes, int groupSize) + { + if (bytes == null) + { + return "null"; + } + else + { + char[] hexChars = new char[bytes.length * 2 + numberOfGroups(bytes, groupSize)]; + int outPos = 0; + for (int j = 0; j < bytes.length; j++) + { + if (j > 0 && j % groupSize == 0) + { + hexChars[outPos++] = ' '; + } + int v = bytes[j] & 0xFF; + hexChars[outPos++] = hexArray[v >>> 4]; + hexChars[outPos++] = hexArray[v & 0x0F]; + } + return new String(hexChars); + } + } + + private static int numberOfGroups(byte[] bytes, int groupSize) + { + int groups = bytes.length / groupSize; + + if (bytes.length % groupSize == 0) + { + groups--; + } + + return groups; + } + + public static byte[] longToBytes(long x) + { + ByteBuf buffer = UnpooledByteBufAllocator.DEFAULT.heapBuffer(8, 8); + buffer.writeLong(x); + return buffer.array(); + } + +} http://git-wip-us.apache.org/repos/asf/activemq-6/blob/177e6820/hornetq-commons/src/main/java/org/hornetq/utils/FactoryFinder.java ---------------------------------------------------------------------- diff --git a/hornetq-commons/src/main/java/org/hornetq/utils/FactoryFinder.java b/hornetq-commons/src/main/java/org/hornetq/utils/FactoryFinder.java new file mode 100644 index 0000000..a057656 --- /dev/null +++ b/hornetq-commons/src/main/java/org/hornetq/utils/FactoryFinder.java @@ -0,0 +1,166 @@ +/* + * Copyright 2005-2014 Red Hat, Inc. + * Red Hat licenses this file to you under the Apache License, version + * 2.0 (the "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing + * permissions and limitations under the License. + */ +package org.hornetq.utils; + +import java.io.BufferedInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.util.Properties; +import java.util.concurrent.ConcurrentHashMap; + +public class FactoryFinder +{ + /** + * The strategy that the FactoryFinder uses to find load and instantiate Objects + * can be changed out by calling the + * {@link org.hornetq.utils.FactoryFinder#setObjectFactory(org.hornetq.utils.FactoryFinder.ObjectFactory)} + * method with a custom implementation of ObjectFactory. + * <p/> + * The default ObjectFactory is typically changed out when running in a specialized container + * environment where service discovery needs to be done via the container system. For example, + * in an OSGi scenario. + */ + public interface ObjectFactory + { + /** + * @param path the full service path + * @return + */ + Object create(String path) throws IllegalAccessException, InstantiationException, IOException, ClassNotFoundException; + + } + + /** + * The default implementation of Object factory which works well in standalone applications. + */ + protected static class StandaloneObjectFactory implements ObjectFactory + { + final ConcurrentHashMap<String, Class> classMap = new ConcurrentHashMap<String, Class>(); + + public Object create(final String path) throws InstantiationException, IllegalAccessException, ClassNotFoundException, IOException + { + Class clazz = classMap.get(path); + if (clazz == null) + { + clazz = loadClass(loadProperties(path)); + classMap.put(path, clazz); + } + return clazz.newInstance(); + } + + static Class loadClass(Properties properties) throws ClassNotFoundException, IOException + { + + String className = properties.getProperty("class"); + if (className == null) + { + throw new IOException("Expected property is missing: class"); + } + Class clazz = null; + ClassLoader loader = Thread.currentThread().getContextClassLoader(); + if (loader != null) + { + try + { + clazz = loader.loadClass(className); + } + catch (ClassNotFoundException e) + { + // ignore + } + } + if (clazz == null) + { + clazz = FactoryFinder.class.getClassLoader().loadClass(className); + } + + return clazz; + } + + public Properties loadProperties(String uri) throws IOException + { + // lets try the thread context class loader first + ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); + if (classLoader == null) + { + classLoader = StandaloneObjectFactory.class.getClassLoader(); + } + InputStream in = classLoader.getResourceAsStream(uri); + if (in == null) + { + in = FactoryFinder.class.getClassLoader().getResourceAsStream(uri); + if (in == null) + { + throw new IOException("Could not find factory class for resource: " + uri); + } + } + + // lets load the file + BufferedInputStream reader = null; + try + { + reader = new BufferedInputStream(in); + Properties properties = new Properties(); + properties.load(reader); + return properties; + } + finally + { + try + { + reader.close(); + } + catch (Exception e) + { + } + } + } + } + + // ================================================================ + // Class methods and properties + // ================================================================ + private static ObjectFactory objectFactory = new StandaloneObjectFactory(); + + public static ObjectFactory getObjectFactory() + { + return objectFactory; + } + + public static void setObjectFactory(ObjectFactory objectFactory) + { + FactoryFinder.objectFactory = objectFactory; + } + + // ================================================================ + // Instance methods and properties + // ================================================================ + private final String path; + + public FactoryFinder(String path) + { + this.path = path; + } + + /** + * Creates a new instance of the given key + * + * @param key is the key to add to the path to find a text file containing + * the factory name + * @return a newly created instance + */ + public Object newInstance(String key) throws IllegalAccessException, InstantiationException, IOException, ClassNotFoundException + { + return objectFactory.create(path + key); + } +} http://git-wip-us.apache.org/repos/asf/activemq-6/blob/177e6820/hornetq-commons/src/main/java/org/hornetq/utils/HornetQThreadFactory.java ---------------------------------------------------------------------- diff --git a/hornetq-commons/src/main/java/org/hornetq/utils/HornetQThreadFactory.java b/hornetq-commons/src/main/java/org/hornetq/utils/HornetQThreadFactory.java index 2fc63ec..be16d4c 100644 --- a/hornetq-commons/src/main/java/org/hornetq/utils/HornetQThreadFactory.java +++ b/hornetq-commons/src/main/java/org/hornetq/utils/HornetQThreadFactory.java @@ -49,44 +49,20 @@ public final class HornetQThreadFactory implements ThreadFactory public Thread newThread(final Runnable command) { - final Thread t; - // attach the thread to a group only if there is no security manager: - // when sandboxed, the code does not have the RuntimePermission modifyThreadGroup - if (System.getSecurityManager() == null) + // always create a thread in a privileged block. + return AccessController.doPrivileged(new PrivilegedAction<Thread>() { - t = new Thread(group, command, "Thread-" + threadCount.getAndIncrement() + " (" + group.getName() + ")"); - } - else - { - t = new Thread(command, "Thread-" + threadCount.getAndIncrement()); - } - - AccessController.doPrivileged(new PrivilegedAction<Object>() - { - public Object run() + @Override + public Thread run() { + final Thread t = new Thread(group, command, "Thread-" + threadCount.getAndIncrement() + " (" + group.getName() + ")"); t.setDaemon(daemon); t.setPriority(threadPriority); - return null; + t.setContextClassLoader(tccl); + + return t; } }); - - try - { - AccessController.doPrivileged(new PrivilegedAction<Object>() - { - public Object run() - { - t.setContextClassLoader(tccl); - return null; - } - }); - } - catch (java.security.AccessControlException e) - { - HornetQUtilLogger.LOGGER.missingPrivsForClassloader(); - } - - return t; } + } http://git-wip-us.apache.org/repos/asf/activemq-6/blob/177e6820/hornetq-commons/src/main/java/org/hornetq/utils/TypedProperties.java ---------------------------------------------------------------------- diff --git a/hornetq-commons/src/main/java/org/hornetq/utils/TypedProperties.java b/hornetq-commons/src/main/java/org/hornetq/utils/TypedProperties.java index f6375a8..d970ebd 100644 --- a/hornetq-commons/src/main/java/org/hornetq/utils/TypedProperties.java +++ b/hornetq-commons/src/main/java/org/hornetq/utils/TypedProperties.java @@ -12,8 +12,10 @@ */ package org.hornetq.utils; +import java.nio.ByteBuffer; import java.util.Collections; import java.util.HashMap; +import java.util.Iterator; import java.util.Map; import java.util.Map.Entry; import java.util.Set; @@ -599,7 +601,70 @@ public final class TypedProperties @Override public String toString() { - return "TypedProperties[" + properties + "]"; + StringBuilder sb = new StringBuilder("TypedProperties["); + + + if (properties != null) + { + + Iterator<Entry<SimpleString, PropertyValue>> iter = properties.entrySet().iterator(); + + while (iter.hasNext()) + { + Entry<SimpleString, PropertyValue> iterItem = iter.next(); + sb.append(iterItem.getKey() + "="); + + // it seems weird but it's right!! + // The first getValue is from the EntrySet + // The second is to convert the PropertyValue into the actual value + Object theValue = iterItem.getValue().getValue(); + + + if (theValue == null) + { + sb.append("NULL-value"); + } + else if (theValue instanceof byte[]) + { + sb.append("[" + ByteUtil.maxString(ByteUtil.bytesToHex((byte [])theValue, 2), 150) + ")"); + + if (iterItem.getKey().toString().startsWith("_HQ_ROUTE_TO")) + { + sb.append(",bytesAsLongs("); + try + { + ByteBuffer buff = ByteBuffer.wrap((byte[]) theValue); + while (buff.hasRemaining()) + { + long bindingID = buff.getLong(); + sb.append(bindingID); + if (buff.hasRemaining()) + { + sb.append(","); + } + } + } + catch (Throwable e) + { + sb.append("error-converting-longs=" + e.getMessage()); + } + sb.append("]"); + } + } + else + { + sb.append(theValue.toString()); + } + + + if (iter.hasNext()) + { + sb.append(","); + } + } + } + + return sb.append("]").toString(); } // Private ------------------------------------------------------------------------------------ http://git-wip-us.apache.org/repos/asf/activemq-6/blob/177e6820/hornetq-commons/src/main/java/org/hornetq/utils/UTF8Util.java ---------------------------------------------------------------------- diff --git a/hornetq-commons/src/main/java/org/hornetq/utils/UTF8Util.java b/hornetq-commons/src/main/java/org/hornetq/utils/UTF8Util.java index 55cda20..6fd9253 100644 --- a/hornetq-commons/src/main/java/org/hornetq/utils/UTF8Util.java +++ b/hornetq-commons/src/main/java/org/hornetq/utils/UTF8Util.java @@ -167,7 +167,7 @@ public final class UTF8Util } - private static StringUtilBuffer getThreadLocalBuffer() + public static StringUtilBuffer getThreadLocalBuffer() { SoftReference<StringUtilBuffer> softReference = UTF8Util.currenBuffer.get(); StringUtilBuffer value; @@ -234,7 +234,7 @@ public final class UTF8Util return calculatedLen; } - private static class StringUtilBuffer + public static class StringUtilBuffer { public char[] charBuffer; http://git-wip-us.apache.org/repos/asf/activemq-6/blob/177e6820/hornetq-commons/src/test/java/org/hornetq/utils/ByteUtilTest.java ---------------------------------------------------------------------- diff --git a/hornetq-commons/src/test/java/org/hornetq/utils/ByteUtilTest.java b/hornetq-commons/src/test/java/org/hornetq/utils/ByteUtilTest.java new file mode 100644 index 0000000..f6ee7a2 --- /dev/null +++ b/hornetq-commons/src/test/java/org/hornetq/utils/ByteUtilTest.java @@ -0,0 +1,52 @@ +/* + * Copyright 2005-2014 Red Hat, Inc. + * Red Hat licenses this file to you under the Apache License, version + * 2.0 (the "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing + * permissions and limitations under the License. + */ + +package org.hornetq.utils; + +import org.junit.Assert; +import org.junit.Test; + +/** + * @author Clebert Suconic + */ + +public class ByteUtilTest +{ + @Test + public void testBytesToString() + { + byte[] byteArray = new byte[] {0, 1, 2, 3}; + + testEquals("0001 0203", ByteUtil.bytesToHex(byteArray, 2)); + testEquals("00 01 02 03", ByteUtil.bytesToHex(byteArray, 1)); + testEquals("000102 03", ByteUtil.bytesToHex(byteArray, 3)); + } + + + @Test + public void testMaxString() + { + byte[] byteArray = new byte[20 * 1024]; + System.out.println(ByteUtil.maxString(ByteUtil.bytesToHex(byteArray, 2),150)); + } + + + void testEquals(String string1, String string2) + { + if (!string1.equals(string2)) + { + Assert.fail("String are not the same:=" + string1 + "!=" + string2); + } + } + +} http://git-wip-us.apache.org/repos/asf/activemq-6/blob/177e6820/hornetq-core-client/src/main/java/org/hornetq/api/core/BroadcastEndpointFactory.java ---------------------------------------------------------------------- diff --git a/hornetq-core-client/src/main/java/org/hornetq/api/core/BroadcastEndpointFactory.java b/hornetq-core-client/src/main/java/org/hornetq/api/core/BroadcastEndpointFactory.java index 447f708..ae6b5ab 100644 --- a/hornetq-core-client/src/main/java/org/hornetq/api/core/BroadcastEndpointFactory.java +++ b/hornetq-core-client/src/main/java/org/hornetq/api/core/BroadcastEndpointFactory.java @@ -12,8 +12,10 @@ */ package org.hornetq.api.core; +import java.io.Serializable; -public interface BroadcastEndpointFactory + +public interface BroadcastEndpointFactory extends Serializable { BroadcastEndpoint createBroadcastEndpoint() throws Exception; } http://git-wip-us.apache.org/repos/asf/activemq-6/blob/177e6820/hornetq-core-client/src/main/java/org/hornetq/api/core/BroadcastGroupConfiguration.java ---------------------------------------------------------------------- diff --git a/hornetq-core-client/src/main/java/org/hornetq/api/core/BroadcastGroupConfiguration.java b/hornetq-core-client/src/main/java/org/hornetq/api/core/BroadcastGroupConfiguration.java index 2e35112..575cc32 100644 --- a/hornetq-core-client/src/main/java/org/hornetq/api/core/BroadcastGroupConfiguration.java +++ b/hornetq-core-client/src/main/java/org/hornetq/api/core/BroadcastGroupConfiguration.java @@ -15,6 +15,8 @@ package org.hornetq.api.core; import java.io.Serializable; import java.util.List; +import org.hornetq.api.config.HornetQDefaultConfiguration; + /** * The basic configuration used to determine how the server will broadcast members @@ -28,23 +30,16 @@ public final class BroadcastGroupConfiguration implements Serializable { private static final long serialVersionUID = 2335634694112319124L; - private String name; + private String name = null; - private long broadcastPeriod; + private long broadcastPeriod = HornetQDefaultConfiguration.getDefaultBroadcastPeriod(); - private final BroadcastEndpointFactoryConfiguration endpointFactoryConfiguration; + private BroadcastEndpointFactoryConfiguration endpointFactoryConfiguration = null; - private List<String> connectorInfos; + private List<String> connectorInfos = null; - public BroadcastGroupConfiguration(final String name, - final long broadcastPeriod, - final List<String> connectorInfos, - final BroadcastEndpointFactoryConfiguration endpointFactoryConfiguration) + public BroadcastGroupConfiguration() { - this.name = name; - this.broadcastPeriod = broadcastPeriod; - this.connectorInfos = connectorInfos; - this.endpointFactoryConfiguration = endpointFactoryConfiguration; } public String getName() @@ -62,19 +57,22 @@ public final class BroadcastGroupConfiguration implements Serializable return connectorInfos; } - public void setName(final String name) + public BroadcastGroupConfiguration setName(final String name) { this.name = name; + return this; } - public void setBroadcastPeriod(final long broadcastPeriod) + public BroadcastGroupConfiguration setBroadcastPeriod(final long broadcastPeriod) { this.broadcastPeriod = broadcastPeriod; + return this; } - public void setConnectorInfos(final List<String> connectorInfos) + public BroadcastGroupConfiguration setConnectorInfos(final List<String> connectorInfos) { this.connectorInfos = connectorInfos; + return this; } public BroadcastEndpointFactoryConfiguration getEndpointFactoryConfiguration() @@ -82,6 +80,12 @@ public final class BroadcastGroupConfiguration implements Serializable return endpointFactoryConfiguration; } + public BroadcastGroupConfiguration setEndpointFactoryConfiguration(BroadcastEndpointFactoryConfiguration endpointFactoryConfiguration) + { + this.endpointFactoryConfiguration = endpointFactoryConfiguration; + return this; + } + @Override public int hashCode() { http://git-wip-us.apache.org/repos/asf/activemq-6/blob/177e6820/hornetq-core-client/src/main/java/org/hornetq/api/core/DiscoveryGroupConfiguration.java ---------------------------------------------------------------------- diff --git a/hornetq-core-client/src/main/java/org/hornetq/api/core/DiscoveryGroupConfiguration.java b/hornetq-core-client/src/main/java/org/hornetq/api/core/DiscoveryGroupConfiguration.java index dbd83a8..d97408e 100644 --- a/hornetq-core-client/src/main/java/org/hornetq/api/core/DiscoveryGroupConfiguration.java +++ b/hornetq-core-client/src/main/java/org/hornetq/api/core/DiscoveryGroupConfiguration.java @@ -17,6 +17,7 @@ import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.io.Serializable; +import org.hornetq.api.core.client.HornetQClient; import org.hornetq.utils.UUIDGenerator; /** @@ -36,61 +37,39 @@ public final class DiscoveryGroupConfiguration implements Serializable { private static final long serialVersionUID = 8657206421727863400L; - private String name; + private String name = UUIDGenerator.getInstance().generateStringUUID(); - private long refreshTimeout; + private long refreshTimeout = HornetQClient.DEFAULT_DISCOVERY_REFRESH_TIMEOUT; - private long discoveryInitialWaitTimeout; + private long discoveryInitialWaitTimeout = HornetQClient.DEFAULT_DISCOVERY_INITIAL_WAIT_TIMEOUT; /* * The localBindAddress is needed so we can be backward compatible with 2.2 clients * */ - private transient String localBindAddress; + private transient String localBindAddress = null; /* * The localBindPort is needed so we can be backward compatible with 2.2 clients * */ - private transient int localBindPort; + private transient int localBindPort = -1; /* * The groupAddress is needed so we can be backward compatible with 2.2 clients * */ - private String groupAddress; + private String groupAddress = null; /* * The groupPort is needed so we can be backward compatible with 2.2 clients * */ - private int groupPort; + private int groupPort = -1; /* * This is the actual object used by the class, it has to be transient so we can handle deserialization with a 2.2 client * */ private transient BroadcastEndpointFactoryConfiguration endpointFactoryConfiguration; - public DiscoveryGroupConfiguration(final String name, - final long refreshTimeout, - final long discoveryInitialWaitTimeout, BroadcastEndpointFactoryConfiguration - endpointFactoryConfiguration) + public DiscoveryGroupConfiguration() { - this.name = name; - this.refreshTimeout = refreshTimeout; - this.discoveryInitialWaitTimeout = discoveryInitialWaitTimeout; - this.endpointFactoryConfiguration = endpointFactoryConfiguration; - if (endpointFactoryConfiguration instanceof DiscoveryGroupConfigurationCompatibilityHelper) - { - DiscoveryGroupConfigurationCompatibilityHelper dgcch = (DiscoveryGroupConfigurationCompatibilityHelper) endpointFactoryConfiguration; - localBindAddress = dgcch.getLocalBindAddress(); - localBindPort = dgcch.getLocalBindPort(); - groupAddress = dgcch.getGroupAddress(); - groupPort = dgcch.getGroupPort(); - } - } - - public DiscoveryGroupConfiguration(final long refreshTimeout, - final long discoveryInitialWaitTimeout, - BroadcastEndpointFactoryConfiguration endpointFactoryConfiguration) - { - this(UUIDGenerator.getInstance().generateStringUUID(), refreshTimeout, discoveryInitialWaitTimeout, endpointFactoryConfiguration); } public String getName() @@ -106,17 +85,19 @@ public final class DiscoveryGroupConfiguration implements Serializable /** * @param name the name to set */ - public void setName(final String name) + public DiscoveryGroupConfiguration setName(final String name) { this.name = name; + return this; } /** * @param refreshTimeout the refreshTimeout to set */ - public void setRefreshTimeout(final long refreshTimeout) + public DiscoveryGroupConfiguration setRefreshTimeout(final long refreshTimeout) { this.refreshTimeout = refreshTimeout; + return this; } /** @@ -130,9 +111,10 @@ public final class DiscoveryGroupConfiguration implements Serializable /** * @param discoveryInitialWaitTimeout the discoveryInitialWaitTimeout to set */ - public void setDiscoveryInitialWaitTimeout(long discoveryInitialWaitTimeout) + public DiscoveryGroupConfiguration setDiscoveryInitialWaitTimeout(long discoveryInitialWaitTimeout) { this.discoveryInitialWaitTimeout = discoveryInitialWaitTimeout; + return this; } public BroadcastEndpointFactoryConfiguration getBroadcastEndpointFactoryConfiguration() @@ -140,6 +122,20 @@ public final class DiscoveryGroupConfiguration implements Serializable return endpointFactoryConfiguration; } + public DiscoveryGroupConfiguration setBroadcastEndpointFactoryConfiguration(BroadcastEndpointFactoryConfiguration endpointFactoryConfiguration) + { + this.endpointFactoryConfiguration = endpointFactoryConfiguration; + if (endpointFactoryConfiguration instanceof DiscoveryGroupConfigurationCompatibilityHelper) + { + DiscoveryGroupConfigurationCompatibilityHelper dgcch = (DiscoveryGroupConfigurationCompatibilityHelper) endpointFactoryConfiguration; + localBindAddress = dgcch.getLocalBindAddress(); + localBindPort = dgcch.getLocalBindPort(); + groupAddress = dgcch.getGroupAddress(); + groupPort = dgcch.getGroupPort(); + } + return this; + } + private void writeObject(ObjectOutputStream out) throws IOException { out.defaultWriteObject(); @@ -158,7 +154,11 @@ public final class DiscoveryGroupConfiguration implements Serializable } else { - endpointFactoryConfiguration = new UDPBroadcastGroupConfiguration(groupAddress, groupPort, localBindAddress, localBindPort); + endpointFactoryConfiguration = new UDPBroadcastGroupConfiguration() + .setGroupAddress(groupAddress) + .setGroupPort(groupPort) + .setLocalBindAddress(localBindAddress) + .setLocalBindPort(localBindPort); } }
