ACTIVEMQ6-51 Example server bootstrapping

This commit is contained in:
jbertram 2014-12-08 22:31:39 -06:00
parent 4f925c5a44
commit a102983d7a
688 changed files with 2698 additions and 1837 deletions

View File

@ -0,0 +1,61 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-pom</artifactId>
<version>6.0.0-SNAPSHOT</version>
</parent>
<artifactId>activemq-maven-plugin</artifactId>
<packaging>maven-plugin</packaging>
<name>ActiveMQ6 Maven Plugin</name>
<properties>
<activemq.basedir>${project.basedir}/..</activemq.basedir>
</properties>
<dependencies>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-api</artifactId>
<version>2.0</version>
</dependency>
<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.0</version>
</dependency>
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-server</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-jms-server</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-all</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.0</version>
<configuration>
<showWarnings>true</showWarnings>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
</build>
</project>

View File

@ -0,0 +1,27 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF 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.apache.activemq.maven;
/**
* @author <a href="mailto:andy.taylor@jboss.com">Andy Taylor</a>
* Date: 8/18/11
* Time: 2:35 PM
*/
public interface ActiveMQClient
{
void run();
}

View File

@ -0,0 +1,72 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF 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.apache.activemq.maven;
import java.lang.reflect.Method;
import java.util.Properties;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
/**
* @author <a href="mailto:andy.taylor@jboss.com">Andy Taylor</a>
*
* Allows a Java Client to be run which must hve a static main(String[] args) method
*/
/**
* @phase verify
* @goal runClient
*/
public class ActiveMQClientPlugin extends AbstractMojo
{
/**
* @parameter
*/
String clientClass;
/**
* @parameter
*/
String[] args;
/**
* @parameter
*/
private Properties systemProperties;
public void execute() throws MojoExecutionException, MojoFailureException
{
try
{
if (systemProperties != null && !systemProperties.isEmpty())
{
System.getProperties().putAll(systemProperties);
}
Class aClass = Class.forName(clientClass);
Method method = aClass.getDeclaredMethod("main", new Class[]{String[].class});
method.invoke(null, new Object[]{args});
}
catch (Exception e)
{
e.printStackTrace();
throw new MojoFailureException(e.getMessage());
}
}
}

View File

@ -0,0 +1,228 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF 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.apache.activemq.maven;
import javax.management.MBeanServer;
import javax.management.ObjectName;
import java.io.File;
import java.lang.management.ManagementFactory;
import java.util.Arrays;
import java.util.Properties;
import org.apache.activemq.server.ActiveMQBootstrap;
import org.apache.activemq.server.SpawnedActiveMQBootstrap;
import org.apache.activemq.server.SpawnedVMSupport;
import org.apache.activemq.spi.core.security.ActiveMQSecurityManager;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugin.descriptor.PluginDescriptor;
import org.codehaus.classworlds.ClassRealm;
import org.codehaus.classworlds.ClassWorld;
/**
* @author <a href="mailto:andy.taylor@jboss.com">Andy Taylor</a>
*/
/**
* @phase verify
* @goal start
*/
public class ActiveMQStartPlugin extends AbstractMojo
{
/**
* The plugin descriptor
*/
private PluginDescriptor descriptor;
/**
* @parameter default-value=false
*/
private Boolean waitOnStart;
/**
* @parameter
*/
private String configurationDir;
/**
* @parameter
*/
private String nodeId;
/**
* @parameter default-value=false;
*/
private Boolean fork;
/**
* @parameter default-value=false
*/
private Boolean debug;
/**
* @parameter
*/
private Properties systemProperties;
/**
* @parameter default-value=STARTED::
*/
private String serverStartString;
/**
* @parameter
*/
private ActiveMQSecurityManager securityManager;
/**
* registers a TestClusterMBean for test clients to use.
*/
private boolean testClusterManager;
public void execute() throws MojoExecutionException, MojoFailureException
{
if (testClusterManager)
{
try
{
createClusterManagerMBean();
}
catch (Exception e)
{
throw new MojoExecutionException("Failed to create cluster manager mbean", e);
}
}
if (systemProperties != null && !systemProperties.isEmpty())
{
System.getProperties()
.putAll(systemProperties);
}
String workingPath = new File(".").getAbsolutePath();
try
{
registerNode(nodeId, workingPath, configurationDir);
}
catch (Exception e1)
{
throw new MojoExecutionException("Failed to create cluster manager mbean", e1);
}
if (fork)
{
try
{
PluginDescriptor pd = (PluginDescriptor) getPluginContext().get("pluginDescriptor");
final Process p = SpawnedVMSupport.spawnVM(pd.getArtifacts(),
"ActiveMQServer_" + (nodeId != null ? nodeId : ""),
SpawnedActiveMQBootstrap.class.getName(),
systemProperties,
true,
serverStartString,
"FAILED::",
".",
configurationDir,
debug,
configurationDir,
"" + waitOnStart,
nodeId);
Runtime.getRuntime().addShutdownHook(new Thread()
{
@Override
public void run()
{
//just to be on the safe side
p.destroy();
}
});
if (waitOnStart)
{
p.waitFor();
}
}
catch (Throwable e)
{
e.printStackTrace();
throw new MojoExecutionException(e.getMessage());
}
}
else
{
ActiveMQBootstrap bootstrap = new ActiveMQBootstrap(configurationDir, waitOnStart, nodeId, securityManager);
if (configurationDir != null)
{
extendPluginClasspath(configurationDir);
}
try
{
bootstrap.execute();
}
catch (Exception e)
{
throw new MojoExecutionException(e.getMessage(), e);
}
}
}
private void registerNode(String nodeId, String workingPath,
String hornetqConfigurationDir) throws Exception
{
TestClusterManagerMBean control = PluginUtil.getTestClusterManager();
if (control != null)
{
control.registerNode(nodeId, workingPath, hornetqConfigurationDir);
}
}
private void createClusterManagerMBean() throws Exception
{
MBeanServer mbeanServer = ManagementFactory.getPlatformMBeanServer();
ObjectName name = ObjectName.getInstance("hornetq:module=test,type=TestClusterManager");
mbeanServer.registerMBean(new TestClusterManager(), name);
}
public void extendPluginClasspath(String element) throws MojoExecutionException
{
ClassWorld world = new ClassWorld();
ClassRealm realm;
try
{
realm = world.newRealm(
"maven.plugin." + getClass().getSimpleName() + ((nodeId == null) ? "" : nodeId),
Thread.currentThread()
.getContextClassLoader()
);
File elementFile = new File(element);
getLog().debug("Adding element to plugin classpath" + elementFile.getPath());
realm.addConstituent(elementFile.toURI()
.toURL());
}
catch (Exception ex)
{
throw new MojoExecutionException(ex.toString(), ex);
}
System.out.println(Arrays.toString(realm.getConstituents()));
Thread.currentThread()
.setContextClassLoader(realm.getClassLoader());
}
}

View File

@ -0,0 +1,78 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF 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.apache.activemq.maven;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import java.io.File;
import java.io.IOException;
/**
* @author <a href="mailto:andy.taylor@jboss.com">Andy Taylor</a>
* Date: 8/18/11
* Time: 12:25 PM
*/
/**
* @phase verify
* @goal stop
*/
public class ActiveMQStopPlugin extends AbstractMojo
{
/**
* @parameter
*/
private String configurationDir;
public void execute() throws MojoExecutionException, MojoFailureException
{
try
{
String dirName = configurationDir != null ? configurationDir : ".";
final File file = new File(dirName + "/" + "/STOP_ME");
file.createNewFile();
long time = System.currentTimeMillis();
while (System.currentTimeMillis() < time + 60000)
{
if (!file.exists())
{
break;
}
try
{
Thread.sleep(200);
}
catch (InterruptedException e)
{
//ignore
}
}
if (file.exists())
{
throw new MojoExecutionException("looks like the server hasn't been stopped");
}
}
catch (IOException e)
{
e.printStackTrace();
throw new MojoExecutionException(e.getMessage());
}
}
}

