JBoss hornetq SVN: r9638 - branches/Branch_2_1/examples/soak/tx-restarts/src/org/hornetq/jms/example.
by do-not-reply@jboss.org
Author: clebert.suconic(a)jboss.com
Date: 2010-09-02 23:40:15 -0400 (Thu, 02 Sep 2010)
New Revision: 9638
Modified:
branches/Branch_2_1/examples/soak/tx-restarts/src/org/hornetq/jms/example/Receiver.java
Log:
tweak
Modified: branches/Branch_2_1/examples/soak/tx-restarts/src/org/hornetq/jms/example/Receiver.java
===================================================================
--- branches/Branch_2_1/examples/soak/tx-restarts/src/org/hornetq/jms/example/Receiver.java 2010-09-03 03:36:41 UTC (rev 9637)
+++ branches/Branch_2_1/examples/soak/tx-restarts/src/org/hornetq/jms/example/Receiver.java 2010-09-03 03:40:15 UTC (rev 9638)
@@ -153,7 +153,7 @@
sem.release(pendingMsgs2);
try
{
- max.acquire(pendingMsgs2);
+ max.tryAcquire(pendingMsgs2, 5, TimeUnit.SECONDS);
}
catch (InterruptedException e)
{
14 years, 3 months
JBoss hornetq SVN: r9637 - branches/Branch_2_1/examples/soak/tx-restarts/src/org/hornetq/jms/example.
by do-not-reply@jboss.org
Author: clebert.suconic(a)jboss.com
Date: 2010-09-02 23:36:41 -0400 (Thu, 02 Sep 2010)
New Revision: 9637
Modified:
branches/Branch_2_1/examples/soak/tx-restarts/src/org/hornetq/jms/example/Receiver.java
Log:
tweak
Modified: branches/Branch_2_1/examples/soak/tx-restarts/src/org/hornetq/jms/example/Receiver.java
===================================================================
--- branches/Branch_2_1/examples/soak/tx-restarts/src/org/hornetq/jms/example/Receiver.java 2010-09-03 03:15:25 UTC (rev 9636)
+++ branches/Branch_2_1/examples/soak/tx-restarts/src/org/hornetq/jms/example/Receiver.java 2010-09-03 03:36:41 UTC (rev 9637)
@@ -38,6 +38,8 @@
private final Semaphore sem = new Semaphore(0);
+ private final Semaphore max = new Semaphore(10000);
+
private final String queueJNDI;
protected volatile long msgs = 0;
@@ -75,6 +77,7 @@
{
break;
}
+ max.release();
Message msg = cons.receive(5000);
if (msg == null)
{
@@ -148,6 +151,14 @@
public void messageProduced(int pendingMsgs2)
{
sem.release(pendingMsgs2);
+ try
+ {
+ max.acquire(pendingMsgs2);
+ }
+ catch (InterruptedException e)
+ {
+ e.printStackTrace();
+ }
}
// Package protected ---------------------------------------------
14 years, 3 months
JBoss hornetq SVN: r9636 - branches/Branch_2_1/examples/soak/tx-restarts/src/org/hornetq/jms/example.
by do-not-reply@jboss.org
Author: clebert.suconic(a)jboss.com
Date: 2010-09-02 23:15:25 -0400 (Thu, 02 Sep 2010)
New Revision: 9636
Modified:
branches/Branch_2_1/examples/soak/tx-restarts/src/org/hornetq/jms/example/Receiver.java
branches/Branch_2_1/examples/soak/tx-restarts/src/org/hornetq/jms/example/Sender.java
branches/Branch_2_1/examples/soak/tx-restarts/src/org/hornetq/jms/example/TXRestartSoak.java
Log:
tweak on soak test
Modified: branches/Branch_2_1/examples/soak/tx-restarts/src/org/hornetq/jms/example/Receiver.java
===================================================================
--- branches/Branch_2_1/examples/soak/tx-restarts/src/org/hornetq/jms/example/Receiver.java 2010-09-03 02:07:52 UTC (rev 9635)
+++ branches/Branch_2_1/examples/soak/tx-restarts/src/org/hornetq/jms/example/Receiver.java 2010-09-03 03:15:25 UTC (rev 9636)
@@ -13,6 +13,9 @@
package org.hornetq.jms.example;
+import java.util.concurrent.Semaphore;
+import java.util.concurrent.TimeUnit;
+
import javax.jms.Message;
import javax.jms.MessageConsumer;
import javax.jms.Queue;
@@ -33,6 +36,8 @@
private Queue queue;
+ private final Semaphore sem = new Semaphore(0);
+
private final String queueJNDI;
protected volatile long msgs = 0;
@@ -66,6 +71,10 @@
for (int i = 0 ; i < 1000; i++)
{
+ if (!sem.tryAcquire(1, 5, TimeUnit.SECONDS))
+ {
+ break;
+ }
Message msg = cons.receive(5000);
if (msg == null)
{
@@ -133,6 +142,14 @@
return "Receiver::" + this.queueJNDI + ", msgs=" + msgs + ", pending=" + pendingMsgs;
}
+ /**
+ * @param pendingMsgs2
+ */
+ public void messageProduced(int pendingMsgs2)
+ {
+ sem.release(pendingMsgs2);
+ }
+
// Package protected ---------------------------------------------
// Protected -----------------------------------------------------
Modified: branches/Branch_2_1/examples/soak/tx-restarts/src/org/hornetq/jms/example/Sender.java
===================================================================
--- branches/Branch_2_1/examples/soak/tx-restarts/src/org/hornetq/jms/example/Sender.java 2010-09-03 02:07:52 UTC (rev 9635)
+++ branches/Branch_2_1/examples/soak/tx-restarts/src/org/hornetq/jms/example/Sender.java 2010-09-03 03:15:25 UTC (rev 9636)
@@ -37,17 +37,20 @@
protected Queue queue;
protected long msgs = TXRestartSoak.MIN_MESSAGES_ON_QUEUE;
- protected long pendingMsgs = 0;
+ protected int pendingMsgs = 0;
+ protected final Receiver[] receivers;
+
// Static --------------------------------------------------------
// Constructors --------------------------------------------------
// Public --------------------------------------------------------
- public Sender()
+ public Sender(final Receiver[] receivers)
{
+ this.receivers = receivers;
}
@Override
@@ -90,6 +93,11 @@
protected void onCommit()
{
this.msgs += pendingMsgs;
+ for (Receiver rec : receivers)
+ {
+ rec.messageProduced(pendingMsgs);
+ }
+
pendingMsgs = 0;
System.out.println("commit on sender msgs = " + msgs );
}
Modified: branches/Branch_2_1/examples/soak/tx-restarts/src/org/hornetq/jms/example/TXRestartSoak.java
===================================================================
--- branches/Branch_2_1/examples/soak/tx-restarts/src/org/hornetq/jms/example/TXRestartSoak.java 2010-09-03 02:07:52 UTC (rev 9635)
+++ branches/Branch_2_1/examples/soak/tx-restarts/src/org/hornetq/jms/example/TXRestartSoak.java 2010-09-03 03:15:25 UTC (rev 9636)
@@ -104,13 +104,13 @@
session.commit();
- Sender send = new Sender();
+ Receiver rec1 = new Receiver("/queue/diverted1");
+ Receiver rec2 = new Receiver("/queue/diverted2");
+ Sender send = new Sender(new Receiver[]{rec1, rec2});
+
send.start();
-
- Receiver rec1 = new Receiver("/queue/diverted1");
rec1.start();
- Receiver rec2 = new Receiver("/queue/diverted2");
rec2.start();
14 years, 3 months
JBoss hornetq SVN: r9635 - branches/Branch_2_1/examples/common/src/org/hornetq/common/example.
by do-not-reply@jboss.org
Author: clebert.suconic(a)jboss.com
Date: 2010-09-02 22:07:52 -0400 (Thu, 02 Sep 2010)
New Revision: 9635
Modified:
branches/Branch_2_1/examples/common/src/org/hornetq/common/example/HornetQExample.java
Log:
tweaks
Modified: branches/Branch_2_1/examples/common/src/org/hornetq/common/example/HornetQExample.java
===================================================================
--- branches/Branch_2_1/examples/common/src/org/hornetq/common/example/HornetQExample.java 2010-09-03 02:05:02 UTC (rev 9634)
+++ branches/Branch_2_1/examples/common/src/org/hornetq/common/example/HornetQExample.java 2010-09-03 02:07:52 UTC (rev 9635)
@@ -17,8 +17,6 @@
import java.util.Properties;
import java.util.logging.Logger;
-import javax.jms.Connection;
-import javax.jms.JMSException;
import javax.naming.InitialContext;
/**
@@ -32,26 +30,26 @@
private Process[] servers;
- private Connection conn;
+ protected boolean failure = false;
- private boolean failure = false;
+ protected String serverClasspath;
- private String serverClasspath;
+ protected String serverProps;
- private String serverProps;
-
public abstract boolean runExample() throws Exception;
private boolean logServerOutput;
- private String[] configs;
+ protected String[] configs;
+
+ protected boolean runServer;
protected void run(final String[] configs)
{
String runServerProp = System.getProperty("hornetq.example.runServer");
String logServerOutputProp = System.getProperty("hornetq.example.logserveroutput");
serverClasspath = System.getProperty("hornetq.example.server.classpath");
- boolean runServer = runServerProp == null ? true : Boolean.valueOf(runServerProp);
+ runServer = runServerProp == null ? true : Boolean.valueOf(runServerProp);
logServerOutput = logServerOutputProp == null ? false : Boolean.valueOf(logServerOutputProp);
serverProps = System.getProperty("hornetq.example.server.args");
if (System.getProperty("hornetq.example.server.override.args") != null)
@@ -83,17 +81,6 @@
}
finally
{
- if (conn != null)
- {
- try
- {
- conn.close();
- }
- catch (JMSException e)
- {
- // ignore
- }
- }
if (runServer)
{
try
@@ -165,7 +152,7 @@
"hornetq-beans.xml");
}
- private void startServers() throws Exception
+ protected void startServers() throws Exception
{
servers = new Process[configs.length];
for (int i = 0; i < configs.length; i++)
@@ -174,7 +161,7 @@
}
}
- private void stopServers() throws Exception
+ protected void stopServers() throws Exception
{
for (Process server : servers)
{
@@ -185,7 +172,7 @@
}
}
- private void stopServer(final Process server) throws Exception
+ protected void stopServer(final Process server) throws Exception
{
if (!System.getProperty("os.name").contains("Windows") && !System.getProperty("os.name").contains("Mac OS X"))
{
14 years, 3 months
JBoss hornetq SVN: r9634 - in branches/Branch_2_1/examples/soak: tx-restarts and 6 other directories.
by do-not-reply@jboss.org
Author: clebert.suconic(a)jboss.com
Date: 2010-09-02 22:05:02 -0400 (Thu, 02 Sep 2010)
New Revision: 9634
Added:
branches/Branch_2_1/examples/soak/tx-restarts/
branches/Branch_2_1/examples/soak/tx-restarts/README
branches/Branch_2_1/examples/soak/tx-restarts/build.bat
branches/Branch_2_1/examples/soak/tx-restarts/build.sh
branches/Branch_2_1/examples/soak/tx-restarts/build.xml
branches/Branch_2_1/examples/soak/tx-restarts/server0/
branches/Branch_2_1/examples/soak/tx-restarts/server0/client-jndi.properties
branches/Branch_2_1/examples/soak/tx-restarts/server0/hornetq-beans.xml
branches/Branch_2_1/examples/soak/tx-restarts/server0/hornetq-configuration.xml
branches/Branch_2_1/examples/soak/tx-restarts/server0/hornetq-jms.xml
branches/Branch_2_1/examples/soak/tx-restarts/server0/hornetq-users.xml
branches/Branch_2_1/examples/soak/tx-restarts/server0/jndi.properties
branches/Branch_2_1/examples/soak/tx-restarts/src/
branches/Branch_2_1/examples/soak/tx-restarts/src/org/
branches/Branch_2_1/examples/soak/tx-restarts/src/org/hornetq/
branches/Branch_2_1/examples/soak/tx-restarts/src/org/hornetq/jms/
branches/Branch_2_1/examples/soak/tx-restarts/src/org/hornetq/jms/example/
branches/Branch_2_1/examples/soak/tx-restarts/src/org/hornetq/jms/example/ClientAbstract.java
branches/Branch_2_1/examples/soak/tx-restarts/src/org/hornetq/jms/example/Receiver.java
branches/Branch_2_1/examples/soak/tx-restarts/src/org/hornetq/jms/example/Sender.java
branches/Branch_2_1/examples/soak/tx-restarts/src/org/hornetq/jms/example/TXRestartSoak.java
Log:
Adding soak test to validate journal restart on transactions
Property changes on: branches/Branch_2_1/examples/soak/tx-restarts
___________________________________________________________________
Name: svn:ignore
+ build
Added: branches/Branch_2_1/examples/soak/tx-restarts/README
===================================================================
--- branches/Branch_2_1/examples/soak/tx-restarts/README (rev 0)
+++ branches/Branch_2_1/examples/soak/tx-restarts/README 2010-09-03 02:05:02 UTC (rev 9634)
@@ -0,0 +1,20 @@
+****************************************************
+* Soak Test For TX survival over restarts
+****************************************************
+
+Run The Test
+==============
+
+To run the test simply use ./build.sh
+
+It's important that you always clean the data directory before starting the test, as it will validate for sequences generated.
+
+The test will start and stop a server multiple times.
+
+
+Run the server remotely
+=======================
+
+You can start the server directly if you want, you can just start the server as:
+
+
Added: branches/Branch_2_1/examples/soak/tx-restarts/build.bat
===================================================================
--- branches/Branch_2_1/examples/soak/tx-restarts/build.bat (rev 0)
+++ branches/Branch_2_1/examples/soak/tx-restarts/build.bat 2010-09-03 02:05:02 UTC (rev 9634)
@@ -0,0 +1,13 @@
+@echo off
+
+set "OVERRIDE_ANT_HOME=..\..\..\tools\ant"
+
+if exist "..\..\..\src\bin\build.bat" (
+ rem running from TRUNK
+ call ..\..\..\src\bin\build.bat %*
+) else (
+ rem running from the distro
+ call ..\..\..\bin\build.bat %*
+)
+
+set "OVERRIDE_ANT_HOME="
Added: branches/Branch_2_1/examples/soak/tx-restarts/build.sh
===================================================================
--- branches/Branch_2_1/examples/soak/tx-restarts/build.sh (rev 0)
+++ branches/Branch_2_1/examples/soak/tx-restarts/build.sh 2010-09-03 02:05:02 UTC (rev 9634)
@@ -0,0 +1,15 @@
+#!/bin/sh
+
+OVERRIDE_ANT_HOME=../../../tools/ant
+export OVERRIDE_ANT_HOME
+
+if [ -f "../../../src/bin/build.sh" ]; then
+ # running from TRUNK
+ ../../../src/bin/build.sh "$@"
+else
+ # running from the distro
+ ../../../bin/build.sh "$@"
+fi
+
+
+
Property changes on: branches/Branch_2_1/examples/soak/tx-restarts/build.sh
___________________________________________________________________
Name: svn:executable
+ *
Added: branches/Branch_2_1/examples/soak/tx-restarts/build.xml
===================================================================
--- branches/Branch_2_1/examples/soak/tx-restarts/build.xml (rev 0)
+++ branches/Branch_2_1/examples/soak/tx-restarts/build.xml 2010-09-03 02:05:02 UTC (rev 9634)
@@ -0,0 +1,38 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE project [
+ <!ENTITY libraries SYSTEM "../../../thirdparty/libraries.ent">
+ ]>
+<!--
+ ~ Copyright 2009 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.
+ -->
+
+<project default="run" name="TX-Restarts soak test">
+
+ <import file="../../common/build.xml"/>
+ <property file="ant.properties"/>
+ <target name="run">
+ <antcall target="runExample">
+ <param name="example.classname" value="org.hornetq.jms.example.TXRestartSoak"/>
+
+ <param name="java-min-memory" value="1G"/>
+ <param name="java-max-memory" value="1G"/>
+ </antcall>
+ </target>
+
+ <target name="runRemote">
+ <antcall target="runExample">
+ <param name="example.classname" value="org.hornetq.jms.example.TXRestartSoak"/>
+ <param name="hornetq.example.runServer" value="false"/>
+ </antcall>
+ </target>
+
+</project>
Property changes on: branches/Branch_2_1/examples/soak/tx-restarts/server0
___________________________________________________________________
Name: svn:ignore
+ data
Added: branches/Branch_2_1/examples/soak/tx-restarts/server0/client-jndi.properties
===================================================================
--- branches/Branch_2_1/examples/soak/tx-restarts/server0/client-jndi.properties (rev 0)
+++ branches/Branch_2_1/examples/soak/tx-restarts/server0/client-jndi.properties 2010-09-03 02:05:02 UTC (rev 9634)
@@ -0,0 +1,3 @@
+java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
+java.naming.provider.url=jnp://localhost:1099
+java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces
Added: branches/Branch_2_1/examples/soak/tx-restarts/server0/hornetq-beans.xml
===================================================================
--- branches/Branch_2_1/examples/soak/tx-restarts/server0/hornetq-beans.xml (rev 0)
+++ branches/Branch_2_1/examples/soak/tx-restarts/server0/hornetq-beans.xml 2010-09-03 02:05:02 UTC (rev 9634)
@@ -0,0 +1,59 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<deployment xmlns="urn:jboss:bean-deployer:2.0">
+
+ <bean name="Naming" class="org.jnp.server.NamingBeanImpl"/>
+
+ <!-- JNDI server. Disable this if you don't want JNDI -->
+ <bean name="JNDIServer" class="org.jnp.server.Main">
+ <property name="namingInfo">
+ <inject bean="Naming"/>
+ </property>
+ <property name="port">1099</property>
+ <property name="bindAddress">localhost</property>
+ <property name="rmiPort">1098</property>
+ <property name="rmiBindAddress">localhost</property>
+ </bean>
+
+ <!-- MBean server -->
+ <bean name="MBeanServer" class="javax.management.MBeanServer">
+ <constructor factoryClass="java.lang.management.ManagementFactory"
+ factoryMethod="getPlatformMBeanServer"/>
+ </bean>
+
+ <!-- The core configuration -->
+ <bean name="Configuration" class="org.hornetq.core.config.impl.FileConfiguration"/>
+
+ <!-- The security manager -->
+ <bean name="HornetQSecurityManager" class="org.hornetq.spi.core.security.HornetQSecurityManagerImpl">
+ <start ignored="true"/>
+ <stop ignored="true"/>
+ </bean>
+
+ <!-- The core server -->
+ <bean name="HornetQServer" class="org.hornetq.core.server.impl.HornetQServerImpl">
+ <constructor>
+ <parameter>
+ <inject bean="Configuration"/>
+ </parameter>
+ <parameter>
+ <inject bean="MBeanServer"/>
+ </parameter>
+ <parameter>
+ <inject bean="HornetQSecurityManager"/>
+ </parameter>
+ </constructor>
+ <start ignored="true"/>
+ <stop ignored="true"/>
+ </bean>
+
+ <!-- The JMS server -->
+ <bean name="JMSServerManager" class="org.hornetq.jms.server.impl.JMSServerManagerImpl">
+ <constructor>
+ <parameter>
+ <inject bean="HornetQServer"/>
+ </parameter>
+ </constructor>
+ </bean>
+
+</deployment>
Added: branches/Branch_2_1/examples/soak/tx-restarts/server0/hornetq-configuration.xml
===================================================================
--- branches/Branch_2_1/examples/soak/tx-restarts/server0/hornetq-configuration.xml (rev 0)
+++ branches/Branch_2_1/examples/soak/tx-restarts/server0/hornetq-configuration.xml 2010-09-03 02:05:02 UTC (rev 9634)
@@ -0,0 +1,62 @@
+<configuration xmlns="urn:hornetq"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="urn:hornetq /schema/hornetq-configuration.xsd">
+
+ <!-- Connectors -->
+ <connectors>
+ <connector name="netty-connector">
+ <factory-class>org.hornetq.core.remoting.impl.netty.NettyConnectorFactory</factory-class>
+ </connector>
+ </connectors>
+
+ <!-- Acceptors -->
+ <acceptors>
+ <acceptor name="netty-acceptor">
+ <factory-class>org.hornetq.core.remoting.impl.netty.NettyAcceptorFactory</factory-class>
+ </acceptor>
+ </acceptors>
+
+ <address-settings>
+ <address-setting match="jms.queue.#">
+ <max-delivery-attempts>-1</max-delivery-attempts>
+ <!-- <max-size-bytes>335544320000</max-size-bytes> -->
+ <max-size-bytes>33554432</max-size-bytes>
+ <page-size-bytes>16777216</page-size-bytes>
+ <address-full-policy>PAGE</address-full-policy>
+ </address-setting>
+
+ </address-settings>
+
+
+ <diverts>
+ <divert name="div1">
+ <address>jms.queue.inputQueue</address>
+ <forwarding-address>jms.queue.diverted1</forwarding-address>
+ <exclusive>true</exclusive>
+ </divert>
+
+ <divert name="div2">
+ <address>jms.queue.inputQueue</address>
+ <forwarding-address>jms.queue.diverted2</forwarding-address>
+ <exclusive>true</exclusive>
+ </divert>
+ </diverts>
+
+
+
+
+ <!-- Other config -->
+
+ <security-settings>
+ <!--security for example queue-->
+ <security-setting match="jms.queue.#">
+ <permission type="createDurableQueue" roles="guest"/>
+ <permission type="deleteDurableQueue" roles="guest"/>
+ <permission type="createNonDurableQueue" roles="guest"/>
+ <permission type="deleteNonDurableQueue" roles="guest"/>
+ <permission type="consume" roles="guest"/>
+ <permission type="send" roles="guest"/>
+ </security-setting>
+ </security-settings>
+
+</configuration>
Added: branches/Branch_2_1/examples/soak/tx-restarts/server0/hornetq-jms.xml
===================================================================
--- branches/Branch_2_1/examples/soak/tx-restarts/server0/hornetq-jms.xml (rev 0)
+++ branches/Branch_2_1/examples/soak/tx-restarts/server0/hornetq-jms.xml 2010-09-03 02:05:02 UTC (rev 9634)
@@ -0,0 +1,27 @@
+<configuration xmlns="urn:hornetq"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="urn:hornetq /schema/hornetq-jms.xsd">
+ <!--the connection factory used by the example-->
+ <connection-factory name="ConnectionFactory">
+ <connectors>
+ <connector-ref connector-name="netty-connector"/>
+ </connectors>
+ <min-large-message-size>100240</min-large-message-size>
+ <entries>
+ <entry name="ConnectionFactory"/>
+ </entries>
+ </connection-factory>
+
+ <!--the queue used by the example-->
+ <queue name="inputQueue">
+ <entry name="/queue/inputQueue"/>
+ </queue>
+
+ <queue name="diverted1">
+ <entry name="/queue/diverted1"/>
+ </queue>
+
+ <queue name="diverted2">
+ <entry name="/queue/diverted2"/>
+ </queue>
+</configuration>
Added: branches/Branch_2_1/examples/soak/tx-restarts/server0/hornetq-users.xml
===================================================================
--- branches/Branch_2_1/examples/soak/tx-restarts/server0/hornetq-users.xml (rev 0)
+++ branches/Branch_2_1/examples/soak/tx-restarts/server0/hornetq-users.xml 2010-09-03 02:05:02 UTC (rev 9634)
@@ -0,0 +1,7 @@
+<configuration xmlns="urn:hornetq" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="urn:hornetq /schema/hornetq-users.xsd">
+ <!-- the default user. this is used where username is null-->
+ <defaultuser name="guest" password="guest">
+ <role name="guest"/>
+ </defaultuser>
+</configuration>
\ No newline at end of file
Added: branches/Branch_2_1/examples/soak/tx-restarts/server0/jndi.properties
===================================================================
--- branches/Branch_2_1/examples/soak/tx-restarts/server0/jndi.properties (rev 0)
+++ branches/Branch_2_1/examples/soak/tx-restarts/server0/jndi.properties 2010-09-03 02:05:02 UTC (rev 9634)
@@ -0,0 +1,2 @@
+java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
+java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces
\ No newline at end of file
Added: branches/Branch_2_1/examples/soak/tx-restarts/src/org/hornetq/jms/example/ClientAbstract.java
===================================================================
--- branches/Branch_2_1/examples/soak/tx-restarts/src/org/hornetq/jms/example/ClientAbstract.java (rev 0)
+++ branches/Branch_2_1/examples/soak/tx-restarts/src/org/hornetq/jms/example/ClientAbstract.java 2010-09-03 02:05:02 UTC (rev 9634)
@@ -0,0 +1,278 @@
+/*
+ * Copyright 2010 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.io.File;
+import java.io.FileInputStream;
+import java.util.Properties;
+import java.util.logging.Logger;
+
+import javax.jms.XAConnection;
+import javax.jms.XAConnectionFactory;
+import javax.jms.XASession;
+import javax.naming.InitialContext;
+import javax.transaction.xa.XAResource;
+import javax.transaction.xa.Xid;
+
+import org.hornetq.core.transaction.impl.XidImpl;
+import org.hornetq.utils.UUIDGenerator;
+
+/**
+ * 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:clebert.suconic@jboss.org">Clebert Suconic</a>
+ *
+ *
+ */
+public abstract class ClientAbstract extends Thread
+{
+
+ // Constants -----------------------------------------------------
+ private static final Logger log = Logger.getLogger(ClientAbstract.class.getName());
+
+ // Attributes ----------------------------------------------------
+
+ protected InitialContext ctx;
+
+ protected XAConnection conn;
+
+ protected XASession sess;
+
+ protected XAResource activeXAResource;
+
+ protected Xid activeXid;
+
+ protected volatile boolean running = true;
+
+ protected volatile int errors = 0;
+
+ /**
+ * A commit was called
+ * case we don't find the Xid, means it was accepted
+ */
+ protected volatile boolean pendingCommit = false;
+
+ // Static --------------------------------------------------------
+
+ // Constructors --------------------------------------------------
+
+ // Public --------------------------------------------------------
+
+ protected InitialContext getContext(final int serverId) throws Exception
+ {
+ String jndiFilename = "server" + serverId + "/client-jndi.properties";
+ File jndiFile = new File(jndiFilename);
+ Properties props = new Properties();
+ FileInputStream inStream = null;
+ try
+ {
+ inStream = new FileInputStream(jndiFile);
+ props.load(inStream);
+ }
+ finally
+ {
+ if (inStream != null)
+ {
+ inStream.close();
+ }
+ }
+ return new InitialContext(props);
+
+ }
+
+ public XAConnection getConnection()
+ {
+ return conn;
+ }
+
+ public int getErrorsCount()
+ {
+ return errors;
+ }
+
+ public final void connect()
+ {
+ while (running)
+ {
+ try
+ {
+ disconnect();
+
+ ctx = getContext(0);
+
+ XAConnectionFactory cf = (XAConnectionFactory)ctx.lookup("/ConnectionFactory");
+
+ conn = cf.createXAConnection();
+
+ sess = conn.createXASession();
+
+ activeXAResource = sess.getXAResource();
+
+ if (activeXid != null)
+ {
+ synchronized (ClientAbstract.class)
+ {
+ Xid[] xids = activeXAResource.recover(XAResource.TMSTARTRSCAN);
+ boolean found = false;
+ for (Xid recXid : xids)
+ {
+ if (recXid.equals(activeXid))
+ {
+ // System.out.println("Calling commit after a prepare on " + this);
+ found = true;
+ callCommit();
+ }
+ }
+
+ if (!found)
+ {
+ if (pendingCommit)
+ {
+ System.out.println("Doing a commit based on a pending commit on " + this);
+ onCommit();
+ }
+ else
+ {
+ System.out.println("Doing a rollback on " + this);
+ onRollback();
+ }
+
+ activeXid = null;
+ pendingCommit = false;
+ }
+ }
+ }
+
+ connectClients();
+
+ break;
+ }
+ catch (Exception e)
+ {
+ ClientAbstract.log.warning("Can't connect to server, retrying");
+ disconnect();
+ try
+ {
+ Thread.sleep(1000);
+ }
+ catch (InterruptedException ignored)
+ {
+ // if an interruption was sent, we will respect it and leave the loop
+ break;
+ }
+ }
+ }
+ }
+
+ @Override
+ public void run()
+ {
+ connect();
+ }
+
+ protected void callCommit() throws Exception
+ {
+ pendingCommit = true;
+ activeXAResource.commit(activeXid, false);
+ pendingCommit = false;
+ activeXid = null;
+ onCommit();
+ }
+
+ protected void callPrepare() throws Exception
+ {
+ activeXAResource.prepare(activeXid);
+ }
+
+ public void beginTX() throws Exception
+ {
+ activeXid = newXID();
+
+ activeXAResource.start(activeXid, XAResource.TMNOFLAGS);
+ }
+
+ public void endTX() throws Exception
+ {
+ activeXAResource.end(activeXid, XAResource.TMSUCCESS);
+ callPrepare();
+ callCommit();
+ }
+
+ public void setRunning(final boolean running)
+ {
+ this.running = running;
+ }
+
+ /**
+ * @return
+ */
+ private XidImpl newXID()
+ {
+ return new XidImpl("tst".getBytes(), 1, UUIDGenerator.getInstance().generateStringUUID().getBytes());
+ }
+
+ protected abstract void connectClients() throws Exception;
+
+ protected abstract void onCommit();
+
+ protected abstract void onRollback();
+
+ public void disconnect()
+ {
+ try
+ {
+ if (conn != null)
+ {
+ conn.close();
+ }
+ }
+ catch (Exception ignored)
+ {
+ ignored.printStackTrace();
+ }
+
+ try
+ {
+ if (ctx != null)
+ {
+ ctx.close();
+ }
+ }
+ catch (Exception ignored)
+ {
+ ignored.printStackTrace();
+ }
+
+ ctx = null;
+ conn = null;
+ // it's not necessary to close the session as conn.close() will already take care of that
+ sess = null;
+ }
+
+ // Package protected ---------------------------------------------
+
+ // Protected -----------------------------------------------------
+
+ // Private -------------------------------------------------------
+
+ // Inner classes -------------------------------------------------
+
+}
Added: branches/Branch_2_1/examples/soak/tx-restarts/src/org/hornetq/jms/example/Receiver.java
===================================================================
--- branches/Branch_2_1/examples/soak/tx-restarts/src/org/hornetq/jms/example/Receiver.java (rev 0)
+++ branches/Branch_2_1/examples/soak/tx-restarts/src/org/hornetq/jms/example/Receiver.java 2010-09-03 02:05:02 UTC (rev 9634)
@@ -0,0 +1,144 @@
+/*
+ * Copyright 2010 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.Message;
+import javax.jms.MessageConsumer;
+import javax.jms.Queue;
+
+/**
+ * A Receiver
+ *
+ * @author <a href="mailto:clebert.suconic@jboss.org">Clebert Suconic</a>
+ *
+ *
+ */
+public class Receiver extends ClientAbstract
+{
+
+ // Constants -----------------------------------------------------
+
+ // Attributes ----------------------------------------------------
+
+ private Queue queue;
+
+ private final String queueJNDI;
+
+ protected volatile long msgs = 0;
+
+ protected volatile long pendingMsgs = 0;
+
+ protected MessageConsumer cons;
+
+
+ // Static --------------------------------------------------------
+
+ // Constructors --------------------------------------------------
+
+ public Receiver(String queueJNDI)
+ {
+ super();
+ this.queueJNDI = queueJNDI;
+ }
+
+ // Public --------------------------------------------------------
+
+ public void run()
+ {
+ super.run();
+
+ while (running)
+ {
+ try
+ {
+ beginTX();
+
+ for (int i = 0 ; i < 1000; i++)
+ {
+ Message msg = cons.receive(5000);
+ if (msg == null)
+ {
+ break;
+ }
+
+ if (msg.getLongProperty("count") != msgs + pendingMsgs)
+ {
+ errors++;
+ System.out.println("count should be " + (msgs + pendingMsgs) + " when it was " + msg.getLongProperty("count") + " on " + queueJNDI);
+ }
+
+ pendingMsgs++;
+
+ }
+
+ endTX();
+ }
+ catch (Exception e)
+ {
+ connect();
+ }
+
+
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.hornetq.jms.example.ClientAbstract#connectClients()
+ */
+ @Override
+ protected void connectClients() throws Exception
+ {
+
+ queue = (Queue)ctx.lookup(queueJNDI);
+
+ cons = sess.createConsumer(queue);
+
+ conn.start();
+ }
+
+ /* (non-Javadoc)
+ * @see org.hornetq.jms.example.ClientAbstract#onCommit()
+ */
+ @Override
+ protected void onCommit()
+ {
+ msgs += pendingMsgs;
+ pendingMsgs = 0;
+ System.out.println("Commit on consumer " + queueJNDI + ", msgs=" + msgs);
+ }
+
+ /* (non-Javadoc)
+ * @see org.hornetq.jms.example.ClientAbstract#onRollback()
+ */
+ @Override
+ protected void onRollback()
+ {
+ System.out.println("Rollback on consumer " + queueJNDI + ", msgs=" + msgs);
+ pendingMsgs = 0;
+ }
+
+ public String toString()
+ {
+ return "Receiver::" + this.queueJNDI + ", msgs=" + msgs + ", pending=" + pendingMsgs;
+ }
+
+ // Package protected ---------------------------------------------
+
+ // Protected -----------------------------------------------------
+
+ // Private -------------------------------------------------------
+
+ // Inner classes -------------------------------------------------
+
+}
Added: branches/Branch_2_1/examples/soak/tx-restarts/src/org/hornetq/jms/example/Sender.java
===================================================================
--- branches/Branch_2_1/examples/soak/tx-restarts/src/org/hornetq/jms/example/Sender.java (rev 0)
+++ branches/Branch_2_1/examples/soak/tx-restarts/src/org/hornetq/jms/example/Sender.java 2010-09-03 02:05:02 UTC (rev 9634)
@@ -0,0 +1,121 @@
+/*
+ * Copyright 2010 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:clebert.suconic@jboss.org">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 long pendingMsgs = 0;
+
+
+ // Static --------------------------------------------------------
+
+ // Constructors --------------------------------------------------
+
+ // Public --------------------------------------------------------
+
+ public Sender()
+ {
+ }
+
+ @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;
+ 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 -------------------------------------------------
+
+}
Added: branches/Branch_2_1/examples/soak/tx-restarts/src/org/hornetq/jms/example/TXRestartSoak.java
===================================================================
--- branches/Branch_2_1/examples/soak/tx-restarts/src/org/hornetq/jms/example/TXRestartSoak.java (rev 0)
+++ branches/Branch_2_1/examples/soak/tx-restarts/src/org/hornetq/jms/example/TXRestartSoak.java 2010-09-03 02:05:02 UTC (rev 9634)
@@ -0,0 +1,175 @@
+/*
+ * Copyright 2009 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:clebert.suconic@jboss.org">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();
+
+ Sender send = new Sender();
+
+ send.start();
+
+ Receiver rec1 = new Receiver("/queue/diverted1");
+ rec1.start();
+ Receiver rec2 = new Receiver("/queue/diverted2");
+ rec2.start();
+
+
+ if (runServer)
+ {
+ long timeEnd = System.currentTimeMillis() + TimeUnit.HOURS.toMillis(1);
+ 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
+ {
+ long timeEnd = System.currentTimeMillis() + TimeUnit.HOURS.toMillis(1);
+ while (timeEnd > System.currentTimeMillis())
+ {
+
+ }
+ }
+
+ 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();
+ }
+
+ }
+}
14 years, 3 months
JBoss hornetq SVN: r9633 - branches/Branch_2_1/tests/src/org/hornetq/tests/integration/journal.
by do-not-reply@jboss.org
Author: clebert.suconic(a)jboss.com
Date: 2010-09-02 19:59:03 -0400 (Thu, 02 Sep 2010)
New Revision: 9633
Modified:
branches/Branch_2_1/tests/src/org/hornetq/tests/integration/journal/NIOJournalCompactTest.java
Log:
HORNETQ-485 - adding new tests on compacting
Modified: branches/Branch_2_1/tests/src/org/hornetq/tests/integration/journal/NIOJournalCompactTest.java
===================================================================
--- branches/Branch_2_1/tests/src/org/hornetq/tests/integration/journal/NIOJournalCompactTest.java 2010-09-02 23:53:00 UTC (rev 9632)
+++ branches/Branch_2_1/tests/src/org/hornetq/tests/integration/journal/NIOJournalCompactTest.java 2010-09-02 23:59:03 UTC (rev 9633)
@@ -23,6 +23,7 @@
import junit.framework.Assert;
import org.hornetq.api.core.Pair;
+import org.hornetq.core.journal.EncodingSupport;
import org.hornetq.core.journal.PreparedTransactionInfo;
import org.hornetq.core.journal.RecordInfo;
import org.hornetq.core.journal.SequentialFile;
@@ -232,6 +233,119 @@
}
+ public void testCompactPrepareRestart() throws Exception
+ {
+ setup(2, 60 * 1024, false);
+
+ createJournal();
+
+ startJournal();
+
+ load();
+
+ startCompact();
+
+ addTx(1, 2);
+
+ prepare(1, new SimpleEncoding(10, (byte)0));
+
+ finishCompact();
+
+ stopJournal();
+
+ createJournal();
+
+ startJournal();
+
+ loadAndCheck();
+
+ startCompact();
+
+ commit(1);
+
+ finishCompact();
+
+ journal.compact();
+
+ stopJournal();
+
+ createJournal();
+
+ startJournal();
+
+ loadAndCheck();
+ }
+
+ public void testCompactPrepareRestart2() throws Exception
+ {
+ setup(2, 60 * 1024, false);
+
+ createJournal();
+
+ startJournal();
+
+ load();
+
+ addTx(1, 2);
+
+ prepare(1, new SimpleEncoding(10, (byte)0));
+
+ stopJournal();
+
+ createJournal();
+
+ startJournal();
+
+ loadAndCheck();
+
+ startCompact();
+
+ commit(1);
+
+ finishCompact();
+
+ journal.compact();
+
+ stopJournal();
+
+ createJournal();
+
+ startJournal();
+
+ loadAndCheck();
+ }
+
+ public void testCompactPrepareRestart3() throws Exception
+ {
+ setup(2, 60 * 1024, false);
+
+ createJournal();
+
+ startJournal();
+
+ load();
+
+ addTx(1, 2, 3);
+
+ prepare(1, new SimpleEncoding(10, (byte)0));
+
+ startCompact();
+
+ commit(1);
+
+ finishCompact();
+
+ journal.compact();
+
+ stopJournal();
+
+ createJournal();
+
+ startJournal();
+
+ loadAndCheck();
+ }
+
public void testOnRollback() throws Exception
{
14 years, 3 months
JBoss hornetq SVN: r9632 - branches/Branch_2_1/src/main/org/hornetq/core/journal/impl.
by do-not-reply@jboss.org
Author: clebert.suconic(a)jboss.com
Date: 2010-09-02 19:53:00 -0400 (Thu, 02 Sep 2010)
New Revision: 9632
Modified:
branches/Branch_2_1/src/main/org/hornetq/core/journal/impl/JournalImpl.java
Log:
HORNETQ-485 - fixing id of TX
Modified: branches/Branch_2_1/src/main/org/hornetq/core/journal/impl/JournalImpl.java
===================================================================
--- branches/Branch_2_1/src/main/org/hornetq/core/journal/impl/JournalImpl.java 2010-09-02 23:21:38 UTC (rev 9631)
+++ branches/Branch_2_1/src/main/org/hornetq/core/journal/impl/JournalImpl.java 2010-09-02 23:53:00 UTC (rev 9632)
@@ -1914,7 +1914,7 @@
if (tnp == null)
{
- tnp = new JournalTransaction(info.id, JournalImpl.this);
+ tnp = new JournalTransaction(transactionID, JournalImpl.this);
transactions.put(transactionID, tnp);
}
14 years, 3 months
JBoss hornetq SVN: r9631 - in trunk: examples/jms/embedded/src/org/hornetq/jms/example and 17 other directories.
by do-not-reply@jboss.org
Author: bill.burke(a)jboss.com
Date: 2010-09-02 19:21:38 -0400 (Thu, 02 Sep 2010)
New Revision: 9631
Added:
trunk/examples/jms/embedded-simple/
trunk/examples/jms/embedded-simple/build.bat
trunk/examples/jms/embedded-simple/build.sh
trunk/examples/jms/embedded-simple/build.xml
trunk/examples/jms/embedded-simple/readme.html
trunk/examples/jms/embedded-simple/server0/
trunk/examples/jms/embedded-simple/server0/hornetq-configuration.xml
trunk/examples/jms/embedded-simple/server0/hornetq-jms.xml
trunk/examples/jms/embedded-simple/server0/hornetq-users.xml
trunk/examples/jms/embedded-simple/src/
trunk/examples/jms/embedded-simple/src/org/
trunk/examples/jms/embedded-simple/src/org/hornetq/
trunk/examples/jms/embedded-simple/src/org/hornetq/jms/
trunk/examples/jms/embedded-simple/src/org/hornetq/jms/example/
trunk/examples/jms/embedded-simple/src/org/hornetq/jms/example/EmbeddedExample.java
trunk/examples/jms/spring-integration/
trunk/examples/jms/spring-integration/build.bat
trunk/examples/jms/spring-integration/build.sh
trunk/examples/jms/spring-integration/build.xml
trunk/examples/jms/spring-integration/readme.html
trunk/examples/jms/spring-integration/server0/
trunk/examples/jms/spring-integration/server0/hornetq-configuration.xml
trunk/examples/jms/spring-integration/server0/hornetq-jms.xml
trunk/examples/jms/spring-integration/server0/hornetq-users.xml
trunk/examples/jms/spring-integration/server0/spring-jms-beans.xml
trunk/examples/jms/spring-integration/src/
trunk/examples/jms/spring-integration/src/org/
trunk/examples/jms/spring-integration/src/org/hornetq/
trunk/examples/jms/spring-integration/src/org/hornetq/jms/
trunk/examples/jms/spring-integration/src/org/hornetq/jms/example/
trunk/examples/jms/spring-integration/src/org/hornetq/jms/example/ExampleListener.java
trunk/examples/jms/spring-integration/src/org/hornetq/jms/example/MessageSender.java
trunk/examples/jms/spring-integration/src/org/hornetq/jms/example/SpringExample.java
Modified:
trunk/examples/jms/embedded/src/org/hornetq/jms/example/EmbeddedExample.java
trunk/src/main/org/hornetq/core/registry/MapBindingRegistry.java
trunk/src/main/org/hornetq/core/server/embedded/EmbeddedHornetQ.java
trunk/src/main/org/hornetq/jms/server/embedded/EmbeddedJMS.java
Log:
added new examples for spring and embedded, reworked embedded example
Modified: trunk/examples/jms/embedded/src/org/hornetq/jms/example/EmbeddedExample.java
===================================================================
--- trunk/examples/jms/embedded/src/org/hornetq/jms/example/EmbeddedExample.java 2010-09-02 23:20:36 UTC (rev 9630)
+++ trunk/examples/jms/embedded/src/org/hornetq/jms/example/EmbeddedExample.java 2010-09-02 23:21:38 UTC (rev 9631)
@@ -12,42 +12,34 @@
*/
package org.hornetq.jms.example;
-import java.util.Date;
-import java.util.Hashtable;
-
-import javax.jms.Connection;
-import javax.jms.ConnectionFactory;
-import javax.jms.MessageConsumer;
-import javax.jms.MessageProducer;
-import javax.jms.Queue;
-import javax.jms.Session;
-import javax.jms.TextMessage;
-import javax.naming.Context;
-import javax.naming.InitialContext;
-
import org.hornetq.api.core.TransportConfiguration;
import org.hornetq.core.config.Configuration;
import org.hornetq.core.config.impl.ConfigurationImpl;
import org.hornetq.core.remoting.impl.netty.NettyAcceptorFactory;
import org.hornetq.core.remoting.impl.netty.NettyConnectorFactory;
-import org.hornetq.core.server.HornetQServer;
-import org.hornetq.core.server.HornetQServers;
-import org.hornetq.jms.server.JMSServerManager;
import org.hornetq.jms.server.config.ConnectionFactoryConfiguration;
import org.hornetq.jms.server.config.JMSConfiguration;
import org.hornetq.jms.server.config.JMSQueueConfiguration;
import org.hornetq.jms.server.config.impl.ConnectionFactoryConfigurationImpl;
import org.hornetq.jms.server.config.impl.JMSConfigurationImpl;
import org.hornetq.jms.server.config.impl.JMSQueueConfigurationImpl;
-import org.hornetq.jms.server.impl.JMSServerManagerImpl;
-import org.jnp.server.Main;
-import org.jnp.server.NamingBeanImpl;
+import org.hornetq.jms.server.embedded.EmbeddedJMS;
+import javax.jms.Connection;
+import javax.jms.ConnectionFactory;
+import javax.jms.MessageConsumer;
+import javax.jms.MessageProducer;
+import javax.jms.Queue;
+import javax.jms.Session;
+import javax.jms.TextMessage;
+import java.util.Date;
+
/**
* This example demonstrates how to run a HornetQ embedded with JMS
*
* @author <a href="clebert.suconic(a)jboss.com">Clebert Suconic</a>
* @author <a href="mailto:jmesnil@redhat.com">Jeff Mesnil</a>
+ * @author <a href="mailto:bburke@redhat.com">Bill Burke</a>
*/
public class EmbeddedExample
{
@@ -64,51 +56,30 @@
configuration.getAcceptorConfigurations()
.add(new TransportConfiguration(NettyAcceptorFactory.class.getName()));
- // Step 2. Create HornetQ core server
- HornetQServer hornetqServer = HornetQServers.newHornetQServer(configuration);
-
- // Step 3. Create and start the JNDI server
- System.setProperty("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");
- NamingBeanImpl naming = new NamingBeanImpl();
- naming.start();
- Main jndiServer = new Main();
- jndiServer.setNamingInfo(naming);
- jndiServer.setPort(1099);
- jndiServer.setBindAddress("localhost");
- jndiServer.setRmiPort(1098);
- jndiServer.setRmiBindAddress("localhost");
- jndiServer.start();
-
- // Step 4. Create the JMS configuration
+ // Step 2. Create the JMS configuration
JMSConfiguration jmsConfig = new JMSConfigurationImpl();
- // Step 5. Configure context used to bind the JMS resources to JNDI
- Hashtable<String, String> env = new Hashtable<String, String>();
- env.put("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");
- env.put("java.naming.provider.url", "jnp://localhost:1099");
- env.put("java.naming.factory.url.pkgs", "org.jboss.naming:org.jnp.interfaces");
- Context context = new InitialContext(env);
- jmsConfig.setContext(context);
-
- // Step 6. Configure the JMS ConnectionFactory
+ // Step 3. Configure the JMS ConnectionFactory
TransportConfiguration connectorConfig = new TransportConfiguration(NettyConnectorFactory.class.getName());
ConnectionFactoryConfiguration cfConfig = new ConnectionFactoryConfigurationImpl("cf", connectorConfig, "/cf");
jmsConfig.getConnectionFactoryConfigurations().add(cfConfig);
- // Step 7. Configure the JMS Queue
+ // Step 4. Configure the JMS Queue
JMSQueueConfiguration queueConfig = new JMSQueueConfigurationImpl("queue1", null, false, "/queue/queue1");
jmsConfig.getQueueConfigurations().add(queueConfig);
- // Step 8. Start the JMS Server using the HornetQ core server and the JMS configuration
- JMSServerManager jmsServer = new JMSServerManagerImpl(hornetqServer, jmsConfig);
+ // Step 5. Start the JMS Server using the HornetQ core server and the JMS configuration
+ EmbeddedJMS jmsServer = new EmbeddedJMS();
+ jmsServer.setConfiguration(configuration);
+ jmsServer.setJmsConfiguration(jmsConfig);
jmsServer.start();
System.out.println("Started Embedded JMS Server");
- // Step 9. Lookup JMS resources defined in the configuration
- ConnectionFactory cf = (ConnectionFactory)context.lookup("/cf");
- Queue queue = (Queue)context.lookup("/queue/queue1");
+ // Step 6. Lookup JMS resources defined in the configuration
+ ConnectionFactory cf = (ConnectionFactory)jmsServer.lookup("/cf");
+ Queue queue = (Queue)jmsServer.lookup("/queue/queue1");
- // Step 10. Send and receive a message using JMS API
+ // Step 7. Send and receive a message using JMS API
Connection connection = null;
try
{
@@ -134,9 +105,6 @@
jmsServer.stop();
System.out.println("Stopped the JMS Server");
- // Step 12. Stop the JNDI server
- naming.stop();
- jndiServer.stop();
System.exit(0);
}
}
Added: trunk/examples/jms/embedded-simple/build.bat
===================================================================
--- trunk/examples/jms/embedded-simple/build.bat (rev 0)
+++ trunk/examples/jms/embedded-simple/build.bat 2010-09-02 23:21:38 UTC (rev 9631)
@@ -0,0 +1,13 @@
+@echo off
+
+set "OVERRIDE_ANT_HOME=..\..\..\tools\ant"
+
+if exist "..\..\..\src\bin\build.bat" (
+ rem running from TRUNK
+ call ..\..\..\src\bin\build.bat %*
+) else (
+ rem running from the distro
+ call ..\..\..\bin\build.bat %*
+)
+
+set "OVERRIDE_ANT_HOME="
Added: trunk/examples/jms/embedded-simple/build.sh
===================================================================
--- trunk/examples/jms/embedded-simple/build.sh (rev 0)
+++ trunk/examples/jms/embedded-simple/build.sh 2010-09-02 23:21:38 UTC (rev 9631)
@@ -0,0 +1,15 @@
+#!/bin/sh
+
+OVERRIDE_ANT_HOME=../../../tools/ant
+export OVERRIDE_ANT_HOME
+
+if [ -f "../../../src/bin/build.sh" ]; then
+ # running from TRUNK
+ ../../../src/bin/build.sh "$@"
+else
+ # running from the distro
+ ../../../bin/build.sh "$@"
+fi
+
+
+
Property changes on: trunk/examples/jms/embedded-simple/build.sh
___________________________________________________________________
Name: svn:executable
+ *
Added: trunk/examples/jms/embedded-simple/build.xml
===================================================================
--- trunk/examples/jms/embedded-simple/build.xml (rev 0)
+++ trunk/examples/jms/embedded-simple/build.xml 2010-09-02 23:21:38 UTC (rev 9631)
@@ -0,0 +1,54 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE project [
+ <!ENTITY libraries SYSTEM "../../../thirdparty/libraries.ent">
+ ]>
+<!--
+ ~ Copyright 2009 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.
+ -->
+
+<project default="run" name="HornetQ Embedded Example">
+
+ <import file="../../common/build.xml"/>
+
+ <path id="local.classpath">
+ <fileset dir="${hornetq.jars.dir}">
+ <include name="hornetq-core.jar"/>
+ <include name="hornetq-jms.jar"/>
+ </fileset>
+
+ <fileset dir="${jars.dir}">
+ <include name="**/jboss-jms-api.jar"/>
+ <include name="**/netty.jar"/>
+ </fileset>
+
+ <pathelement location="${classes.dir}"/>
+ <pathelement location="server0"/>
+ </path>
+
+ <target name="run" depends="compile">
+ <java classname="org.hornetq.jms.example.EmbeddedExample" fork="true" resultproperty="example-result">
+ <jvmarg value="-Xms50M"/>
+ <jvmarg value="-Xmx50M"/>
+ <classpath refid="local.classpath"/>
+ </java>
+
+ <!-- if the example exited with a result value != 0, we fail the build -->
+ <fail message="Example EmbeddedExample failed">
+ <condition>
+ <not>
+ <equals arg1="${example-result}" arg2="0"/>
+ </not>
+ </condition>
+ </fail>
+
+ </target>
+</project>
Added: trunk/examples/jms/embedded-simple/readme.html
===================================================================
--- trunk/examples/jms/embedded-simple/readme.html (rev 0)
+++ trunk/examples/jms/embedded-simple/readme.html 2010-09-02 23:21:38 UTC (rev 9631)
@@ -0,0 +1,52 @@
+<html>
+ <head>
+ <title>HornetQ Embedded JMS Server Example</title>
+ <link rel="stylesheet" type="text/css" href="../../common/common.css" />
+ <link rel="stylesheet" type="text/css" href="../../common/prettify.css" />
+ <script type="text/javascript" src="../../common/prettify.js"></script>
+ </head>
+ <body onload="prettyPrint()">
+ <h1>Embedded JMS Server Example</h1>
+
+ <p>This examples shows how to setup and run an embedded JMS server using HornetQ along with HornetQ configuration files.</p>
+
+ <h2>Example step-by-step</h2>
+ <p><i>To run the example, simply type <code>./build.sh</code> (or <code>build.bat</code> on windows) from this directory</i></p>
+
+ <ol>
+ <li>Create HornetQ core configuration files and make sure they are within your classpath. By default, HornetQ
+ expects the classnames to be "hornetq-configuration.xml", "hornetq-jms.xml", and "hornetq-users.xml".</li>
+ <li>Create and start HornetQ JMS server</li>
+ <pre class="prettyprint">
+ <code>EmbeddedJMS jmsServer = new EmbeddedJMS();
+ jmsServer.start();</code>
+ </pre>
+
+ <p>At this point the JMS server is started and any JMS clients can look up JMS resources from the JNDI to send/receive
+ messages from the server. To keep the example simple, we will send and receive a JMS message from the same JVM
+ used to run the JMS server.</p>
+
+ <li>Lookup JMS resources defined in the configuration </li>
+ <pre class="prettyprint">
+ <code>ConnectionFactory cf = (ConnectionFactory)context.lookup("/cf");
+ Queue queue = (Queue)context.lookup("/queue/queue1");</code>
+ </pre>
+
+ <li>Send and receive a message using JMS API</li>
+ <p>See the <a href="../queue/readme.html">Queue Example</a> for detailed steps to send and receive a JMS message</p>
+
+ <p>Finally, we stop the JMS server and its associated resources.</p>
+
+ <li>Stop the JMS server</li>
+ <pre class="prettyprint">
+ <code>jmsServer.stop();</code>
+ </pre>
+
+ <li>Stop the JNDI server</li>
+ <pre class="prettyprint">
+ <code>naming.stop();
+ jndiServer.stop();</code>
+ </pre>
+ </ol>
+ </body>
+</html>
\ No newline at end of file
Added: trunk/examples/jms/embedded-simple/server0/hornetq-configuration.xml
===================================================================
--- trunk/examples/jms/embedded-simple/server0/hornetq-configuration.xml (rev 0)
+++ trunk/examples/jms/embedded-simple/server0/hornetq-configuration.xml 2010-09-02 23:21:38 UTC (rev 9631)
@@ -0,0 +1,34 @@
+<configuration xmlns="urn:hornetq"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="urn:hornetq /schema/hornetq-configuration.xsd">
+
+ <persistence-enabled>false</persistence-enabled>
+ <!-- Connectors -->
+
+ <connectors>
+ <connector name="in-vm">
+ <factory-class>org.hornetq.core.remoting.impl.invm.InVMConnectorFactory</factory-class>
+ </connector>
+ </connectors>
+
+ <acceptors>
+ <acceptor name="in-vm">
+ <factory-class>org.hornetq.core.remoting.impl.invm.InVMAcceptorFactory</factory-class>
+ </acceptor>
+ </acceptors>
+
+ <!-- Other config -->
+
+ <security-settings>
+ <!--security for example queue-->
+ <security-setting match="#">
+ <permission type="createDurableQueue" roles="guest"/>
+ <permission type="deleteDurableQueue" roles="guest"/>
+ <permission type="createNonDurableQueue" roles="guest"/>
+ <permission type="deleteNonDurableQueue" roles="guest"/>
+ <permission type="consume" roles="guest"/>
+ <permission type="send" roles="guest"/>
+ </security-setting>
+ </security-settings>
+
+</configuration>
Added: trunk/examples/jms/embedded-simple/server0/hornetq-jms.xml
===================================================================
--- trunk/examples/jms/embedded-simple/server0/hornetq-jms.xml (rev 0)
+++ trunk/examples/jms/embedded-simple/server0/hornetq-jms.xml 2010-09-02 23:21:38 UTC (rev 9631)
@@ -0,0 +1,19 @@
+<configuration xmlns="urn:hornetq"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="urn:hornetq /schema/hornetq-jms.xsd">
+ <!--the connection factory used by the example-->
+ <connection-factory name="ConnectionFactory">
+ <connectors>
+ <connector-ref connector-name="in-vm"/>
+ </connectors>
+ <entries>
+ <entry name="ConnectionFactory"/>
+ </entries>
+ </connection-factory>
+
+ <!--the queue used by the example-->
+ <queue name="exampleQueue">
+ <entry name="/queue/exampleQueue"/>
+ </queue>
+
+</configuration>
Added: trunk/examples/jms/embedded-simple/server0/hornetq-users.xml
===================================================================
--- trunk/examples/jms/embedded-simple/server0/hornetq-users.xml (rev 0)
+++ trunk/examples/jms/embedded-simple/server0/hornetq-users.xml 2010-09-02 23:21:38 UTC (rev 9631)
@@ -0,0 +1,7 @@
+<configuration xmlns="urn:hornetq" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="urn:hornetq /schema/hornetq-users.xsd">
+ <!-- the default user. this is used where username is null-->
+ <defaultuser name="guest" password="guest">
+ <role name="guest"/>
+ </defaultuser>
+</configuration>
\ No newline at end of file
Added: trunk/examples/jms/embedded-simple/src/org/hornetq/jms/example/EmbeddedExample.java
===================================================================
--- trunk/examples/jms/embedded-simple/src/org/hornetq/jms/example/EmbeddedExample.java (rev 0)
+++ trunk/examples/jms/embedded-simple/src/org/hornetq/jms/example/EmbeddedExample.java 2010-09-02 23:21:38 UTC (rev 9631)
@@ -0,0 +1,83 @@
+/*
+ * Copyright 2009 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.Date;
+import java.util.Hashtable;
+
+import javax.jms.Connection;
+import javax.jms.ConnectionFactory;
+import javax.jms.MessageConsumer;
+import javax.jms.MessageProducer;
+import javax.jms.Queue;
+import javax.jms.Session;
+import javax.jms.TextMessage;
+
+import org.hornetq.jms.server.embedded.EmbeddedJMS;
+
+/**
+ * This example demonstrates how to run a HornetQ embedded with JMS
+ *
+ * @author <a href="clebert.suconic(a)jboss.com">Clebert Suconic</a>
+ * @author <a href="mailto:jmesnil@redhat.com">Jeff Mesnil</a>
+ */
+public class EmbeddedExample
+{
+
+ public static void main(final String[] args)
+ {
+ try
+ {
+ EmbeddedJMS jmsServer = new EmbeddedJMS();
+ jmsServer.start();
+ System.out.println("Started Embedded JMS Server");
+
+ ConnectionFactory cf = (ConnectionFactory)jmsServer.lookup("/cf");
+ Queue queue = (Queue)jmsServer.lookup("/queue/exampleQueue");
+
+ // Step 10. Send and receive a message using JMS API
+ Connection connection = null;
+ try
+ {
+ connection = cf.createConnection();
+ Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ MessageProducer producer = session.createProducer(queue);
+ TextMessage message = session.createTextMessage("Hello sent at " + new Date());
+ System.out.println("Sending message: " + message.getText());
+ producer.send(message);
+ MessageConsumer messageConsumer = session.createConsumer(queue);
+ connection.start();
+ TextMessage messageReceived = (TextMessage)messageConsumer.receive(1000);
+ System.out.println("Received message:" + messageReceived.getText());
+ }
+ finally
+ {
+ if (connection != null)
+ {
+ connection.close();
+ }
+
+ // Step 11. Stop the JMS server
+ jmsServer.stop();
+ System.out.println("Stopped the JMS Server");
+ System.exit(0);
+ }
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ System.exit(-1);
+ }
+ }
+
+}
Added: trunk/examples/jms/spring-integration/build.bat
===================================================================
--- trunk/examples/jms/spring-integration/build.bat (rev 0)
+++ trunk/examples/jms/spring-integration/build.bat 2010-09-02 23:21:38 UTC (rev 9631)
@@ -0,0 +1,13 @@
+@echo off
+
+set "OVERRIDE_ANT_HOME=..\..\..\tools\ant"
+
+if exist "..\..\..\src\bin\build.bat" (
+ rem running from TRUNK
+ call ..\..\..\src\bin\build.bat %*
+) else (
+ rem running from the distro
+ call ..\..\..\bin\build.bat %*
+)
+
+set "OVERRIDE_ANT_HOME="
Added: trunk/examples/jms/spring-integration/build.sh
===================================================================
--- trunk/examples/jms/spring-integration/build.sh (rev 0)
+++ trunk/examples/jms/spring-integration/build.sh 2010-09-02 23:21:38 UTC (rev 9631)
@@ -0,0 +1,15 @@
+#!/bin/sh
+
+OVERRIDE_ANT_HOME=../../../tools/ant
+export OVERRIDE_ANT_HOME
+
+if [ -f "../../../src/bin/build.sh" ]; then
+ # running from TRUNK
+ ../../../src/bin/build.sh "$@"
+else
+ # running from the distro
+ ../../../bin/build.sh "$@"
+fi
+
+
+
Property changes on: trunk/examples/jms/spring-integration/build.sh
___________________________________________________________________
Name: svn:executable
+ *
Added: trunk/examples/jms/spring-integration/build.xml
===================================================================
--- trunk/examples/jms/spring-integration/build.xml (rev 0)
+++ trunk/examples/jms/spring-integration/build.xml 2010-09-02 23:21:38 UTC (rev 9631)
@@ -0,0 +1,64 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE project [
+ <!ENTITY libraries SYSTEM "../../../thirdparty/libraries.ent">
+ ]>
+<!--
+ ~ Copyright 2009 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.
+ -->
+
+<project default="run" name="HornetQ Embedded Example">
+
+ <import file="../../common/build.xml"/>
+ <echo message = "Do not forget to add the Spring jars to your classpath!!!!!!!"/>
+ <path id="extra.classpath">
+ <fileset dir="${jars.dir}">
+ <include name="**/spring*.jar"/>
+ <include name="**/commons-logging.jar"/>
+ </fileset>
+ </path>
+
+ <path id="local.classpath">
+ <fileset dir="${hornetq.jars.dir}">
+ <include name="hornetq-core.jar"/>
+ <include name="hornetq-jms.jar"/>
+ <include name="hornetq-spring-integration.jar"/>
+ </fileset>
+
+ <fileset dir="${jars.dir}">
+ <include name="**/jboss-jms-api.jar"/>
+ <include name="**/netty.jar"/>
+ <include name="**/spring*.jar"/>
+ <include name="**/commons-logging.jar"/>
+ </fileset>
+
+ <pathelement location="${classes.dir}"/>
+ <pathelement location="server0"/>
+ </path>
+
+ <target name="run" depends="compile">
+ <java classname="org.hornetq.jms.example.SpringExample" fork="true" resultproperty="example-result">
+ <jvmarg value="-Xms50M"/>
+ <jvmarg value="-Xmx50M"/>
+ <classpath refid="local.classpath"/>
+ </java>
+
+ <!-- if the example exited with a result value != 0, we fail the build -->
+ <fail message="Example SpringExample failed">
+ <condition>
+ <not>
+ <equals arg1="${example-result}" arg2="0"/>
+ </not>
+ </condition>
+ </fail>
+
+ </target>
+</project>
Added: trunk/examples/jms/spring-integration/readme.html
===================================================================
--- trunk/examples/jms/spring-integration/readme.html (rev 0)
+++ trunk/examples/jms/spring-integration/readme.html 2010-09-02 23:21:38 UTC (rev 9631)
@@ -0,0 +1,17 @@
+<html>
+ <head>
+ <title>HornetQ Spring Example</title>
+ <link rel="stylesheet" type="text/css" href="../../common/common.css" />
+ <link rel="stylesheet" type="text/css" href="../../common/prettify.css" />
+ <script type="text/javascript" src="../../common/prettify.js"></script>
+ </head>
+ <body onload="prettyPrint()">
+ <h1>HornetQ Spring Example</h1>
+
+ <p>This examples shows how to setup and run an embedded JMS server within a Spring ApplicationContext using HornetQ along with HornetQ configuration files.</p>
+
+ <h2>Example step-by-step</h2>
+ <p><i><b>YOU MUST DOWNLOAD THE SPRING LIBRARIES TO RUN THIS EXAMPLE!!!</b> You must also modify the build.xml file to include the spring jars. You'll see the placeholder that is already there.</i></p>
+ <p><i>To run the example, simply type <code>./build.sh</code> (or <code>build.bat</code> on windows) from this directory</i></p>
+ </body>
+</html>
Added: trunk/examples/jms/spring-integration/server0/hornetq-configuration.xml
===================================================================
--- trunk/examples/jms/spring-integration/server0/hornetq-configuration.xml (rev 0)
+++ trunk/examples/jms/spring-integration/server0/hornetq-configuration.xml 2010-09-02 23:21:38 UTC (rev 9631)
@@ -0,0 +1,34 @@
+<configuration xmlns="urn:hornetq"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="urn:hornetq /schema/hornetq-configuration.xsd">
+
+ <persistence-enabled>false</persistence-enabled>
+ <!-- Connectors -->
+
+ <connectors>
+ <connector name="in-vm">
+ <factory-class>org.hornetq.core.remoting.impl.invm.InVMConnectorFactory</factory-class>
+ </connector>
+ </connectors>
+
+ <acceptors>
+ <acceptor name="in-vm">
+ <factory-class>org.hornetq.core.remoting.impl.invm.InVMAcceptorFactory</factory-class>
+ </acceptor>
+ </acceptors>
+
+ <!-- Other config -->
+
+ <security-settings>
+ <!--security for example queue-->
+ <security-setting match="#">
+ <permission type="createDurableQueue" roles="guest"/>
+ <permission type="deleteDurableQueue" roles="guest"/>
+ <permission type="createNonDurableQueue" roles="guest"/>
+ <permission type="deleteNonDurableQueue" roles="guest"/>
+ <permission type="consume" roles="guest"/>
+ <permission type="send" roles="guest"/>
+ </security-setting>
+ </security-settings>
+
+</configuration>
Added: trunk/examples/jms/spring-integration/server0/hornetq-jms.xml
===================================================================
--- trunk/examples/jms/spring-integration/server0/hornetq-jms.xml (rev 0)
+++ trunk/examples/jms/spring-integration/server0/hornetq-jms.xml 2010-09-02 23:21:38 UTC (rev 9631)
@@ -0,0 +1,19 @@
+<configuration xmlns="urn:hornetq"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="urn:hornetq /schema/hornetq-jms.xsd">
+ <!--the connection factory used by the example-->
+ <connection-factory name="ConnectionFactory">
+ <connectors>
+ <connector-ref connector-name="in-vm"/>
+ </connectors>
+ <entries>
+ <entry name="ConnectionFactory"/>
+ </entries>
+ </connection-factory>
+
+ <!--the queue used by the example-->
+ <queue name="exampleQueue">
+ <entry name="/queue/exampleQueue"/>
+ </queue>
+
+</configuration>
Added: trunk/examples/jms/spring-integration/server0/hornetq-users.xml
===================================================================
--- trunk/examples/jms/spring-integration/server0/hornetq-users.xml (rev 0)
+++ trunk/examples/jms/spring-integration/server0/hornetq-users.xml 2010-09-02 23:21:38 UTC (rev 9631)
@@ -0,0 +1,7 @@
+<configuration xmlns="urn:hornetq" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="urn:hornetq /schema/hornetq-users.xsd">
+ <!-- the default user. this is used where username is null-->
+ <defaultuser name="guest" password="guest">
+ <role name="guest"/>
+ </defaultuser>
+</configuration>
\ No newline at end of file
Added: trunk/examples/jms/spring-integration/server0/spring-jms-beans.xml
===================================================================
--- trunk/examples/jms/spring-integration/server0/spring-jms-beans.xml (rev 0)
+++ trunk/examples/jms/spring-integration/server0/spring-jms-beans.xml 2010-09-02 23:21:38 UTC (rev 9631)
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://www.springframework.org/schema/beans
+ http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
+
+ <bean id="EmbeddedJms" class="org.hornetq.integration.spring.SpringJmsBootstrap" init-method="start" destroy-method="stop"/>
+
+ <bean id="listener" class="org.hornetq.jms.example.ExampleListener"/>
+
+ <bean id="MessageSender" class="org.hornetq.jms.example.MessageSender">
+ <property name="connectionFactory" ref="ConnectionFactory"/>
+ <property name="destination" ref="/queue/exampleQueue"/>
+ </bean>
+
+ <bean id="listenerContainer" class="org.springframework.jms.listener.DefaultMessageListenerContainer">
+ <property name="connectionFactory" ref="ConnectionFactory"/>
+ <property name="destination" ref="/queue/exampleQueue"/>
+ <property name="messageListener" ref="listener"/>
+ </bean>
+
+
+</beans>
+
\ No newline at end of file
Added: trunk/examples/jms/spring-integration/src/org/hornetq/jms/example/ExampleListener.java
===================================================================
--- trunk/examples/jms/spring-integration/src/org/hornetq/jms/example/ExampleListener.java (rev 0)
+++ trunk/examples/jms/spring-integration/src/org/hornetq/jms/example/ExampleListener.java 2010-09-02 23:21:38 UTC (rev 9631)
@@ -0,0 +1,28 @@
+package org.hornetq.jms.example;
+
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.jms.MessageListener;
+import javax.jms.TextMessage;
+
+/**
+ * @author <a href="mailto:bill@burkecentral.com">Bill Burke</a>
+ * @version $Revision: 1 $
+ */
+public class ExampleListener implements MessageListener
+{
+ public static String lastMessage = null;
+
+ public void onMessage(Message message)
+ {
+ try
+ {
+ lastMessage = ((TextMessage)message).getText();
+ }
+ catch (JMSException e)
+ {
+ throw new RuntimeException(e);
+ }
+ System.out.println("MESSAGE RECEIVED: " + lastMessage);
+ }
+}
Added: trunk/examples/jms/spring-integration/src/org/hornetq/jms/example/MessageSender.java
===================================================================
--- trunk/examples/jms/spring-integration/src/org/hornetq/jms/example/MessageSender.java (rev 0)
+++ trunk/examples/jms/spring-integration/src/org/hornetq/jms/example/MessageSender.java 2010-09-02 23:21:38 UTC (rev 9631)
@@ -0,0 +1,54 @@
+package org.hornetq.jms.example;
+
+import javax.jms.Connection;
+import javax.jms.ConnectionFactory;
+import javax.jms.Destination;
+import javax.jms.MessageProducer;
+import javax.jms.Session;
+import javax.jms.TextMessage;
+
+/**
+ * @author <a href="mailto:bill@burkecentral.com">Bill Burke</a>
+ * @version $Revision: 1 $
+ */
+public class MessageSender
+{
+ private ConnectionFactory connectionFactory;
+ private Destination destination;
+
+ public ConnectionFactory getConnectionFactory()
+ {
+ return connectionFactory;
+ }
+
+ public void setConnectionFactory(ConnectionFactory connectionFactory)
+ {
+ this.connectionFactory = connectionFactory;
+ }
+
+ public Destination getDestination()
+ {
+ return destination;
+ }
+
+ public void setDestination(Destination destination)
+ {
+ this.destination = destination;
+ }
+
+ public void send(String msg)
+ {
+ try
+ {
+ Connection conn = connectionFactory.createConnection();
+ Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ MessageProducer producer = session.createProducer(destination);
+ TextMessage message = session.createTextMessage(msg);
+ producer.send(message);
+ }
+ catch (Exception ex)
+ {
+ ex.printStackTrace();
+ }
+ }
+}
Added: trunk/examples/jms/spring-integration/src/org/hornetq/jms/example/SpringExample.java
===================================================================
--- trunk/examples/jms/spring-integration/src/org/hornetq/jms/example/SpringExample.java (rev 0)
+++ trunk/examples/jms/spring-integration/src/org/hornetq/jms/example/SpringExample.java 2010-09-02 23:21:38 UTC (rev 9631)
@@ -0,0 +1,22 @@
+package org.hornetq.jms.example;
+
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+
+/**
+ * @author <a href="mailto:bill@burkecentral.com">Bill Burke</a>
+ * @version $Revision: 1 $
+ */
+public class SpringExample
+{
+ public static void main(String[] args) throws Exception
+ {
+ System.out.println("Creating bean factory...");
+ ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(new String[] {"spring-jms-beans.xml"});
+ MessageSender sender = (MessageSender)context.getBean("MessageSender");
+ System.out.println("Sending message...");
+ sender.send("Hello world");
+ Thread.sleep(100);
+ context.destroy();
+ }
+}
Modified: trunk/src/main/org/hornetq/core/registry/MapBindingRegistry.java
===================================================================
--- trunk/src/main/org/hornetq/core/registry/MapBindingRegistry.java 2010-09-02 23:20:36 UTC (rev 9630)
+++ trunk/src/main/org/hornetq/core/registry/MapBindingRegistry.java 2010-09-02 23:21:38 UTC (rev 9631)
@@ -1,7 +1,7 @@
package org.hornetq.core.registry;
import org.hornetq.spi.BindingRegistry;
-import org.jboss.netty.util.internal.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentHashMap;
/**
* @author <a href="mailto:bill@burkecentral.com">Bill Burke</a>
Modified: trunk/src/main/org/hornetq/core/server/embedded/EmbeddedHornetQ.java
===================================================================
--- trunk/src/main/org/hornetq/core/server/embedded/EmbeddedHornetQ.java 2010-09-02 23:20:36 UTC (rev 9630)
+++ trunk/src/main/org/hornetq/core/server/embedded/EmbeddedHornetQ.java 2010-09-02 23:21:38 UTC (rev 9631)
@@ -1,5 +1,6 @@
package org.hornetq.core.server.embedded;
+import org.hornetq.core.config.Configuration;
import org.hornetq.core.config.impl.FileConfiguration;
import org.hornetq.core.server.HornetQServer;
import org.hornetq.core.server.impl.HornetQServerImpl;
@@ -17,7 +18,8 @@
public class EmbeddedHornetQ
{
protected HornetQSecurityManager securityManager;
- protected FileConfiguration configuration = new FileConfiguration();
+ protected String configResourcePath = null;
+ protected Configuration configuration;
protected HornetQServer hornetQServer;
protected MBeanServer mbeanServer;
@@ -28,7 +30,7 @@
*/
public void setConfigResourcePath(String filename)
{
- configuration.setConfigurationUrl(filename);
+ configResourcePath = filename;
}
/**
@@ -51,6 +53,17 @@
this.mbeanServer = mbeanServer;
}
+ /**
+ * Set this object if you are not using file-based configuration. The default implementation will load
+ * configuration from a file.
+ *
+ * @param configuration
+ */
+ public void setConfiguration(Configuration configuration)
+ {
+ this.configuration = configuration;
+ }
+
public HornetQServer getHornetQServer()
{
return hornetQServer;
@@ -65,7 +78,14 @@
protected void initStart() throws Exception
{
- configuration.start();
+ if (configuration == null)
+ {
+ if (configResourcePath == null) configResourcePath = "hornetq-configuration.xml";
+ FileConfiguration config = new FileConfiguration();
+ config.setConfigurationUrl(configResourcePath);
+ config.start();
+ configuration = config;
+ }
if (securityManager == null)
{
securityManager = new HornetQSecurityManagerImpl();
Modified: trunk/src/main/org/hornetq/jms/server/embedded/EmbeddedJMS.java
===================================================================
--- trunk/src/main/org/hornetq/jms/server/embedded/EmbeddedJMS.java 2010-09-02 23:20:36 UTC (rev 9630)
+++ trunk/src/main/org/hornetq/jms/server/embedded/EmbeddedJMS.java 2010-09-02 23:21:38 UTC (rev 9631)
@@ -1,16 +1,20 @@
package org.hornetq.jms.server.embedded;
+import org.hornetq.core.registry.JndiBindingRegistry;
import org.hornetq.core.registry.MapBindingRegistry;
import org.hornetq.core.server.embedded.EmbeddedHornetQ;
+import org.hornetq.jms.server.config.JMSConfiguration;
import org.hornetq.jms.server.impl.JMSServerManagerImpl;
import org.hornetq.spi.BindingRegistry;
+import javax.naming.Context;
+
/**
* Simple bootstrap class that parses hornetq config files (server and jms and security) and starts
* a HornetQServer instance and populates it with configured JMS endpoints.
* <p/>
* JMS Endpoints are registered with a simple MapBindingRegistry. If you want to use a different registry
- * you must set the registry property of this clas
+ * you must set the registry property of this class or call the setRegistry() method if you want to use JNDI
*
* @author <a href="mailto:bill@burkecentral.com">Bill Burke</a>
* @version $Revision: 1 $
@@ -20,6 +24,8 @@
protected JMSServerManagerImpl serverManager;
protected BindingRegistry registry;
protected String jmsConfigResourcePath;
+ protected JMSConfiguration jmsConfiguration;
+ protected Context context;
/**
* Classpath resource where JMS config file is. Defaults to 'hornetq-jms.xml'
@@ -36,12 +42,37 @@
return registry;
}
+ /**
+ * Only set this property if you are using a custom BindingRegistry
+ *
+ * @param registry
+ */
public void setRegistry(BindingRegistry registry)
{
this.registry = registry;
}
/**
+ * By default, this class uses file-based configuration. Set this property to override it.
+ *
+ * @param jmsConfiguration
+ */
+ public void setJmsConfiguration(JMSConfiguration jmsConfiguration)
+ {
+ this.jmsConfiguration = jmsConfiguration;
+ }
+
+ /**
+ * If you want to use JNDI instead of an internal map, set this property
+ *
+ * @param context
+ */
+ public void setContext(Context context)
+ {
+ this.context = context;
+ }
+
+ /**
* Lookup in the registry for registered object, i.e. a ConnectionFactory. This is a convenience method.
*
* @param name
@@ -55,11 +86,17 @@
public void start() throws Exception
{
super.initStart();
- if (jmsConfigResourcePath == null) serverManager = new JMSServerManagerImpl(hornetQServer);
+ if (jmsConfiguration != null)
+ {
+ serverManager = new JMSServerManagerImpl(hornetQServer, jmsConfiguration);
+ }
+ else if (jmsConfigResourcePath == null) serverManager = new JMSServerManagerImpl(hornetQServer);
else serverManager = new JMSServerManagerImpl(hornetQServer, jmsConfigResourcePath);
+
if (registry == null)
{
- registry = new MapBindingRegistry();
+ if (context != null) registry = new JndiBindingRegistry(context);
+ else registry = new MapBindingRegistry();
}
serverManager.setRegistry(registry);
serverManager.start();
14 years, 3 months
JBoss hornetq SVN: r9630 - trunk/docs/user-manual/en.
by do-not-reply@jboss.org
Author: bill.burke(a)jboss.com
Date: 2010-09-02 19:20:36 -0400 (Thu, 02 Sep 2010)
New Revision: 9630
Added:
trunk/docs/user-manual/en/spring-integration.xml
Modified:
trunk/docs/user-manual/en/embedding-hornetq.xml
trunk/docs/user-manual/en/examples.xml
trunk/docs/user-manual/en/master.xml
Log:
Spring and embedded reworking
Modified: trunk/docs/user-manual/en/embedding-hornetq.xml
===================================================================
--- trunk/docs/user-manual/en/embedding-hornetq.xml 2010-09-02 11:58:21 UTC (rev 9629)
+++ trunk/docs/user-manual/en/embedding-hornetq.xml 2010-09-02 23:20:36 UTC (rev 9630)
@@ -1,4 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
+<!-- <!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.3CR3//EN"
+"../../../lib/docbook-support/support/docbook-dtd/docbookx.dtd"> -->
<!-- ============================================================================= -->
<!-- Copyright © 2009 Red Hat, Inc. and others. -->
<!-- -->
@@ -17,51 +19,37 @@
<!-- permitted by applicable law. -->
<!-- ============================================================================= -->
<chapter id="embedding-hornetq">
- <title>Embedding HornetQ</title>
- <para>HornetQ is designed as set of simple Plain Old Java Objects (POJOs). This means HornetQ
- can be instantiated and run in any dependency injection framework such as JBoss
- Microcontainer, Spring or Google Guice. It also means that if you have an application that
- could use messaging functionality internally, then it can <emphasis>directly
- instantiate</emphasis> HornetQ clients and servers in its own application code to
- perform that functionality. We call this <emphasis>embedding</emphasis> HornetQ.</para>
- <para>Examples of applications that might want to do this include any application that needs
- very high performance, transactional, persistent messaging but doesn't want the hassle of
- writing it all from scratch.</para>
- <para>Embedding HornetQ can be done in very few easy steps. Instantiate the configuration
- object, instantiate the server, start it, and you have a HornetQ running in your virtual
- machine. It's as simple and easy as that.</para>
- <section>
- <title>POJO instantiation</title>
- <para>You can follow this step-by-step guide:</para>
- <para>Create the configuration object - this contains configuration information for a
- HornetQ. If you want to configure it from a file on the classpath, use <literal
- >FileConfigurationImpl</literal></para>
- <programlisting>import org.hornetq.core.config.Configuration;
-import org.hornetq.core.config.impl.FileConfiguration;
+ <title>Embedding HornetQ</title>
-...
+ <para>HornetQ is designed as set of simple Plain Old Java Objects (POJOs).
+ This means HornetQ can be instantiated and run in any dependency injection
+ framework such as JBoss Microcontainer, Spring or Google Guice. It also
+ means that if you have an application that could use messaging functionality
+ internally, then it can <emphasis>directly instantiate</emphasis> HornetQ
+ clients and servers in its own application code to perform that
+ functionality. We call this <emphasis>embedding</emphasis> HornetQ.</para>
+ <para>Examples of applications that might want to do this include any
+ application that needs very high performance, transactional, persistent
+ messaging but doesn't want the hassle of writing it all from scratch.</para>
-Configuration config = new FileConfiguration();
-config.setConfigurationUrl(urlToYourconfigfile);
-config.start();</programlisting>
- <para>If you don't need to support a configuration file, just use <literal
- >ConfigurationImpl</literal> and change the config parameters accordingly, such as
- adding acceptors. </para>
- <para>The acceptors are configured through <literal>ConfigurationImpl</literal>. Just add
- the <literal>NettyAcceptorFactory</literal> on the transports the same way you would
- through the main configuration file.</para>
- <programlisting>import org.hornetq.core.config.Configuration;
-import org.hornetq.core.config.impl.ConfigurationImpl;
+ <para>Embedding HornetQ can be done in very few easy steps. Instantiate the
+ configuration object, instantiate the server, start it, and you have a
+ HornetQ running in your virtual machine. It's as simple and easy as
+ that.</para>
-...
+ <section>
+ <title>Simple Config File Embedding</title>
-Configuration config = new ConfigurationImpl();
-HashSet<TransportConfiguration> transports = new HashSet<TransportConfiguration>();
-
-transports.add(new TransportConfiguration(NettyAcceptorFactory.class.getName()));
-transports.add(new TransportConfiguration(InVMAcceptorFactory.class.getName()));
+ <para>The simplest way to embed HornetQ is to use the embedded wrapper
+ classes and configure HornetQ through its configuration files. There are
+ two different helper classes for this depending on whether your using the
+ HornetQ Core API or JMS.</para>
+<<<<<<< .mine
+ <section>
+ <title>Core API Only</title>
+=======
config.setAcceptorConfigurations(transports);</programlisting>
<para>You need to instantiate and start HornetQ server. The class <literal
>org.hornetq.api.core.server.HornetQ</literal> has a few static methods for creating
@@ -69,11 +57,25 @@
<programlisting>import org.hornetq.core.server.HornetQServer;
import org.hornetq.core.server.HornetQServers;
+>>>>>>> .r9629
+ <para>For instantiating a core HornetQ Server only, the steps are pretty
+ simple. The example requires that you have defined a configuration file
+ <literal>hornetq-configuration.xml</literal> in your
+ classpath:<programlisting>import org.hornetq.core.server.embedded.EmbeddedHornetQ;
+
...
+<<<<<<< .mine
+EmbeddedHornetQ embedded = new EmbeddedHornetQ();
+embedded.start();
+=======
HornetQServer server = HornetQServers.newHornetQServer(config);
+>>>>>>> .r9629
+<<<<<<< .mine
+// Assuming you defined an "in-vm" acceptor within your hornetq-configuration.xml file
+=======
server.start();</programlisting>
<para>You also have the option of instantiating <literal>HornetQServerImpl</literal>
directly:</para>
@@ -94,38 +96,9 @@
optional.</para>
<para>A very basic XML Bean declaration for the JBoss Micro Container would be:</para>
<programlisting><?xml version="1.0" encoding="UTF-8"?>
+>>>>>>> .r9629
-<deployment xmlns="urn:jboss:bean-deployer:2.0">
-
- <!-- The core configuration -->
- <bean name="Configuration"
- class="org.hornetq.core.config.impl.FileConfiguration">
- </bean>
-
- <!-- The core server -->
- <bean name="HornetQServer"
- class="org.hornetq.core.server.impl.HornetQServerImpl">
- <constructor>
- <parameter>
- <inject bean="Configuration"/>
- </parameter>
- </constructor>
- </bean>
- </deployment></programlisting>
- <para><literal>HornetQBootstrapServer</literal> provides an easy encapsulation of JBoss
- Micro Container.</para>
- <programlisting>HornetQBootstrapServer bootStrap =
- new HornetQBootstrapServer(new String[] {"hornetq-beans.xml"});
- bootStrap.run();</programlisting>
- </section>
- <section>
- <title>Connecting to the Embedded HornetQ</title>
- <para>To connect clients to HornetQ you just create the factories as normal:</para>
- <section>
- <title>Core API</title>
- <para>If using the core API, just create the <literal>ClientSessionFactory</literal> and
- use the regular core API.</para>
- <programlisting>ClientSessionFactory nettyFactory = HornetQClient.createClientSessionFactory(
+ClientSessionFactory nettyFactory = HornetQClient.createClientSessionFactory(
new TransportConfiguration(
InVMConnectorFactory.class.getName()));
@@ -149,45 +122,186 @@
System.out.println("message = " + msgReceived.getBody().readString());
-session.close();</programlisting>
- </section>
- <section>
- <title>JMS API</title>
- <para>Connection on an Embedded HornetQ through JMS is also simple. Just instantiate
- <literal>ConnectionFactory</literal> directly. The following example
- illustrates that.</para>
- <programlisting>ConnectionFactory cf =
- HornetQJMSClient.createConnectionFactory(
- new TransportConfiguration(InVMConnectorFactory.class.getName()));
+session.close();
+</programlisting><parameter>The <literal>EmbeddedHornetQ</literal> class has a
+ few additional setter methods that allow you to specify a different
+ config file name as well as other properties. See the javadocs for this
+ class for more details.</parameter></para>
+ </section>
-Connection conn = cf.createConnection();
+ <section id="simple.embedded.jms">
+ <title>JMS API</title>
-conn.start();
+ <para>JMS embedding is simple as well. This example requires that you
+ have defined the config files
+ <literal>hornetq-configuration.xml</literal>,
+ <literal>hornetq-jms.xml</literal>, and a
+ <literal>hornetq-users.xml</literal> if you have security enabled. Let's
+ also assume that a queue and connection factory has been defined in the
+ <literal>hornetq-jms.xml</literal> config file.<programlisting>import org.hornetq.jms.server.embedded.EmbeddedJMS;
-Session sess = conn.createSession(true, Session.SESSION_TRANSACTED);
+...
-MessageProducer prod = sess.createProducer(queue);
+EmbeddedJMS jms = new EmbeddedJMS();
+jms.start();
-TextMessage msg = sess.createTextMessage("Hello!");
+// This assumes we have configured hornetq-jms.xml with the appropriate config information
+ConnectionFactory connectionFactory = jms.lookup("ConnectionFactory");
+Destination destination = jms.lookup("/example/queue");
-prod.send(msg);
+... regular JMS code ...
-sess.commit();
-MessageConsumer consumer = sess.createConsumer(queue);
+</programlisting><parameter>By default, the <literal>EmbeddedJMS</literal>
+ class will store component entries defined within your
+ <literal>hornetq-jms.xml</literal> file in an internal concurrent hash
+ map. The <literal>EmbeddedJMS.lookup()</literal> method returns
+ components stored in this map. If you want to use JNDI, call the
+ <literal>EmbeddedJMS.setContext()</literal> method with the root JNDI
+ context you want your components bound into. See the javadocs for this
+ class for more details on other config options.</parameter></para>
+ </section>
+ </section>
-TextMessage txtmsg = (TextMessage)consumer.receive();
+ <section>
+ <title>POJO instantiation - Embedding Programmatically</title>
-System.out.println("Msg = " + txtmsg.getText());
+ <para>You can follow this step-by-step guide to programmatically embed the
+ core, non-JMS HornetQ Server instance:</para>
-sess.commit();
+ <para>Create the configuration object - this contains configuration
+ information for a HornetQ instance. The setter methods of this class allow
+ you to programmitcally set configuration options as describe in the <xref
+ linkend="server.configuration" /> section.</para>
-conn.close();</programlisting>
- </section>
- </section>
- <section>
- <title>JMS Embedding Example</title>
- <para>Please see <xref linkend="examples.embedded"/> for an example which shows how to setup
- and run HornetQ embedded with JMS.</para>
- </section>
+ <para>The acceptors are configured through
+ <literal>ConfigurationImpl</literal>. Just add the
+ <literal>NettyAcceptorFactory</literal> on the transports the same way you
+ would through the main configuration file.</para>
+
+ <programlisting>import org.hornetq.core.config.Configuration;
+import org.hornetq.core.config.impl.ConfigurationImpl;
+
+...
+
+Configuration config = new ConfigurationImpl();
+HashSet<TransportConfiguration> transports = new HashSet<TransportConfiguration>();
+
+transports.add(new TransportConfiguration(NettyAcceptorFactory.class.getName()));
+transports.add(new TransportConfiguration(InVMAcceptorFactory.class.getName()));
+
+config.setAcceptorConfigurations(transports);
+</programlisting>
+
+ <para>You need to instantiate an instance of
+ <literal>org.hornetq.api.core.server.embedded.EmbeddedHornetQ</literal>
+ and add the configuration object to it.</para>
+
+ <programlisting>import org.hornetq.api.core.server.HornetQ;
+import org.hornetq.core.server.embedded.EmbeddedHornetQ;
+
+...
+
+EmbeddedHornetQ server = new EmbeddedHornetQ();
+server.setConfiguration(config);
+
+server.start();</programlisting>
+
+ <para>You also have the option of instantiating
+ <literal>HornetQServerImpl</literal> directly:</para>
+
+ <programlisting>HornetQServer server =
+ new HornetQServerImpl(config);
+server.start();</programlisting>
+
+ <para>For JMS POJO instantiation, you work with the EmbeddedJMS class
+ instead as described earlier. First you define the configuration
+ programmatically for your ConnectionFactory and Destination objects, then
+ set the JmsConfiguration property of the EmbeddedJMS class. Here is an
+ example of this:</para>
+
+ <programlisting>
+// Step 1. Create HornetQ core configuration, and set the properties accordingly
+Configuration configuration = new ConfigurationImpl();
+configuration.setPersistenceEnabled(false);
+configuration.setSecurityEnabled(false);
+configuration.getAcceptorConfigurations()
+ .add(new TransportConfiguration(NettyAcceptorFactory.class.getName()));
+
+// Step 2. Create the JMS configuration
+JMSConfiguration jmsConfig = new JMSConfigurationImpl();
+
+// Step 3. Configure the JMS ConnectionFactory
+TransportConfiguration connectorConfig = new TransportConfiguration(NettyConnectorFactory.class.getName());
+ConnectionFactoryConfiguration cfConfig = new ConnectionFactoryConfigurationImpl("cf", connectorConfig, "/cf");
+jmsConfig.getConnectionFactoryConfigurations().add(cfConfig);
+
+// Step 4. Configure the JMS Queue
+JMSQueueConfiguration queueConfig = new JMSQueueConfigurationImpl("queue1", null, false, "/queue/queue1");
+jmsConfig.getQueueConfigurations().add(queueConfig);
+
+// Step 5. Start the JMS Server using the HornetQ core server and the JMS configuration
+EmbeddedJMS jmsServer = new EmbeddedJMS();
+jmsServer.setConfiguration(configuration);
+jmsServer.setJmsConfiguration(jmsConfig);
+jmsServer.start();</programlisting>
+
+ <para>Please see <xref linkend="examples.embedded.jms" /> for an example which
+ shows how to setup and run HornetQ embedded with JMS.</para>
+ </section>
+
+ <section>
+ <title>Dependency Frameworks</title>
+
+ <para>You may also choose to use a dependency injection framework such as
+ <trademark>JBoss Micro Container</trademark> or <trademark>Spring
+ Framework</trademark>. See <xref linkend="spring.integration" /> for more
+ details on Spring and HornetQ, but here's how you would do things with the
+ JBoss Micro Contaier.</para>
+
+ <para>HornetQ standalone uses JBoss Micro Container as the injection
+ framework. <literal>HornetQBootstrapServer</literal> and
+ <literal>hornetq-beans.xml</literal> which are part of the HornetQ
+ distribution provide a very complete implementation of what's needed to
+ bootstrap the server using JBoss Micro Container.</para>
+
+ <para>When using JBoss Micro Container, you need to provide an XML file
+ declaring the <literal>HornetQServer</literal> and
+ <literal>Configuration</literal> object, you can also inject a security
+ manager and a MBean server if you want, but those are optional.</para>
+
+ <para>A very basic XML Bean declaration for the JBoss Micro Container
+ would be:</para>
+
+ <programlisting><?xml version="1.0" encoding="UTF-8"?>
+
+<deployment xmlns="urn:jboss:bean-deployer:2.0">
+
+ <!-- The core configuration -->
+ <bean name="Configuration"
+ class="org.hornetq.core.config.impl.FileConfiguration">
+ </bean>
+
+ <!-- The core server -->
+ <bean name="HornetQServer"
+ class="org.hornetq.core.server.impl.HornetQServerImpl">
+ <constructor>
+ <parameter>
+ <inject bean="Configuration"/>
+ </parameter>
+ </constructor>
+ </bean>
+ </deployment></programlisting>
+
+ <para><literal>HornetQBootstrapServer</literal> provides an easy
+ encapsulation of JBoss Micro Container.</para>
+
+ <programlisting>HornetQBootstrapServer bootStrap =
+ new HornetQBootstrapServer(new String[] {"hornetq-beans.xml"});
+ bootStrap.run(</programlisting>
+ </section>
+
+ <section>
+ <para />
+ </section>
</chapter>
Modified: trunk/docs/user-manual/en/examples.xml
===================================================================
--- trunk/docs/user-manual/en/examples.xml 2010-09-02 11:58:21 UTC (rev 9629)
+++ trunk/docs/user-manual/en/examples.xml 2010-09-02 23:20:36 UTC (rev 9630)
@@ -161,10 +161,14 @@
Note that for the messages to be persisted, the messages sent to them must be marked
as durable messages. </para>
</section>
- <section>
+ <section id="examples.embedded.jms.simple">
+ <title>Embedded Simple</title>
+ <para>The <literal>embedded</literal> example shows how to embed JMS within your own code using regular HornetQ XML files.</para>
+ </section>
+ <section id="examples.embedded.jms">
<title>Embedded</title>
- <para>The <literal>embedded</literal> example shows how to embed the HornetQ server
- within your own code.</para>
+ <para>The <literal>embedded</literal> example shows how to embed JMS
+ within your own code using POJO instantiation and no config files.</para>
</section>
<section>
<title>HTTP Transport</title>
@@ -400,6 +404,10 @@
to obtain acknowledgement from the server that sends have been received and
processed in a separate stream to the sent messages. </para>
</section>
+ <section id="examples.jms.spring.integration">
+ <title>Spring Integration</title>
+ <para>This example shows how to use embedded JMS using HornetQ's Spring integration.</para>
+ </section>
<section>
<title>SSL Transport</title>
<para>The <literal>ssl-enabled</literal> shows you how to configure SSL with HornetQ to
@@ -507,7 +515,8 @@
directory and type <literal>ant</literal></para>
<section id="examples.embedded">
<title>Embedded</title>
- <para>This example shows how to embed the HornetQ server within your own code.</para>
+ <para>The <literal>embedded</literal> example shows how to embed the HornetQ server
+ within your own code.</para>
</section>
</section>
<section>
Modified: trunk/docs/user-manual/en/master.xml
===================================================================
--- trunk/docs/user-manual/en/master.xml 2010-09-02 11:58:21 UTC (rev 9629)
+++ trunk/docs/user-manual/en/master.xml 2010-09-02 23:20:36 UTC (rev 9630)
@@ -59,6 +59,7 @@
<!ENTITY scheduled-messages SYSTEM "scheduled-messages.xml">
<!ENTITY security SYSTEM "security.xml">
<!ENTITY send-guarantees SYSTEM "send-guarantees.xml">
+ <!ENTITY spring-integration SYSTEM "spring-integration.xml">
<!ENTITY thread-pooling SYSTEM "thread-pooling.xml">
<!ENTITY undelivered-messages SYSTEM "undelivered-messages.xml">
<!ENTITY using-core SYSTEM "using-core.xml">
@@ -119,6 +120,7 @@
&thread-pooling;
&logging;
&embedding-hornetq;
+ &spring-integration;
&intercepting-operations;
&interoperability;
&perf-tuning;
Added: trunk/docs/user-manual/en/spring-integration.xml
===================================================================
--- trunk/docs/user-manual/en/spring-integration.xml (rev 0)
+++ trunk/docs/user-manual/en/spring-integration.xml 2010-09-02 23:20:36 UTC (rev 9630)
@@ -0,0 +1,87 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- <!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.3CR3//EN"
+"../../../lib/docbook-support/support/docbook-dtd/docbookx.dtd"> -->
+<!-- ============================================================================= -->
+<!-- Copyright © 2009 Red Hat, Inc. and others. -->
+<!-- -->
+<!-- The text of and illustrations in this document are licensed by Red Hat under -->
+<!-- a Creative Commons Attribution–Share Alike 3.0 Unported license ("CC-BY-SA"). -->
+<!-- -->
+<!-- An explanation of CC-BY-SA is available at -->
+<!-- -->
+<!-- http://creativecommons.org/licenses/by-sa/3.0/. -->
+<!-- -->
+<!-- In accordance with CC-BY-SA, if you distribute this document or an adaptation -->
+<!-- of it, you must provide the URL for the original version. -->
+<!-- -->
+<!-- Red Hat, as the licensor of this document, waives the right to enforce, -->
+<!-- and agrees not to assert, Section 4d of CC-BY-SA to the fullest extent -->
+<!-- permitted by applicable law. -->
+<!-- ============================================================================= -->
+<chapter id="spring.integration">
+ <title>Spring Integration<parameter></parameter></title>
+
+ <para>HornetQ provides a simple bootstrap class,
+ <literal>org.hornetq.integration.spring.SpringJmsBootstrap</literal>, for
+ integration with Spring. To use it, you configure HornetQ as you always
+ would, through its various configuration files like
+ <literal>hornetq-configuration.xml</literal>,
+ <literal>hornetq-jms.xml</literal>, and
+ <literal>hornetq-users.xml</literal>. The Spring helper class starts the
+ HornetQ server and adds any factories or destinations configured within
+ <literal>hornetq-jms.xml</literal> directly into the namespace of the Spring
+ context. Let's take this <literal>hornetq-jms.xml</literal> file for
+ instance: <programlisting><configuration xmlns="urn:hornetq"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="urn:hornetq /schema/hornetq-jms.xsd">
+ <!--the connection factory used by the example-->
+ <connection-factory name="ConnectionFactory">
+ <connectors>
+ <connector-ref connector-name="in-vm"/>
+ </connectors>
+ <entries>
+ <entry name="ConnectionFactory"/>
+ </entries>
+ </connection-factory>
+
+ <!--the queue used by the example-->
+ <queue name="exampleQueue">
+ <entry name="/queue/exampleQueue"/>
+ </queue>
+
+</configuration>
+</programlisting>Here we've specified a
+ <literal>javax.jms.ConnectionFactory</literal> we want bound to a
+ <literal>ConnectionFactory</literal> entry as well as a queue destination
+ bound to a <literal>/queue/exampleQueue</literal> entry. Using the
+ <literal>SpringJmsBootStrap</literal> bean will automatically populate the
+ Spring context with references to those beans so that you can use them.
+ Below is an example Spring JMS bean file taking advantage of this
+ feature:<programlisting><beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://www.springframework.org/schema/beans
+ http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
+
+ <bean id="EmbeddedJms" class="org.hornetq.integration.spring.SpringJmsBootstrap" init-method="start"/>
+
+ <bean id="listener" class="org.hornetq.tests.integration.spring.ExampleListener"/>
+
+ <bean id="listenerContainer" class="org.springframework.jms.listener.DefaultMessageListenerContainer">
+ <property name="connectionFactory" ref="ConnectionFactory"/>
+ <property name="destination" ref="/queue/exampleQueue"/>
+ <property name="messageListener" ref="listener"/>
+ </bean>
+
+
+</beans>
+</programlisting>As you can see, the
+ <literal>listenerContainer</literal> bean references the components defined
+ in the <literal>hornetq-jms.xml</literal> file. The
+ <literal>SpringJmsBootstrap</literal> class extends the EmbeddedJMS class
+ talked about in <xref
+ linkend="simple.embedded.jms" /> and the same defaults and
+ configuration options apply. Also notice that an
+ <literal>init-method</literal> must be declared with a start value so that
+ the bean's lifecycle is executed. See the javadocs for more details on other
+ properties of the bean class.</para>
+</chapter>
14 years, 3 months
JBoss hornetq SVN: r9629 - branches/2_2_0_HA_Improvements/src/main/org/hornetq/core/server/impl.
by do-not-reply@jboss.org
Author: jmesnil
Date: 2010-09-02 07:58:21 -0400 (Thu, 02 Sep 2010)
New Revision: 9629
Modified:
branches/2_2_0_HA_Improvements/src/main/org/hornetq/core/server/impl/HornetQServerImpl.java
Log:
fix typo in log
Modified: branches/2_2_0_HA_Improvements/src/main/org/hornetq/core/server/impl/HornetQServerImpl.java
===================================================================
--- branches/2_2_0_HA_Improvements/src/main/org/hornetq/core/server/impl/HornetQServerImpl.java 2010-09-01 15:53:47 UTC (rev 9628)
+++ branches/2_2_0_HA_Improvements/src/main/org/hornetq/core/server/impl/HornetQServerImpl.java 2010-09-02 11:58:21 UTC (rev 9629)
@@ -578,7 +578,7 @@
clusterManager.start();
- log.info("Live server is up - waiting for failover");
+ log.info("Backup server is up - waiting for failover");
liveLock.lock();
//todo check if we need this or not
@@ -604,7 +604,7 @@
initialisePart2();
- log.info("Back Up Server is now live");
+ log.info("Backup Server is now live");
backupLock.unlock();
}
14 years, 3 months