View File

@ -0,0 +1,73 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF 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.apache.activemq.maven;
import javax.management.MBeanServer;
import org.apache.activemq.core.config.Configuration;
import org.apache.activemq.core.server.NodeManager;
import org.apache.activemq.core.server.impl.ActiveMQServerImpl;
import org.apache.activemq.spi.core.security.ActiveMQSecurityManager;
public final class InVMNodeManagerServer extends ActiveMQServerImpl
{
final NodeManager nodeManager;
public InVMNodeManagerServer(final NodeManager nodeManager)
{
super();
this.nodeManager = nodeManager;
}
public InVMNodeManagerServer(final Configuration configuration, final NodeManager nodeManager)
{
super(configuration);
this.nodeManager = nodeManager;
}
public InVMNodeManagerServer(final Configuration configuration,
final MBeanServer mbeanServer,
final NodeManager nodeManager)
{
super(configuration, mbeanServer);
this.nodeManager = nodeManager;
}
public InVMNodeManagerServer(final Configuration configuration,
final ActiveMQSecurityManager securityManager,
final NodeManager nodeManager)
{
super(configuration, securityManager);
this.nodeManager = nodeManager;
}
public InVMNodeManagerServer(final Configuration configuration,
final MBeanServer mbeanServer,
final ActiveMQSecurityManager securityManager,
final NodeManager nodeManager)
{
super(configuration, mbeanServer, securityManager);
this.nodeManager = nodeManager;
}
@Override
protected NodeManager createNodeManager(final String directory, boolean replicatingBackup)
{
return nodeManager;
}
}

View File

@ -0,0 +1,50 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF 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.apache.activemq.maven;
import javax.management.MBeanServerConnection;
import javax.management.MBeanServerInvocationHandler;
import javax.management.ObjectName;
import javax.management.remote.JMXConnector;
import javax.management.remote.JMXConnectorFactory;
import javax.management.remote.JMXServiceURL;
import java.util.HashMap;
public class PluginUtil
{
public static TestClusterManagerMBean getTestClusterManager()
{
final String JMX_URL = "service:jmx:rmi:///jndi/rmi://localhost:3000/jmxrmi";
try
{
JMXConnector connector = JMXConnectorFactory.connect(new JMXServiceURL(JMX_URL), new HashMap<String, String>());
ObjectName name = ObjectName.getInstance("activemq:module=test,type=TestClusterManager");
MBeanServerConnection mbsc = connector.getMBeanServerConnection();
TestClusterManagerMBean clusterControl = MBeanServerInvocationHandler.newProxyInstance(mbsc,
name,
TestClusterManagerMBean.class,
false);
clusterControl.getNumNodes();//serves as a validation.
return clusterControl;
}
catch (Exception e)
{
return null;
}
}
}

View File

@ -0,0 +1,52 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF 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.apache.activemq.maven;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
public class TestClusterManager implements TestClusterManagerMBean
{
private List<TestNode> testNodes = new ArrayList<TestNode>();
@Override
public int getNumNodes()
{
synchronized (testNodes)
{
return testNodes.size();
}
}
@Override
public void registerNode(String nodeId, String workingDir,
String hornetqConfigurationDir)
{
synchronized (testNodes)
{
testNodes.add(new TestNode(nodeId, workingDir, hornetqConfigurationDir));
}
}
@Override
public void killNode(int i) throws IOException
{
TestNode node = testNodes.get(i);
node.kill();
}
}

View File

@ -0,0 +1,29 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF 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.apache.activemq.maven;
import java.io.IOException;
public interface TestClusterManagerMBean
{
int getNumNodes();
void registerNode(String nodeId, String workingDir,
String hornetqConfigurationDirt);
void killNode(int i) throws IOException;
}

View File

@ -0,0 +1,49 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF 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.apache.activemq.maven;
import java.io.File;
import java.io.IOException;
public class TestNode
{
String nodeId;
String workingDir;
String configDir;
public TestNode(String nodeId, String workingDir,
String configDir)
{
this.nodeId = nodeId;
this.workingDir = workingDir;
this.configDir = configDir;
}
public void kill() throws IOException
{
File file = new File(configDir, "KILL_ME");
file.createNewFile();
try
{
Thread.sleep(3000);
}
catch (InterruptedException e)
{
}
}
}

View File

@ -0,0 +1,258 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF 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.apache.activemq.server;
import java.io.File;
import java.lang.management.ManagementFactory;
import java.util.HashMap;
import java.util.Map;
import java.util.Timer;
import java.util.TimerTask;
import org.apache.activemq.core.config.Configuration;
import org.apache.activemq.core.config.HAPolicyConfiguration;
import org.apache.activemq.core.config.impl.ConfigurationImpl;
import org.apache.activemq.core.config.impl.FileConfiguration;
import org.apache.activemq.core.server.ActiveMQServer;
import org.apache.activemq.core.server.JournalType;
import org.apache.activemq.core.server.NodeManager;
import org.apache.activemq.core.server.impl.ActiveMQServerImpl;
import org.apache.activemq.core.server.impl.InVMNodeManager;
import org.apache.activemq.jms.server.JMSServerManager;
import org.apache.activemq.jms.server.impl.JMSServerManagerImpl;
import org.apache.activemq.maven.InVMNodeManagerServer;
import org.apache.activemq.spi.core.security.ActiveMQSecurityManager;
import org.apache.activemq.spi.core.security.ActiveMQSecurityManagerImpl;
/**
* This will bootstrap the HornetQ Server and also the naming server if required
*
* @author <a href="mailto:andy.taylor@jboss.org">Andy Taylor</a>
*/
public class ActiveMQBootstrap
{
private final String configurationDir;
private final Boolean waitOnStart;
private final String nodeId;
private static Map<String, NodeManager> managerMap = new HashMap<String, NodeManager>();
private boolean spawned = false;
private ActiveMQServer server;
private Configuration configuration;
private JMSServerManager manager;
private ActiveMQSecurityManager securityManager;
public ActiveMQBootstrap(String configurationDir, Boolean waitOnStart, String nodeId, ActiveMQSecurityManager securityManager)
{
this.configurationDir = configurationDir;
this.waitOnStart = waitOnStart;
this.nodeId = nodeId;
this.securityManager = securityManager;
}
public ActiveMQBootstrap(String[] args)
{
this.configurationDir = args[0];
this.waitOnStart = Boolean.valueOf(args[1]);
this.nodeId = args[2];
spawned = true;
}
public void execute() throws Exception
{
try
{
if (configurationDir != null)
{
//extendPluginClasspath(configurationDir);
configuration = new FileConfiguration();
File file = new File(configurationDir + "/" + "activemq-configuration.xml");
((FileConfiguration) configuration).setConfigurationUrl(file.toURI().toURL().toExternalForm());
((FileConfiguration) configuration).start();
}
else
{
configuration = new ConfigurationImpl();
configuration.setJournalType(JournalType.NIO);
}
createServer(configuration);
if (waitOnStart)
{
String dirName = System.getProperty("activemq.config.dir", ".");
final File file = new File(dirName + "/STOP_ME");
if (file.exists())
{
file.delete();
}
while (!file.exists())
{
Thread.sleep(500);
}
manager.stop();
file.delete();
}
else
{
String dirName = configurationDir != null ? configurationDir : ".";
final File stopFile = new File(dirName + "/STOP_ME");
if (stopFile.exists())
{
stopFile.delete();
}
final File killFile = new File(dirName + "/KILL_ME");
if (killFile.exists())
{
killFile.delete();
}
final File restartFile = new File(dirName + "/RESTART_ME");
if (restartFile.exists())
{
restartFile.delete();
}
final Timer timer = new Timer("ActiveMQ Server Shutdown Timer", true);
timer.scheduleAtFixedRate(new ServerStopTimerTask(stopFile, killFile, restartFile, timer), 500, 500);
}
}
catch (Exception e)
{
e.printStackTrace();
throw new Exception(e.getMessage());
}
}
private void createServer(Configuration configuration) throws Exception
{
if (nodeId != null && !nodeId.equals("") && !nodeId.equals("null"))
{
InVMNodeManager nodeManager = (InVMNodeManager) managerMap.get(nodeId);
if (nodeManager == null)
{
boolean replicatedBackup = configuration.getHAPolicyConfiguration().getType() == HAPolicyConfiguration.TYPE.REPLICA;
nodeManager = new InVMNodeManager(replicatedBackup, configuration.getJournalDirectory());
managerMap.put(nodeId, nodeManager);
}
server = new InVMNodeManagerServer(configuration, ManagementFactory.getPlatformMBeanServer(),
securityManager != null ? securityManager : new ActiveMQSecurityManagerImpl(), nodeManager);
}
else
{
server = new ActiveMQServerImpl(configuration, ManagementFactory.getPlatformMBeanServer(),
securityManager != null ? securityManager : new ActiveMQSecurityManagerImpl());
}
manager = new JMSServerManagerImpl(server);
manager.start();
}
private class ServerStopTimerTask extends TimerTask
{
private final File stopFile;
private final Timer timer;
private final File killFile;
private final File restartFile;
public ServerStopTimerTask(File stopFile, File killFile, File restartFile, Timer timer)
{
this.stopFile = stopFile;
this.killFile = killFile;
this.restartFile = restartFile;
this.timer = timer;
}
@Override
public void run()
{
if (stopFile.exists())
{
try
{
timer.cancel();
}
finally
{
try
{
if (manager != null)
{
manager.stop();
manager = null;
}
server = null;
stopFile.delete();
}
catch (Exception e)
{
e.printStackTrace();
}
}
if (spawned)
{
Runtime.getRuntime()
.halt(666);
}
}
else if (killFile.exists())
{
try
{
if (!spawned)
{
manager.getActiveMQServer()
.stop(true);
manager.stop();
manager = null;
server = null;
killFile.delete();
}
else
{
killFile.delete();
Runtime.getRuntime().halt(777);
}
}
catch (Exception e)
{
e.printStackTrace();
}
}
else if (restartFile.exists())
{
try
{
createServer(configuration);
restartFile.delete();
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
}
}

View File

@ -0,0 +1,41 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF 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.apache.activemq.server;
/**
* @author <a href="mailto:andy.taylor@jboss.org">Andy Taylor</a>
* 5/14/12
*
* This class will be spawned in a new vm and will call the bootstrap
*/
public class SpawnedActiveMQBootstrap
{
public static void main(final String[] args)
{
ActiveMQBootstrap bootstrap;
try
{
bootstrap = new ActiveMQBootstrap(args);
bootstrap.execute();
System.out.println("STARTED::");
}
catch (Throwable e)
{
System.out.println("FAILED::" + e.getMessage());
}
}
}

View File

@ -0,0 +1,257 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF 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.apache.activemq.server;
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import org.apache.maven.artifact.DefaultArtifact;
/**
* @author <a href="mailto:ovidiu@feodorov.com">Ovidiu Feodorov</a>
* @author <a href="mailto:jmesnil@redhat.com">Jeff Mesnil</a>
* @author <a href="mailto:csuconic@redhat.com">Clebert Suconic</a>
*/
public class SpawnedVMSupport
{
public static Process spawnVM(List<DefaultArtifact> arts,
final String logName,
final String className,
final Properties properties,
final boolean logOutput,
final String success,
final String failure,
final String workDir,
final String configDir,
boolean debug,
final String... args) throws Exception
{
StringBuffer sb = new StringBuffer();
sb.append("java")
.append(' ');
StringBuffer props = new StringBuffer();
if (properties != null)
{
for (Map.Entry<Object, Object> entry : properties.entrySet())
{
props.append("-D")
.append(entry.getKey())
.append("=")
.append(entry.getValue())
.append(" ");
}
}
String vmarg = props.toString();
String osName = System.getProperty("os.name");
osName = (osName != null) ? osName.toLowerCase() : "";
boolean isWindows = osName.contains("win");
if (isWindows)
{
vmarg = vmarg.replaceAll("/", "\\\\");
}
sb.append(vmarg)
.append(" ");
String pathSeparater = System.getProperty("path.separator");
StringBuilder classpath = new StringBuilder();
for (DefaultArtifact artifact : arts)
{
classpath.append(artifact.getFile()
.getAbsolutePath())
.append(pathSeparater);
}
classpath.append(configDir)
.append(pathSeparater);
if (isWindows)
{
sb.append("-cp")
.append(" \"")
.append(classpath.toString())
.append("\" ");
}
else
{
sb.append("-cp")
.append(" ")
.append(classpath.toString())
.append(" ");
}
// FIXME - not good to assume path separator
String libPath = "-Djava.library.path=" + System.getProperty("java.library.path", "./native/bin");
if (isWindows)
{
libPath = libPath.replaceAll("/", "\\\\");
libPath = "\"" + libPath + "\"";
}
sb.append("-Djava.library.path=")
.append(libPath)
.append(" ");
if (debug)
{
sb.append("-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005 ");
}
sb.append(className)
.append(' ');
for (String arg : args)
{
sb.append(arg)
.append(' ');
}
String commandLine = sb.toString();
//SpawnedVMSupport.log.trace("command line: " + commandLine);
Process process = Runtime.getRuntime()
.exec(commandLine, null, new File(workDir));
//SpawnedVMSupport.log.trace("process: " + process);
CountDownLatch latch = new CountDownLatch(1);
ProcessLogger outputLogger = new ProcessLogger(logOutput,
process.getInputStream(),
logName,
false,
success,
failure,
latch);
outputLogger.start();
// Adding a reader to System.err, so the VM won't hang on a System.err.println as identified on this forum thread:
// http://www.jboss.org/index.html?module=bb&op=viewtopic&t=151815
ProcessLogger errorLogger = new ProcessLogger(true,
process.getErrorStream(),
logName,
true,
success,
failure,
latch);
errorLogger.start();
if (!latch.await(60, TimeUnit.SECONDS))
{
process.destroy();
throw new RuntimeException("Timed out waiting for server to start");
}
if (outputLogger.failed || errorLogger.failed)
{
try
{
process.destroy();
}
catch (Throwable e)
{
}
throw new RuntimeException("server failed to start");
}
return process;
}
/**
* Redirect the input stream to a logger (as debug logs)
*/
static class ProcessLogger extends Thread
{
private final InputStream is;
private final String logName;
private final boolean print;
private final boolean sendToErr;
private final String success;
private final String failure;
private final CountDownLatch latch;
boolean failed = false;
ProcessLogger(final boolean print,
final InputStream is,
final String logName,
final boolean sendToErr,
final String success,
final String failure,
final CountDownLatch latch) throws ClassNotFoundException
{
this.is = is;
this.print = print;
this.logName = logName;
this.sendToErr = sendToErr;
this.success = success;
this.failure = failure;
this.latch = latch;
setDaemon(false);
}
@Override
public void run()
{
try
{
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);
String line;
while ((line = br.readLine()) != null)
{
if (line.startsWith(success))
{
failed = false;
latch.countDown();
}
else if (line.startsWith(failure))
{
failed = true;
latch.countDown();
}
if (print)
{
if (sendToErr)
{
System.err.println(logName + " err:" + line);
}
else
{
System.out.println(logName + " out:" + line);
}
}
}
}
catch (IOException e)
{
// ok, stream closed
}
}
}
}

View File

@ -63,7 +63,7 @@
</goals>
<configuration>
<waitOnStart>true</waitOnStart>
<hornetqConfigurationDir>${basedir}/target/classes/server0</hornetqConfigurationDir>
<configurationDir>${basedir}/target/classes/server0</configurationDir>
<systemProperties>
<property>
<name>build.directory</name>
@ -75,7 +75,7 @@
</executions>
<configuration>
<waitOnStart>false</waitOnStart>
<hornetqConfigurationDir>${basedir}/target/classes/server0</hornetqConfigurationDir>
<configurationDir>${basedir}/target/classes/server0</configurationDir>
</configuration>
<dependencies>
<dependency>

View File

@ -161,7 +161,7 @@
</dependencies>
<configuration>
<waitOnStart>false</waitOnStart>
<hornetqConfigurationDir>${basedir}/target/classes/server0</hornetqConfigurationDir>
<configurationDir>${basedir}/target/classes/server0</configurationDir>
</configuration>
</plugin>
</plugins>

View File

@ -43,12 +43,11 @@ import org.apache.activemq.jms.client.ActiveMQConnectionFactory;
*/
public abstract class ActiveMQExample
{
protected static final Logger log = Logger.getLogger(ActiveMQExample.class
.getName());
protected static final Logger log = Logger.getLogger(ActiveMQExample.class.getName());
protected boolean failure = false;
private String[] args;
protected String[] args;
public abstract boolean runExample() throws Exception;
@ -176,17 +175,6 @@ public abstract class ActiveMQExample
}
}
protected InitialContext getContext(final int serverId) throws Exception
{
ActiveMQExample.log.info("using " + args[serverId] + " for jndi");
Properties props = new Properties();
props.put("java.naming.factory.initial", "org.apache.activemq.jndi.ActiveMQInitialContextFactory");
props.put("java.naming.provider.url", args[serverId]);
props.put("queue.queue/exampleQueue", "exampleQueue");
props.put("topic.topic/exampleTopic", "exampleTopic");
return new InitialContext(props);
}
protected int getServer(Connection connection)
{
ClientSession session = ((ActiveMQConnection) connection).getInitialSession();

View File

@ -125,7 +125,7 @@
</dependencies>
<configuration>
<waitOnStart>false</waitOnStart>
<hornetqConfigurationDir>${basedir}/target/classes/activemq/server0</hornetqConfigurationDir>
<configurationDir>${basedir}/target/classes/activemq/server0</configurationDir>
</configuration>
</plugin>
</plugins>

View File

@ -65,8 +65,8 @@
<pre class="prettyprint">
<code>
&lt;queues>
&lt;queue name="jms.queue.aerogearQueue">
&lt;address>jms.queue.aerogearQueue&lt;/address>
&lt;queue name="jms.queue.exampleQueue">
&lt;address>jms.queue.exampleQueue&lt;/address>
&lt;/queue>
&lt;/queues>
@ -74,7 +74,7 @@
&lt;connector-service name="aerogear-connector">
&lt;factory-class>org.apache.activemq.integration.aerogear.AeroGearConnectorServiceFactory&lt;/factory-class>
&lt;param key="endpoint" value="${endpoint}"/>
&lt;param key="queue" value="jms.queue.aerogearQueue"/>
&lt;param key="queue" value="jms.queue.exampleQueue"/>
&lt;param key="application-id" value="${applicationid}"/>
&lt;param key="master-secret" value="${mastersecret}"/>
&lt;/connector-service>
@ -105,7 +105,7 @@
<p>Now lets look at a snippet of code we used to send the message for our JMS client</p>
<pre class="prettyprint">
<code>
Queue queue = (Queue)initialContext.lookup("/queue/aerogearQueue");
Queue queue = (Queue)initialContext.lookup("queue/exampleQueue");
// Step 3. Perform a lookup on the Connection Factory
ConnectionFactory cf = (ConnectionFactory)initialContext.lookup("/ConnectionFactory");

View File

@ -48,7 +48,7 @@ public class AerogearExample extends ActiveMQExample
try
{
// Step 1. Create an initial context to perform the JNDI lookup.
initialContext = getContext(0);
initialContext = new InitialContext();
// Step 2. Perfom a lookup on the queue
Queue queue = (Queue)initialContext.lookup("queue/exampleQueue");

View File

@ -9,15 +9,6 @@
<large-messages-directory>${build.directory}/server0/data/messaging/largemessages</large-messages-directory>
<paging-directory>${build.directory}/server0/data/messaging/paging</paging-directory>
<!-- Connectors -->
<connectors>
<connector name="netty-connector">
<factory-class>org.apache.activemq.core.remoting.impl.netty.NettyConnectorFactory</factory-class>
</connector>
</connectors>
<!-- Acceptors -->
<acceptors>
@ -29,8 +20,8 @@
<!-- We need to create a core queue for the JMS queue explicitly because the connector will be deployed
before the JMS queue is deployed, so the first time, it otherwise won't find the queue -->
<queues>
<queue name="jms.queue.aerogearQueue">
<address>jms.queue.aerogearQueue</address>
<queue name="jms.queue.exampleQueue">
<address>jms.queue.exampleQueue</address>
</queue>
</queues>
@ -38,7 +29,7 @@
<connector-service name="aerogear-connector">
<factory-class>org.apache.activemq.integration.aerogear.AeroGearConnectorServiceFactory</factory-class>
<param key="endpoint" value="${endpoint}"/>
<param key="queue" value="jms.queue.aerogearQueue"/>
<param key="queue" value="jms.queue.exampleQueue"/>
<param key="application-id" value="${applicationid}"/>
<param key="master-secret" value="${mastersecret}"/>
</connector-service>
@ -48,7 +39,7 @@
<security-settings>
<!--security for example queue-->
<security-setting match="jms.queue.aerogearQueue">
<security-setting match="jms.queue.exampleQueue">
<permission type="createDurableQueue" roles="guest"/>
<permission type="deleteDurableQueue" roles="guest"/>
<permission type="createNonDurableQueue" roles="guest"/>

View File

@ -1,2 +1,3 @@
java.naming.factory.initial=org.apache.activemq.jndi.ActiveMQInitialContextFactory
java.naming.provider.url=tcp://localhost:5445
java.naming.provider.url=tcp://localhost:5445
queue.queue/exampleQueue=exampleQueue

View File

@ -40,7 +40,7 @@
<goal>start</goal>
</goals>
<configuration>
<hornetqConfigurationDir>${basedir}/target/classes/activemq/server0</hornetqConfigurationDir>
<configurationDir>${basedir}/target/classes/activemq/server0</configurationDir>
</configuration>
</execution>
<execution>
@ -67,7 +67,7 @@
<goal>stop</goal>
</goals>
<configuration>
<hornetqConfigurationDir>${basedir}/target/classes/activemq/server0</hornetqConfigurationDir>
<configurationDir>${basedir}/target/classes/activemq/server0</configurationDir>
</configuration>
</execution>
</executions>

View File

@ -20,8 +20,8 @@ import java.net.InetSocketAddress;
import java.util.concurrent.Executors;
import org.apache.activemq.common.example.ActiveMQExample;
import org.jboss.netty.bootstrap.ServerBootstrap;
import org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory;
import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.socket.nio.NioServerSocketChannelFactory;
/**
* A HttpServer

View File

@ -22,24 +22,24 @@ import java.io.RandomAccessFile;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import org.jboss.netty.buffer.ChannelBuffers;
import org.jboss.netty.channel.Channel;
import org.jboss.netty.channel.ChannelFuture;
import org.jboss.netty.channel.ChannelFutureListener;
import org.jboss.netty.channel.ChannelHandlerContext;
import org.jboss.netty.channel.ChannelPipelineCoverage;
import org.jboss.netty.channel.ExceptionEvent;
import org.jboss.netty.channel.MessageEvent;
import org.jboss.netty.channel.SimpleChannelUpstreamHandler;
import org.jboss.netty.handler.codec.frame.TooLongFrameException;
import org.jboss.netty.handler.codec.http.DefaultHttpResponse;
import org.jboss.netty.handler.codec.http.HttpHeaders;
import org.jboss.netty.handler.codec.http.HttpMethod;
import org.jboss.netty.handler.codec.http.HttpRequest;
import org.jboss.netty.handler.codec.http.HttpResponse;
import org.jboss.netty.handler.codec.http.HttpResponseStatus;
import org.jboss.netty.handler.codec.http.HttpVersion;
import org.jboss.netty.handler.stream.ChunkedFile;
import io.netty.buffer.ChannelBuffers;
import io.netty.channel.Channel;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelFutureListener;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelPipelineCoverage;
import io.netty.channel.ExceptionEvent;
import io.netty.channel.MessageEvent;
import io.netty.channel.SimpleChannelUpstreamHandler;
import io.netty.handler.codec.frame.TooLongFrameException;
import io.netty.handler.codec.http.DefaultHttpResponse;
import io.netty.handler.codec.http.HttpHeaders;
import io.netty.handler.codec.http.HttpMethod;
import io.netty.handler.codec.http.HttpRequest;
import io.netty.handler.codec.http.HttpResponse;
import io.netty.handler.codec.http.HttpResponseStatus;
import io.netty.handler.codec.http.HttpVersion;
import io.netty.handler.stream.ChunkedFile;
/**
* A HttpStaticFileServerHandler

View File

@ -16,12 +16,12 @@
*/
package org.apache.activemq.jms.example;
import org.jboss.netty.channel.ChannelPipeline;
import org.jboss.netty.channel.ChannelPipelineFactory;
import org.jboss.netty.channel.Channels;
import org.jboss.netty.handler.codec.http.HttpRequestDecoder;
import org.jboss.netty.handler.codec.http.HttpResponseEncoder;
import org.jboss.netty.handler.stream.ChunkedWriteHandler;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.ChannelPipelineFactory;
import io.netty.channel.Channels;
import io.netty.handler.codec.http.HttpRequestDecoder;
import io.netty.handler.codec.http.HttpResponseEncoder;
import io.netty.handler.stream.ChunkedWriteHandler;
/**
* A HttpStaticFileServerPipelineFactory

View File

@ -9,13 +9,6 @@
<large-messages-directory>${build.directory}/server0/data/messaging/largemessages</large-messages-directory>
<paging-directory>${build.directory}/server0/data/messaging/paging</paging-directory>
<!-- Connectors -->
<connectors>
<connector name="netty-connector">
<factory-class>org.apache.activemq.core.remoting.impl.netty.NettyConnectorFactory</factory-class>
</connector>
</connectors>
<!-- Acceptors -->
<acceptors>

View File

@ -36,7 +36,7 @@
<goal>start</goal>
</goals>
<configuration>
<hornetqConfigurationDir>${basedir}/target/classes/activemq/server0</hornetqConfigurationDir>
<configurationDir>${basedir}/target/classes/activemq/server0</configurationDir>
</configuration>
</execution>
<execution>
@ -45,10 +45,8 @@
<goal>start</goal>
</goals>
<configuration>
<jndiPort>1199</jndiPort>
<jndiRmiPort>1198</jndiRmiPort>
<hornetqConfigurationDir>${basedir}/target/classes/activemq/server1</hornetqConfigurationDir>
<serverStartString>INFO: HQ221034</serverStartString>
<configurationDir>${basedir}/target/classes/activemq/server1</configurationDir>
<serverStartString>INFO: AMQ221001</serverStartString>
<fork>true</fork>
</configuration>
</execution>
@ -77,7 +75,7 @@
<goal>stop</goal>
</goals>
<configuration>
<hornetqConfigurationDir>${basedir}/target/classes/activemq/server0</hornetqConfigurationDir>
<configurationDir>${basedir}/target/classes/activemq/server0</configurationDir>
</configuration>
</execution>
<execution>
@ -86,7 +84,7 @@
<goal>stop</goal>
</goals>
<configuration>
<hornetqConfigurationDir>${basedir}/target/classes/activemq/server1</hornetqConfigurationDir>
<configurationDir>${basedir}/target/classes/activemq/server1</configurationDir>
</configuration>
</execution>
</executions>
@ -129,7 +127,7 @@
</dependencies>
<configuration>
<waitOnStart>false</waitOnStart>
<hornetqConfigurationDir>${basedir}/target/classes/activemq/server0</hornetqConfigurationDir>
<configurationDir>${basedir}/target/classes/activemq/server0</configurationDir>
</configuration>
</plugin>
</plugins>

View File

@ -16,6 +16,9 @@
*/
package org.apache.activemq.jms.example;
import java.lang.Object;
import java.lang.String;
import java.util.Hashtable;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
@ -149,7 +152,11 @@ public class ApplicationLayerFailoverExample extends ActiveMQExample
private void createJMSObjects(final int server) throws Exception
{
// Step 1. Get an initial context for looking up JNDI from the server
initialContext = getContext(server);
Hashtable<String, Object> properties = new Hashtable<String, Object>();
properties.put("java.naming.factory.initial", "org.apache.activemq.jndi.ActiveMQInitialContextFactory");
properties.put("java.naming.provider.url", "tcp://127.0.0.1:" + (5445 + server));
properties.put("queue.queue/exampleQueue", "exampleQueue");
initialContext = new InitialContext(properties);
// Step 2. Look-up the JMS Queue object from JNDI
Queue queue = (Queue)initialContext.lookup("queue/exampleQueue");

View File

@ -2,16 +2,7 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="urn:activemq /schema/activemq-configuration.xsd">
<!-- Connectors -->
<connectors>
<connector name="netty-connector">
<factory-class>org.apache.activemq.core.remoting.impl.netty.NettyConnectorFactory</factory-class>
<param key="port" value="5445"/>
</connector>
</connectors>
<!-- Acceptors -->
<acceptors>
<acceptor name="netty-acceptor">
<factory-class>org.apache.activemq.core.remoting.impl.netty.NettyAcceptorFactory</factory-class>

View File

@ -3,15 +3,6 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="urn:activemq /schema/activemq-configuration.xsd">
<!-- Connectors -->
<connectors>
<connector name="netty-connector">
<factory-class>org.apache.activemq.core.remoting.impl.netty.NettyConnectorFactory</factory-class>
<param key="port" value="5446"/>
</connector>
</connectors>
<!-- Acceptors -->
<acceptors>
<acceptor name="netty-acceptor">

View File

@ -41,7 +41,7 @@
<goal>start</goal>
</goals>
<configuration>
<hornetqConfigurationDir>${basedir}/target/classes/activemq/server0</hornetqConfigurationDir>
<configurationDir>${basedir}/target/classes/activemq/server0</configurationDir>
</configuration>
</execution>
<execution>
@ -52,7 +52,7 @@
<configuration>
<jndiPort>1199</jndiPort>
<jndiRmiPort>1198</jndiRmiPort>
<hornetqConfigurationDir>${basedir}/target/classes/activemq/server1</hornetqConfigurationDir>
<configurationDir>${basedir}/target/classes/activemq/server1</configurationDir>
<fork>true</fork>
</configuration>
</execution>
@ -81,7 +81,7 @@
<goal>stop</goal>
</goals>
<configuration>
<hornetqConfigurationDir>${basedir}/target/classes/activemq/server0</hornetqConfigurationDir>
<configurationDir>${basedir}/target/classes/activemq/server0</configurationDir>
</configuration>
</execution>
<execution>
@ -90,7 +90,7 @@
<goal>stop</goal>
</goals>
<configuration>
<hornetqConfigurationDir>${basedir}/target/classes/activemq/server1</hornetqConfigurationDir>
<configurationDir>${basedir}/target/classes/activemq/server1</configurationDir>
</configuration>
</execution>
</executions>

View File

@ -16,6 +16,8 @@
*/
package org.apache.activemq.jms.example;
import java.util.Hashtable;
import javax.jms.Connection;
import javax.jms.ConnectionFactory;
import javax.jms.Message;
@ -55,11 +57,15 @@ public class BridgeExample extends ActiveMQExample
{
// Step 1 - we create an initial context for looking up JNDI on node 0
ic0 = getContext(0);
Hashtable<String, Object> properties = new Hashtable<String, Object>();
properties.put("java.naming.factory.initial", "org.apache.activemq.jndi.ActiveMQInitialContextFactory");
properties.put("java.naming.provider.url", "tcp://127.0.0.1:5445");
properties.put("queue.queue/sausage-factory", "sausage-factory");
ic0 = new InitialContext(properties);
// Step 2 - we look up the sausage-factory queue from node 0
Queue sausageFactory = (Queue)ic0.lookup("queue/exampleQueue");
Queue sausageFactory = (Queue)ic0.lookup("queue/sausage-factory");
// Step 3 - we look up a JMS ConnectionFactory object from node 0
@ -67,11 +73,15 @@ public class BridgeExample extends ActiveMQExample
// Step 4 - we create an initial context for looking up JNDI on node 1
ic1 = getContext(1);
properties = new Hashtable<String, Object>();
properties.put("java.naming.factory.initial", "org.apache.activemq.jndi.ActiveMQInitialContextFactory");
properties.put("java.naming.provider.url", "tcp://127.0.0.1:5446");
properties.put("queue.queue/mincing-machine", "mincing-machine");
ic1 = new InitialContext(properties);
// Step 5 - we look up the mincing-machine queue on node 1
Queue mincingMachine = (Queue)ic1.lookup("queue/exampleQueue1");
Queue mincingMachine = (Queue)ic1.lookup("queue/mincing-machine");
// Step 6 - we look up a JMS ConnectionFactory object from node 1

View File

@ -12,11 +12,6 @@
<!-- Connectors -->
<connectors>
<connector name="netty-connector">
<factory-class>org.apache.activemq.core.remoting.impl.netty.NettyConnectorFactory</factory-class>
<param key="port" value="5445"/>
</connector>
<!-- Connector to the other node -->
<connector name="remote-connector">
<factory-class>org.apache.activemq.core.remoting.impl.netty.NettyConnectorFactory</factory-class>

View File

@ -9,15 +9,6 @@
<large-messages-directory>${build.directory}/server1/data/messaging/largemessages</large-messages-directory>
<paging-directory>${build.directory}/server1/data/messaging/paging</paging-directory>
<!-- Connectors -->
<connectors>
<connector name="netty-connector">
<factory-class>org.apache.activemq.core.remoting.impl.netty.NettyConnectorFactory</factory-class>
<param key="port" value="5446"/>
</connector>
</connectors>
<!-- Acceptors -->
<acceptors>

View File

@ -94,7 +94,7 @@
</dependencies>
<configuration>
<waitOnStart>false</waitOnStart>
<hornetqConfigurationDir>${basedir}/target/classes/activemq/server0</hornetqConfigurationDir>
<configurationDir>${basedir}/target/classes/activemq/server0</configurationDir>
<systemProperties>
<property>
<name>build.directory</name>

View File

@ -52,7 +52,7 @@ public class QueueBrowserExample extends ActiveMQExample
try
{
// Step 1. Create an initial context to perform the JNDI lookup.
initialContext = getContext(0);
initialContext = new InitialContext();
// Step 2. Perfom a lookup on the queue
Queue queue = (Queue)initialContext.lookup("queue/exampleQueue");

View File

@ -9,14 +9,6 @@
<large-messages-directory>${build.directory}/server0/data/messaging/largemessages</large-messages-directory>
<paging-directory>${build.directory}/server0/data/messaging/paging</paging-directory>
<!-- Connectors -->
<connectors>
<connector name="netty-connector">
<factory-class>org.apache.activemq.core.remoting.impl.netty.NettyConnectorFactory</factory-class>
</connector>
</connectors>
<!-- Acceptors -->
<acceptors>

View File

@ -1,2 +1,3 @@
java.naming.factory.initial=org.apache.activemq.jndi.ActiveMQInitialContextFactory
java.naming.provider.url=tcp://localhost:5445
java.naming.provider.url=tcp://localhost:5445
queue.queue/exampleQueue=exampleQueue

View File

@ -125,7 +125,7 @@
</dependencies>
<configuration>
<waitOnStart>false</waitOnStart>
<hornetqConfigurationDir>${basedir}/target/classes/activemq/server0</hornetqConfigurationDir>
<configurationDir>${basedir}/target/classes/activemq/server0</configurationDir>
</configuration>
</plugin>
</plugins>

View File

@ -57,7 +57,7 @@ public class ClientKickoffExample extends ActiveMQExample
try
{
// Step 1. Create an initial context to perform the JNDI lookup.
initialContext = getContext(0);
initialContext = new InitialContext();
// Step 2. Perform a lookup on the Connection Factory
QueueConnectionFactory cf = (QueueConnectionFactory)initialContext.lookup("ConnectionFactory");

View File

@ -12,13 +12,6 @@
<!-- true to expose ActiveMQ resources through JMX -->
<jmx-management-enabled>true</jmx-management-enabled>
<!-- Connectors -->
<connectors>
<connector name="netty">
<factory-class>org.apache.activemq.core.remoting.impl.netty.NettyConnectorFactory</factory-class>
</connector>
</connectors>
<!-- Acceptors -->
<acceptors>

View File

@ -36,7 +36,7 @@
<goal>start</goal>
</goals>
<configuration>
<hornetqConfigurationDir>${basedir}/target/classes/activemq/server0</hornetqConfigurationDir>
<configurationDir>${basedir}/target/classes/activemq/server0</configurationDir>
<systemProperties>
<property>
<name>build.directory</name>
@ -55,9 +55,7 @@
<goal>start</goal>
</goals>
<configuration>
<jndiPort>1199</jndiPort>
<jndiRmiPort>1198</jndiRmiPort>
<hornetqConfigurationDir>${basedir}/target/classes/activemq/server1</hornetqConfigurationDir>
<configurationDir>${basedir}/target/classes/activemq/server1</configurationDir>
<fork>true</fork>
<systemProperties>
<property>
@ -79,10 +77,6 @@
</goals>
<configuration>
<clientClass>org.apache.activemq.jms.example.ClientSideFailoverListerExample</clientClass>
<args>
<param>tcp://localhost:5445</param>
<param>tcp://localhost:5446</param>
</args>
<systemProperties>
<property>
<name>exampleConfigDir</name>
@ -97,7 +91,7 @@
<goal>stop</goal>
</goals>
<configuration>
<hornetqConfigurationDir>${basedir}/target/classes/activemq/server0</hornetqConfigurationDir>
<configurationDir>${basedir}/target/classes/activemq/server0</configurationDir>
</configuration>
</execution>
<execution>
@ -106,7 +100,7 @@
<goal>stop</goal>
</goals>
<configuration>
<hornetqConfigurationDir>${basedir}/target/classes/activemq/server1</hornetqConfigurationDir>
<configurationDir>${basedir}/target/classes/activemq/server1</configurationDir>
</configuration>
</execution>
</executions>

View File

@ -11,7 +11,7 @@
<p>This example demonstrates how you can listen on failover event on the client side.</p>
<p>In this example there are two nodes running in a cluster, both server will be running for start,
but after a while the first server will crash. This will trigger an fail oever event.</p>
but after a while the first server will crash. This will trigger an fail-over event.</p>
<h2>Example step-by-step</h2>
<p><em>To run the example, simply type <code>mvn verify</code> from this directory</em></p>

View File

@ -55,7 +55,7 @@ public class ClientSideFailoverListerExample extends ActiveMQExample
try
{
// Step 1. Get an initial context for looking up JNDI from server 0
initialContext = getContext(0);
initialContext = new InitialContext();
// Step 2. Look-up the JMS Queue object from JNDI
Queue queue = (Queue)initialContext.lookup("queue/exampleQueue");

View File

@ -0,0 +1,7 @@
java.naming.factory.initial=org.apache.activemq.jndi.ActiveMQInitialContextFactory
java.naming.provider.url=tcp://localhost:5445
queue.queue/exampleQueue=exampleQueue
connection.ConnectionFactory.ha=true
connection.ConnectionFactory.retryInterval=1000
connection.ConnectionFactory.retryIntervalMultiplier=1.0
connection.ConnectionFactory.reconnectAttempts=-1

View File

@ -36,16 +36,12 @@
<goal>start</goal>
</goals>
<configuration>
<hornetqConfigurationDir>${basedir}/target/classes/activemq/server0</hornetqConfigurationDir>
<configurationDir>${basedir}/target/classes/activemq/server0</configurationDir>
<systemProperties>
<property>
<name>build.directory</name>
<value>${basedir}/target/</value>
</property>
<property>
<name>udp-address</name>
<value>${udp-address}</value>
</property>
</systemProperties>
</configuration>
</execution>
@ -55,9 +51,7 @@
<goal>start</goal>
</goals>
<configuration>
<jndiPort>1199</jndiPort>
<jndiRmiPort>1198</jndiRmiPort>
<hornetqConfigurationDir>${basedir}/target/classes/activemq/server1</hornetqConfigurationDir>
<configurationDir>${basedir}/target/classes/activemq/server1</configurationDir>
<fork>true</fork>
<systemProperties>
<property>
@ -77,19 +71,13 @@
<goal>start</goal>
</goals>
<configuration>
<jndiPort>1299</jndiPort>
<jndiRmiPort>1298</jndiRmiPort>
<hornetqConfigurationDir>${basedir}/target/classes/activemq/server2</hornetqConfigurationDir>
<configurationDir>${basedir}/target/classes/activemq/server2</configurationDir>
<fork>true</fork>
<systemProperties>
<property>
<name>build.directory</name>
<value>${basedir}/target/</value>
</property>
<property>
<name>udp-address</name>
<value>${udp-address}</value>
</property>
</systemProperties>
</configuration>
</execution>
@ -100,10 +88,6 @@
</goals>
<configuration>
<clientClass>org.apache.activemq.jms.example.ClientSideLoadBalancingExample</clientClass>
<args>
<param>tcp://localhost:5445</param>
<param>tcp://localhost:5446</param>
</args>
<systemProperties>
<property>
<name>exampleConfigDir</name>
@ -118,7 +102,7 @@
<goal>stop</goal>
</goals>
<configuration>
<hornetqConfigurationDir>${basedir}/target/classes/activemq/server0</hornetqConfigurationDir>
<configurationDir>${basedir}/target/classes/activemq/server0</configurationDir>
</configuration>
</execution>
<execution>
@ -127,7 +111,7 @@
<goal>stop</goal>
</goals>
<configuration>
<hornetqConfigurationDir>${basedir}/target/classes/activemq/server1</hornetqConfigurationDir>
<configurationDir>${basedir}/target/classes/activemq/server1</configurationDir>
</configuration>
</execution>
<execution>
@ -136,7 +120,7 @@
<goal>stop</goal>
</goals>
<configuration>
<hornetqConfigurationDir>${basedir}/target/classes/activemq/server2</hornetqConfigurationDir>
<configurationDir>${basedir}/target/classes/activemq/server2</configurationDir>
</configuration>
</execution>
</executions>

View File

@ -56,7 +56,7 @@ public class ClientSideLoadBalancingExample extends ActiveMQExample
try
{
// Step 1. Get an initial context for looking up JNDI from server 0
initialContext = getContext(0);
initialContext = new InitialContext();
// Step 2. Look-up the JMS Queue object from JNDI
Queue queue = (Queue)initialContext.lookup("queue/exampleQueue");

View File

@ -1,2 +1,3 @@
java.naming.factory.initial=org.apache.activemq.jndi.ActiveMQInitialContextFactory
java.naming.provider.url=tcp://localhost:5445
java.naming.provider.url=udp://231.7.7.7:9876
queue.queue/exampleQueue=exampleQueue

View File

@ -36,16 +36,12 @@
<goal>start</goal>
</goals>
<configuration>
<hornetqConfigurationDir>${basedir}/target/classes/activemq/server0</hornetqConfigurationDir>
<configurationDir>${basedir}/target/classes/activemq/server0</configurationDir>
<systemProperties>
<property>
<name>build.directory</name>
<value>${basedir}/target/</value>
</property>
<property>
<name>udp-address</name>
<value>${udp-address}</value>
</property>
</systemProperties>
</configuration>
</execution>
@ -55,19 +51,13 @@
<goal>start</goal>
</goals>
<configuration>
<jndiPort>1199</jndiPort>
<jndiRmiPort>1198</jndiRmiPort>
<hornetqConfigurationDir>${basedir}/target/classes/activemq/server1</hornetqConfigurationDir>
<configurationDir>${basedir}/target/classes/activemq/server1</configurationDir>
<fork>true</fork>
<systemProperties>
<property>
<name>build.directory</name>
<value>${basedir}/target/</value>
</property>
<property>
<name>udp-address</name>
<value>${udp-address}</value>
</property>
</systemProperties>
</configuration>
</execution>
@ -96,7 +86,7 @@
<goal>stop</goal>
</goals>
<configuration>
<hornetqConfigurationDir>${basedir}/target/classes/activemq/server0</hornetqConfigurationDir>
<configurationDir>${basedir}/target/classes/activemq/server0</configurationDir>
</configuration>
</execution>
<execution>
@ -105,7 +95,7 @@
<goal>stop</goal>
</goals>
<configuration>
<hornetqConfigurationDir>${basedir}/target/classes/activemq/server1</hornetqConfigurationDir>
<configurationDir>${basedir}/target/classes/activemq/server1</configurationDir>
</configuration>
</execution>
</executions>

View File

@ -16,6 +16,8 @@
*/
package org.apache.activemq.jms.example;
import java.util.Hashtable;
import javax.jms.Connection;
import javax.jms.ConnectionFactory;
import javax.jms.MessageConsumer;
@ -56,7 +58,11 @@ public class ClusteredDurableSubscriptionExample extends ActiveMQExample
try
{
// Step 1. Get an initial context for looking up JNDI from server 0
ic0 = getContext(0);
Hashtable<String, Object> properties = new Hashtable<String, Object>();
properties.put("java.naming.factory.initial", "org.apache.activemq.jndi.ActiveMQInitialContextFactory");
properties.put("java.naming.provider.url", args[0]);
properties.put("topic.topic/exampleTopic", "exampleTopic");
ic0 = new InitialContext(properties);
// Step 2. Look-up the JMS Topic object from JNDI
Topic topic = (Topic)ic0.lookup("topic/exampleTopic");
@ -65,7 +71,11 @@ public class ClusteredDurableSubscriptionExample extends ActiveMQExample
ConnectionFactory cf0 = (ConnectionFactory)ic0.lookup("ConnectionFactory");
// Step 4. Get an initial context for looking up JNDI from server 1
ic1 = getContext(1);
properties = new Hashtable<String, Object>();
properties.put("java.naming.factory.initial", "org.apache.activemq.jndi.ActiveMQInitialContextFactory");
properties.put("java.naming.provider.url", args[1]);
ic1 = new InitialContext(properties);
// Step 5. Look-up a JMS Connection Factory object from JNDI on server 1
ConnectionFactory cf1 = (ConnectionFactory)ic1.lookup("ConnectionFactory");

View File

@ -36,7 +36,7 @@
<goal>start</goal>
</goals>
<configuration>
<hornetqConfigurationDir>${basedir}/target/classes/activemq/server0</hornetqConfigurationDir>
<configurationDir>${basedir}/target/classes/activemq/server0</configurationDir>
<systemProperties>
<property>
<name>build.directory</name>
@ -55,9 +55,7 @@
<goal>start</goal>
</goals>
<configuration>
<jndiPort>1199</jndiPort>
<jndiRmiPort>1198</jndiRmiPort>
<hornetqConfigurationDir>${basedir}/target/classes/activemq/server1</hornetqConfigurationDir>
<configurationDir>${basedir}/target/classes/activemq/server1</configurationDir>
<fork>true</fork>
<systemProperties>
<property>
@ -77,9 +75,7 @@
<goal>start</goal>
</goals>
<configuration>
<jndiPort>1299</jndiPort>
<jndiRmiPort>1298</jndiRmiPort>
<hornetqConfigurationDir>${basedir}/target/classes/activemq/server2</hornetqConfigurationDir>
<configurationDir>${basedir}/target/classes/activemq/server2</configurationDir>
<fork>true</fork>
<systemProperties>
<property>
@ -119,7 +115,7 @@
<goal>stop</goal>
</goals>
<configuration>
<hornetqConfigurationDir>${basedir}/target/classes/activemq/server0</hornetqConfigurationDir>
<configurationDir>${basedir}/target/classes/activemq/server0</configurationDir>
</configuration>
</execution>
<execution>
@ -128,7 +124,7 @@
<goal>stop</goal>
</goals>
<configuration>
<hornetqConfigurationDir>${basedir}/target/classes/activemq/server1</hornetqConfigurationDir>
<configurationDir>${basedir}/target/classes/activemq/server1</configurationDir>
</configuration>
</execution>
<execution>
@ -137,7 +133,7 @@
<goal>stop</goal>
</goals>
<configuration>
<hornetqConfigurationDir>${basedir}/target/classes/activemq/server2</hornetqConfigurationDir>
<configurationDir>${basedir}/target/classes/activemq/server2</configurationDir>
</configuration>
</execution>
</executions>

View File

@ -16,6 +16,8 @@
*/
package org.apache.activemq.jms.example;
import java.util.Hashtable;
import javax.jms.Connection;
import javax.jms.ConnectionFactory;
import javax.jms.MessageConsumer;
@ -58,7 +60,11 @@ public class ClusteredGroupingExample extends ActiveMQExample
try
{
// Step 1. Get an initial context for looking up JNDI from server 0
ic0 = getContext(0);
Hashtable<String, Object> properties = new Hashtable<String, Object>();
properties.put("java.naming.factory.initial", "org.apache.activemq.jndi.ActiveMQInitialContextFactory");
properties.put("java.naming.provider.url", args[0]);
properties.put("queue.queue/exampleQueue", "exampleQueue");
ic0 = new InitialContext(properties);
// Step 2. Look-up the JMS Queue object from JNDI
Queue queue = (Queue)ic0.lookup("queue/exampleQueue");
@ -67,15 +73,21 @@ public class ClusteredGroupingExample extends ActiveMQExample
ConnectionFactory cf0 = (ConnectionFactory)ic0.lookup("ConnectionFactory");
// Step 4. Get an initial context for looking up JNDI from server 1
ic1 = getContext(1);
properties = new Hashtable<String, Object>();
properties.put("java.naming.factory.initial", "org.apache.activemq.jndi.ActiveMQInitialContextFactory");
properties.put("java.naming.provider.url", args[1]);
ic1 = new InitialContext(properties);
// Step 5. Look-up a JMS Connection Factory object from JNDI on server 1
ConnectionFactory cf1 = (ConnectionFactory)ic1.lookup("ConnectionFactory");
// Step 4. Get an initial context for looking up JNDI from server 1
ic2 = getContext(2);
// Step 4. Get an initial context for looking up JNDI from server 2
properties = new Hashtable<String, Object>();
properties.put("java.naming.factory.initial", "org.apache.activemq.jndi.ActiveMQInitialContextFactory");
properties.put("java.naming.provider.url", args[2]);
ic2 = new InitialContext(properties);
// Step 5. Look-up a JMS Connection Factory object from JNDI on server 1
// Step 5. Look-up a JMS Connection Factory object from JNDI on server 2
ConnectionFactory cf2 = (ConnectionFactory)ic2.lookup("ConnectionFactory");
// Step 6. We create a JMS Connection connection0 which is a connection to server 0
@ -93,7 +105,7 @@ public class ClusteredGroupingExample extends ActiveMQExample
// Step 10. We create a JMS Session on server 1
Session session1 = connection1.createSession(false, Session.AUTO_ACKNOWLEDGE);
// Step 11. We create a JMS Session on server 1
// Step 11. We create a JMS Session on server 2
Session session2 = connection1.createSession(false, Session.AUTO_ACKNOWLEDGE);
// Step 12. We start the connections to ensure delivery occurs on them
@ -200,5 +212,4 @@ public class ClusteredGroupingExample extends ActiveMQExample
}
}
}
}

View File

@ -36,7 +36,7 @@
<goal>start</goal>
</goals>
<configuration>
<hornetqConfigurationDir>${basedir}/target/classes/activemq/server0</hornetqConfigurationDir>
<configurationDir>${basedir}/target/classes/activemq/server0</configurationDir>
<systemProperties>
<!-- this is to make sure the example will run fine on any box.
you may tweak this to any property you like. More information on the JGroups docs -->
@ -53,9 +53,7 @@
<goal>start</goal>
</goals>
<configuration>
<jndiPort>1199</jndiPort>
<jndiRmiPort>1198</jndiRmiPort>
<hornetqConfigurationDir>${basedir}/target/classes/activemq/server1</hornetqConfigurationDir>
<configurationDir>${basedir}/target/classes/activemq/server1</configurationDir>
<fork>true</fork>
<systemProperties>
<!-- this is to make sure the example will run fine on any box.
@ -86,7 +84,7 @@
<goal>stop</goal>
</goals>
<configuration>
<hornetqConfigurationDir>${basedir}/target/classes/activemq/server0</hornetqConfigurationDir>
<configurationDir>${basedir}/target/classes/activemq/server0</configurationDir>
</configuration>
</execution>
<execution>
@ -95,7 +93,7 @@
<goal>stop</goal>
</goals>
<configuration>
<hornetqConfigurationDir>${basedir}/target/classes/activemq/server1</hornetqConfigurationDir>
<configurationDir>${basedir}/target/classes/activemq/server1</configurationDir>
</configuration>
</execution>
</executions>

Some files were not shown because too many files have changed in this diff Show More