JBoss hornetq SVN: r9960 - in branches/Branch_Large_Message_Compression: src/main/org/hornetq/utils and 2 other directories.
by do-not-reply@jboss.org
Author: gaohoward
Date: 2010-12-01 09:25:42 -0500 (Wed, 01 Dec 2010)
New Revision: 9960
Added:
branches/Branch_Large_Message_Compression/tests/src/org/hornetq/tests/unit/util/CompressionUtilTest.java
Modified:
branches/Branch_Large_Message_Compression/src/main/org/hornetq/core/client/impl/LargeMessageBufferImpl.java
branches/Branch_Large_Message_Compression/src/main/org/hornetq/utils/DecompressedLargeMessageBuffer.java
branches/Branch_Large_Message_Compression/src/main/org/hornetq/utils/DeflaterReader.java
branches/Branch_Large_Message_Compression/src/main/org/hornetq/utils/GZipUtil.java
branches/Branch_Large_Message_Compression/src/main/org/hornetq/utils/InflaterReader.java
branches/Branch_Large_Message_Compression/src/main/org/hornetq/utils/InflaterWriter.java
branches/Branch_Large_Message_Compression/tests/src/org/hornetq/tests/integration/client/LargeMessageCompressTest.java
branches/Branch_Large_Message_Compression/tests/src/org/hornetq/tests/integration/client/LargeMessageTest.java
Log:
cleanup and tests
Modified: branches/Branch_Large_Message_Compression/src/main/org/hornetq/core/client/impl/LargeMessageBufferImpl.java
===================================================================
--- branches/Branch_Large_Message_Compression/src/main/org/hornetq/core/client/impl/LargeMessageBufferImpl.java 2010-12-01 12:23:36 UTC (rev 9959)
+++ branches/Branch_Large_Message_Compression/src/main/org/hornetq/core/client/impl/LargeMessageBufferImpl.java 2010-12-01 14:25:42 UTC (rev 9960)
@@ -1257,7 +1257,6 @@
{
try
{
- System.err.println("___writing packet: " + packet + " output " + output);
output.write(packet.getBody());
if (!packet.isContinues())
{
Modified: branches/Branch_Large_Message_Compression/src/main/org/hornetq/utils/DecompressedLargeMessageBuffer.java
===================================================================
--- branches/Branch_Large_Message_Compression/src/main/org/hornetq/utils/DecompressedLargeMessageBuffer.java 2010-12-01 12:23:36 UTC (rev 9959)
+++ branches/Branch_Large_Message_Compression/src/main/org/hornetq/utils/DecompressedLargeMessageBuffer.java 2010-12-01 14:25:42 UTC (rev 9960)
@@ -17,8 +17,6 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
-import java.io.PipedInputStream;
-import java.io.PipedOutputStream;
import java.nio.ByteBuffer;
import java.nio.channels.GatheringByteChannel;
import java.nio.channels.ScatteringByteChannel;
@@ -28,7 +26,6 @@
import org.hornetq.api.core.HornetQBuffers;
import org.hornetq.api.core.HornetQException;
import org.hornetq.api.core.SimpleString;
-import org.hornetq.core.client.impl.LargeMessageBufferImpl;
import org.hornetq.core.client.impl.LargeMessageBufferInternal;
import org.hornetq.core.protocol.core.impl.wireformat.SessionReceiveContinuationMessage;
import org.jboss.netty.buffer.ChannelBuffer;
@@ -45,18 +42,15 @@
// Constants -----------------------------------------------------
- /**
- *
- */
private static final String OPERATION_NOT_SUPPORTED = "Operation not supported";
private static final String READ_ONLY_ERROR_MESSAGE = "This is a read-only buffer, setOperations are not supported";
// Attributes ----------------------------------------------------
-
final LargeMessageBufferInternal bufferDelegate;
+ private long readerIndex = 0;
// Static --------------------------------------------------------
// Constructors --------------------------------------------------
@@ -411,7 +405,6 @@
public int readerIndex()
{
- // TODO
return 0;
}
Modified: branches/Branch_Large_Message_Compression/src/main/org/hornetq/utils/DeflaterReader.java
===================================================================
--- branches/Branch_Large_Message_Compression/src/main/org/hornetq/utils/DeflaterReader.java 2010-12-01 12:23:36 UTC (rev 9959)
+++ branches/Branch_Large_Message_Compression/src/main/org/hornetq/utils/DeflaterReader.java 2010-12-01 14:25:42 UTC (rev 9960)
@@ -13,10 +13,8 @@
package org.hornetq.utils;
-import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
-import java.util.ArrayList;
import java.util.zip.Deflater;
/**
@@ -46,9 +44,9 @@
int n = read(buffer, 0, 1);
if (n == 1)
{
- return buffer[0];
+ return (int)buffer[0] & 0xFF;
}
- if (n == -1)
+ if (n == -1 || n == 0)
{
return -1;
}
@@ -86,19 +84,15 @@
{
deflater.end();
compressDone = true;
- read = -1;
break;
}
else if (deflater.needsInput())
{
- System.err.println("need input so read input");
// read some data from inputstream
int m = input.read(readBuffer);
- System.err.println("original data read: " + m);
+
if (m == -1)
{
- System.err.println("no more original data, finish deflater, now offset " + offset + " len " + len);
-
deflater.finish();
isFinished = true;
}
@@ -119,74 +113,8 @@
offset += n;
len -= n;
}
-
}
return read;
}
- public static void main(String[] args) throws IOException
- {
- String inputString = "blahblahblah??blahblahblahblahblah??blablahblah??blablahblah??bla";
- byte[] input = inputString.getBytes("UTF-8");
-
- ByteArrayInputStream inputStream = new ByteArrayInputStream(input);
-
- DeflaterReader reader = new DeflaterReader(inputStream);
-
-
- ArrayList<Integer> zipHolder = new ArrayList<Integer>();
- int b = reader.read();
-
- while (b != -1)
- {
- zipHolder.add(b);
- b = reader.read();
- }
-
- byte[] allCompressed = new byte[zipHolder.size()];
- for (int i = 0; i < allCompressed.length; i++)
- {
- allCompressed[i] = (byte) zipHolder.get(i).intValue();
- }
-
- System.err.println("compressed: " + getBytesString(allCompressed));
-
-/*
- byte[] buffer = new byte[7];
-
- int n = reader.read(buffer);
-
- System.err.println("first read: " + n);
-
- while (n != -1)
- {
- System.err.println("==>read n " + n + " values: " + getBytesString(buffer));
- n = reader.read(buffer);
- }
-*/
- System.err.println("compressed.");
-
- System.err.println("now verify");
-
- byte[] output = new byte[30];
- Deflater compresser = new Deflater();
- compresser.setInput(input);
- compresser.finish();
- int compressedDataLength = compresser.deflate(output);
- System.err.println("compress len: " + compressedDataLength);
- System.err.println("commpress data: " + getBytesString(output));
-
- }
-
- static String getBytesString(byte[] array)
- {
- StringBuffer bf = new StringBuffer();
- for (byte b : array)
- {
- int val = b & 0xFF;
- bf.append(val + " ");
- }
- return bf.toString();
- }
-
}
Modified: branches/Branch_Large_Message_Compression/src/main/org/hornetq/utils/GZipUtil.java
===================================================================
--- branches/Branch_Large_Message_Compression/src/main/org/hornetq/utils/GZipUtil.java 2010-12-01 12:23:36 UTC (rev 9959)
+++ branches/Branch_Large_Message_Compression/src/main/org/hornetq/utils/GZipUtil.java 2010-12-01 14:25:42 UTC (rev 9960)
@@ -34,6 +34,7 @@
*/
public class GZipUtil
{
+
public static InputStream createZipInputStream(InputStream input) throws HornetQException
{
try
Modified: branches/Branch_Large_Message_Compression/src/main/org/hornetq/utils/InflaterReader.java
===================================================================
--- branches/Branch_Large_Message_Compression/src/main/org/hornetq/utils/InflaterReader.java 2010-12-01 12:23:36 UTC (rev 9959)
+++ branches/Branch_Large_Message_Compression/src/main/org/hornetq/utils/InflaterReader.java 2010-12-01 14:25:42 UTC (rev 9960)
@@ -13,12 +13,9 @@
package org.hornetq.utils;
-import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
-import java.util.ArrayList;
import java.util.zip.DataFormatException;
-import java.util.zip.Deflater;
import java.util.zip.Inflater;
/**
@@ -50,30 +47,17 @@
this.pointer = -1;
}
- public static void log(String str)
- {
- System.out.println(str);
- }
-
public int read() throws IOException
{
- log("in read");
-
if (pointer == -1)
{
- log("pointer is -1");
-
try
{
- log("need to decompress more bytes");
length = doRead(readBuffer, 0, readBuffer.length);
- log("bytes decompressed:" + length);
if (length == 0)
{
- log("zero byte got, ending");
return -1;
}
- log("reset pointer to zero");
pointer = 0;
}
catch (DataFormatException e)
@@ -82,16 +66,13 @@
}
}
- log("reading byte at " + pointer);
int value = readBuffer[pointer] & 0xFF;
pointer++;
if (pointer == length)
{
- log("buffer all read, set pointer to -1");
pointer = -1;
}
- log("byte got: " + value);
return value;
}
@@ -153,44 +134,5 @@
}
return read;
}
-
- public static void main(String[] args) throws IOException
- {
- String inputString = "blahblahblah??blahblahblahblahblah??blablahblah??blablahblah??bla";
- byte[] input = inputString.getBytes("UTF-8");
- byte[] output = new byte[30];
- Deflater compresser = new Deflater();
- compresser.setInput(input);
- compresser.finish();
- int compressedDataLength = compresser.deflate(output);
- System.err.println("compress len: " + compressedDataLength);
- byte[] zipBytes = new byte[compressedDataLength];
-
- System.arraycopy(output, 0, zipBytes, 0, compressedDataLength);
- ByteArrayInputStream byteInput = new ByteArrayInputStream(zipBytes);
-
- InflaterReader inflater = new InflaterReader(byteInput);
- ArrayList<Integer> holder = new ArrayList<Integer>();
- int read = inflater.read();
-
- while (read != -1)
- {
- holder.add(read);
- read = inflater.read();
- }
-
- byte[] result = new byte[holder.size()];
-
- System.out.println("total bytes: " + holder.size());
- for (int i = 0; i < result.length; i++)
- {
- result[i] = holder.get(i).byteValue();
- }
-
- String txt = new String(result);
- System.out.println("the result: " + txt);
-
- }
-
}
Modified: branches/Branch_Large_Message_Compression/src/main/org/hornetq/utils/InflaterWriter.java
===================================================================
--- branches/Branch_Large_Message_Compression/src/main/org/hornetq/utils/InflaterWriter.java 2010-12-01 12:23:36 UTC (rev 9959)
+++ branches/Branch_Large_Message_Compression/src/main/org/hornetq/utils/InflaterWriter.java 2010-12-01 14:25:42 UTC (rev 9960)
@@ -47,11 +47,6 @@
{
this.output = output;
}
-
- private void log(String str)
- {
- System.err.println(this + " " + str);
- }
/*
* Write a compressed byte.
@@ -59,7 +54,6 @@
@Override
public void write(int b) throws IOException
{
- log("call write b: " + b);
writeBuffer[writePointer] = (byte)(b & 0xFF);
writePointer++;
@@ -68,7 +62,6 @@
writePointer = 0;
try
{
- log("call doWrite");
doWrite();
}
catch (DataFormatException e)
@@ -81,7 +74,6 @@
@Override
public void close() throws IOException
{
- log("call close");
if (writePointer > 0)
{
inflater.setInput(writeBuffer, 0, writePointer);
@@ -113,43 +105,5 @@
n = inflater.inflate(outputBuffer);
}
}
-
- public static void main(String[] args) throws IOException
- {
- String inputString = "blahblahblah??blahblahblahblahblah??blablahblah??blablahblah??bla";
- byte[] input = inputString.getBytes("UTF-8");
- byte[] output = new byte[30];
- Deflater compresser = new Deflater();
- compresser.setInput(input);
- compresser.finish();
- int compressedDataLength = compresser.deflate(output);
- System.err.println("compress len: " + compressedDataLength);
- byte[] zipBytes = new byte[compressedDataLength];
-
- System.arraycopy(output, 0, zipBytes, 0, compressedDataLength);
- ByteArrayInputStream byteInput = new ByteArrayInputStream(zipBytes);
-
- ByteArrayOutputStream byteOutput = new ByteArrayOutputStream();
- InflaterWriter writer = new InflaterWriter(byteOutput);
-
- byte[] zipBuffer = new byte[12];
-
- int n = byteInput.read(zipBuffer);
- while (n > 0)
- {
- System.out.println("Writing: " + n);
- writer.write(zipBuffer, 0, n);
- n = byteInput.read(zipBuffer);
- }
-
- writer.close();
-
- byte[] outcome = byteOutput.toByteArray();
- String outStr = new String(outcome);
-
- System.out.println("Outcome: " + outStr);
-
- }
-
}
Modified: branches/Branch_Large_Message_Compression/tests/src/org/hornetq/tests/integration/client/LargeMessageCompressTest.java
===================================================================
--- branches/Branch_Large_Message_Compression/tests/src/org/hornetq/tests/integration/client/LargeMessageCompressTest.java 2010-12-01 12:23:36 UTC (rev 9959)
+++ branches/Branch_Large_Message_Compression/tests/src/org/hornetq/tests/integration/client/LargeMessageCompressTest.java 2010-12-01 14:25:42 UTC (rev 9960)
@@ -25,12 +25,15 @@
import org.hornetq.api.core.Message;
import org.hornetq.api.core.SimpleString;
-import org.hornetq.api.core.client.*;
+import org.hornetq.api.core.client.ClientConsumer;
+import org.hornetq.api.core.client.ClientMessage;
+import org.hornetq.api.core.client.ClientProducer;
+import org.hornetq.api.core.client.ClientSession;
+import org.hornetq.api.core.client.ClientSessionFactory;
+import org.hornetq.api.core.client.HornetQClient;
import org.hornetq.core.client.impl.ClientConsumerInternal;
import org.hornetq.core.config.Configuration;
import org.hornetq.core.logging.Logger;
-import org.hornetq.core.persistence.impl.journal.JournalStorageManager;
-import org.hornetq.core.persistence.impl.journal.LargeServerMessageImpl;
import org.hornetq.core.server.HornetQServer;
import org.hornetq.core.server.Queue;
import org.hornetq.core.settings.impl.AddressSettings;
@@ -736,209 +739,6 @@
}
}
- public void testResendSmallStreamMessage() throws Exception
- {
- internalTestResendMessage(50000);
- }
-
- public void testResendLargeStreamMessage() throws Exception
- {
- internalTestResendMessage(150 * 1024);
- }
-
- public void internalTestResendMessage(final long messageSize) throws Exception
- {
- ClientSession session = null;
-
- try
- {
- server = createServer(true, isNetty());
-
- server.start();
-
- ClientSessionFactory sf = createFactory(isNetty());
- sf.setCompressLargeMessages(true);
-
- session = sf.createSession(false, false, false);
-
- session.createQueue(LargeMessageTest.ADDRESS, LargeMessageTest.ADDRESS, true);
-
- SimpleString ADDRESS2 = LargeMessageTest.ADDRESS.concat("-2");
-
- session.createQueue(ADDRESS2, ADDRESS2, true);
-
- ClientProducer producer = session.createProducer(LargeMessageTest.ADDRESS);
-
- ClientProducer producer2 = session.createProducer(ADDRESS2);
-
- Message clientFile = createLargeClientMessage(session, messageSize, false);
-
- producer.send(clientFile);
-
- session.commit();
-
- session.start();
-
- ClientConsumer consumer = session.createConsumer(LargeMessageTest.ADDRESS);
- ClientConsumer consumer2 = session.createConsumer(ADDRESS2);
-
- ClientMessage msg1 = consumer.receive(10000);
- msg1.acknowledge();
-
- producer2.send(msg1);
-
- boolean failed = false;
-
- try
- {
- producer2.send(msg1);
- }
- catch (Throwable e)
- {
- failed = true;
- }
-
- Assert.assertTrue("Exception expected", failed);
-
- session.commit();
-
- ClientMessage msg2 = consumer2.receive(10000);
-
- Assert.assertNotNull(msg2);
-
- msg2.acknowledge();
-
- session.commit();
-
- Assert.assertEquals(messageSize, msg2.getBodySize());
-
- compareString(messageSize, msg2);
-
- session.close();
-
- validateNoFilesOnLargeDir();
- }
- finally
- {
- try
- {
- server.stop();
- }
- catch (Throwable ignored)
- {
- }
-
- try
- {
- session.close();
- }
- catch (Throwable ignored)
- {
- }
- }
- }
-
- public void testResendCachedSmallStreamMessage() throws Exception
- {
- internalTestResendMessage(50000);
- }
-
- public void testResendCachedLargeStreamMessage() throws Exception
- {
- internalTestCachedResendMessage(150 * 1024);
- }
-
- public void internalTestCachedResendMessage(final long messageSize) throws Exception
- {
- ClientSession session = null;
-
- try
- {
- server = createServer(true, isNetty());
-
- server.start();
-
- ClientSessionFactory sf = createFactory(isNetty());
- sf.setCompressLargeMessages(true);
-
- sf.setMinLargeMessageSize(111);
-
- sf.setCacheLargeMessagesClient(true);
-
- session = sf.createSession(false, false, false);
-
- session.createQueue(LargeMessageTest.ADDRESS, LargeMessageTest.ADDRESS, true);
-
- ClientProducer producer = session.createProducer(LargeMessageTest.ADDRESS);
-
- Message originalMsg = createLargeClientMessage(session, messageSize, false);
-
- producer.send(originalMsg);
-
- session.commit();
-
- ClientConsumer consumer = session.createConsumer(LargeMessageTest.ADDRESS);
-
- session.start();
-
- ClientMessage msgReceived = consumer.receive(10000);
- msgReceived.acknowledge();
-
- session.commit();
-
- compareString(messageSize, msgReceived);
-
- msgReceived.getBodyBuffer().readerIndex(0);
-
- producer.send(msgReceived);
-
- session.commit();
-
- ClientMessage msgReceived2 = consumer.receive(10000);
-
- msgReceived2.acknowledge();
-
- compareString(messageSize, msgReceived2);
-
- session.commit();
-
- session.close();
-
- validateNoFilesOnLargeDir();
- }
- finally
- {
- try
- {
- server.stop();
- }
- catch (Throwable ignored)
- {
- }
-
- try
- {
- session.close();
- }
- catch (Throwable ignored)
- {
- }
- }
- }
-
- /**
- * @param messageSize
- * @param msg2
- */
- private void compareString(final long messageSize, ClientMessage msg)
- {
- assertNotNull(msg);
- for (long i = 0; i < messageSize; i++)
- {
- Assert.assertEquals("position " + i, UnitTestCase.getSamplebyte(i), msg.getBodyBuffer().readByte());
- }
- }
-
public void testFilePersistenceOneHugeMessage() throws Exception
{
testChunks(false,
@@ -2028,149 +1828,6 @@
}
- public void testSimpleRollback() throws Exception
- {
- simpleRollbackInternalTest(false);
- }
-
- public void testSimpleRollbackXA() throws Exception
- {
- simpleRollbackInternalTest(true);
- }
-
- public void simpleRollbackInternalTest(final boolean isXA) throws Exception
- {
- // there are two bindings.. one is ACKed, the other is not, the server is restarted
- // The other binding is acked... The file must be deleted
-
- try
- {
-
- server = createServer(true, isNetty());
-
- server.start();
-
- ClientSessionFactory sf = createFactory(isNetty());
- sf.setCompressLargeMessages(true);
-
- ClientSession session = sf.createSession(isXA, false, false);
-
- Xid xid = null;
-
- if (isXA)
- {
- xid = newXID();
- session.start(xid, XAResource.TMNOFLAGS);
- }
-
- session.createQueue(LargeMessageTest.ADDRESS, LargeMessageTest.ADDRESS, null, true);
-
- int numberOfBytes = 200000;
-
- session.start();
-
- ClientProducer producer = session.createProducer(LargeMessageTest.ADDRESS);
-
- ClientConsumer consumer = session.createConsumer(LargeMessageTest.ADDRESS);
-
- for (int n = 0; n < 10; n++)
- {
- Message clientFile = createLargeClientMessage(session, numberOfBytes, n % 2 == 0);
-
- producer.send(clientFile);
-
- Assert.assertNull(consumer.receiveImmediate());
-
- if (isXA)
- {
- session.end(xid, XAResource.TMSUCCESS);
- session.rollback(xid);
- xid = newXID();
- session.start(xid, XAResource.TMNOFLAGS);
- }
- else
- {
- session.rollback();
- }
-
- clientFile = createLargeClientMessage(session, numberOfBytes, n % 2 == 0);
-
- producer.send(clientFile);
-
- Assert.assertNull(consumer.receiveImmediate());
-
- if (isXA)
- {
- session.end(xid, XAResource.TMSUCCESS);
- session.commit(xid, true);
- xid = newXID();
- session.start(xid, XAResource.TMNOFLAGS);
- }
- else
- {
- session.commit();
- }
-
- for (int i = 0; i < 2; i++)
- {
-
- ClientMessage clientMessage = consumer.receive(5000);
-
- Assert.assertNotNull(clientMessage);
-
- Assert.assertEquals(numberOfBytes, clientMessage.getBodyBuffer().writerIndex());
-
- clientMessage.acknowledge();
-
- if (isXA)
- {
- if (i == 0)
- {
- session.end(xid, XAResource.TMSUCCESS);
- session.prepare(xid);
- session.rollback(xid);
- xid = newXID();
- session.start(xid, XAResource.TMNOFLAGS);
- }
- else
- {
- session.end(xid, XAResource.TMSUCCESS);
- session.commit(xid, true);
- xid = newXID();
- session.start(xid, XAResource.TMNOFLAGS);
- }
- }
- else
- {
- if (i == 0)
- {
- session.rollback();
- }
- else
- {
- session.commit();
- }
- }
- }
- }
-
- session.close();
-
- validateNoFilesOnLargeDir();
- }
- finally
- {
- try
- {
- server.stop();
- }
- catch (Throwable ignored)
- {
- }
- }
-
- }
-
public void testBufferMultipleLargeMessages() throws Exception
{
ClientSession session = null;
@@ -2540,68 +2197,7 @@
}
}
- // The ClientConsumer should be able to also send ServerLargeMessages as that's done by the CoreBridge
- public void testSendServerMessage() throws Exception
- {
- HornetQServer server = createServer(true);
- server.start();
-
- ClientSessionFactory sf = createFactory(false);
- sf.setCompressLargeMessages(true);
-
- ClientSession session = sf.createSession(false, false);
-
- try
- {
- LargeServerMessageImpl fileMessage = new LargeServerMessageImpl((JournalStorageManager)server.getStorageManager());
-
- fileMessage.setMessageID(1005);
-
- for (int i = 0; i < LARGE_MESSAGE_SIZE; i++)
- {
- fileMessage.addBytes(new byte[] { UnitTestCase.getSamplebyte(i) });
- }
-
- fileMessage.releaseResources();
-
- session.createQueue(LargeMessageTest.ADDRESS, LargeMessageTest.ADDRESS, true);
-
- ClientProducer prod = session.createProducer(LargeMessageTest.ADDRESS);
-
- prod.send(fileMessage);
-
- fileMessage.deleteFile();
-
- session.commit();
-
- session.start();
-
- ClientConsumer cons = session.createConsumer(LargeMessageTest.ADDRESS);
-
- ClientMessage msg = cons.receive(5000);
-
- Assert.assertNotNull(msg);
-
- Assert.assertEquals(msg.getBodySize(), LARGE_MESSAGE_SIZE);
-
- for (int i = 0; i < LARGE_MESSAGE_SIZE; i++)
- {
- Assert.assertEquals(UnitTestCase.getSamplebyte(i), msg.getBodyBuffer().readByte());
- }
-
- msg.acknowledge();
-
- session.commit();
-
- }
- finally
- {
- sf.close();
- server.stop();
- }
- }
-
public void testLargeMessageCompression() throws Exception
{
final int messageSize = (int)(3.5 * HornetQClient.DEFAULT_MIN_LARGE_MESSAGE_SIZE);
Modified: branches/Branch_Large_Message_Compression/tests/src/org/hornetq/tests/integration/client/LargeMessageTest.java
===================================================================
--- branches/Branch_Large_Message_Compression/tests/src/org/hornetq/tests/integration/client/LargeMessageTest.java 2010-12-01 12:23:36 UTC (rev 9959)
+++ branches/Branch_Large_Message_Compression/tests/src/org/hornetq/tests/integration/client/LargeMessageTest.java 2010-12-01 14:25:42 UTC (rev 9960)
@@ -887,6 +887,7 @@
}
catch (Throwable e)
{
+ log.error("failed", e);
failed = true;
}
Added: branches/Branch_Large_Message_Compression/tests/src/org/hornetq/tests/unit/util/CompressionUtilTest.java
===================================================================
--- branches/Branch_Large_Message_Compression/tests/src/org/hornetq/tests/unit/util/CompressionUtilTest.java (rev 0)
+++ branches/Branch_Large_Message_Compression/tests/src/org/hornetq/tests/unit/util/CompressionUtilTest.java 2010-12-01 14:25:42 UTC (rev 9960)
@@ -0,0 +1,185 @@
+/*
+ * 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.tests.unit.util;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.util.ArrayList;
+import java.util.zip.Deflater;
+
+import org.hornetq.tests.util.UnitTestCase;
+import org.hornetq.utils.DeflaterReader;
+import org.hornetq.utils.InflaterReader;
+import org.hornetq.utils.InflaterWriter;
+
+/**
+ * A CompressionUtilTest
+ *
+ * @author <a href="mailto:hgao@redhat.com">Howard Gao</a>
+ *
+ */
+public class CompressionUtilTest extends UnitTestCase
+{
+
+ public void testDeflaterReader() throws Exception
+ {
+ String inputString = "blahblahblah??blahblahblahblahblah??blablahblah??blablahblah??bla";
+ byte[] input = inputString.getBytes("UTF-8");
+
+ ByteArrayInputStream inputStream = new ByteArrayInputStream(input);
+
+ DeflaterReader reader = new DeflaterReader(inputStream);
+
+ ArrayList<Integer> zipHolder = new ArrayList<Integer>();
+ int b = reader.read();
+
+ while (b != -1)
+ {
+ zipHolder.add(b);
+ b = reader.read();
+ }
+
+ byte[] allCompressed = new byte[zipHolder.size()];
+ for (int i = 0; i < allCompressed.length; i++)
+ {
+ allCompressed[i] = (byte) zipHolder.get(i).intValue();
+ }
+
+ byte[] output = new byte[30];
+ Deflater compresser = new Deflater();
+ compresser.setInput(input);
+ compresser.finish();
+ int compressedDataLength = compresser.deflate(output);
+
+ compareByteArray(allCompressed, output, compressedDataLength);
+ }
+
+ public void testDeflaterReader2() throws Exception
+ {
+ String inputString = "blahblahblah??blahblahblahblahblah??blablahblah??blablahblah??bla";
+ byte[] input = inputString.getBytes("UTF-8");
+
+ ByteArrayInputStream inputStream = new ByteArrayInputStream(input);
+
+ DeflaterReader reader = new DeflaterReader(inputStream);
+
+ byte[] buffer = new byte[7];
+ ArrayList<Integer> zipHolder = new ArrayList<Integer>();
+
+ int n = reader.read(buffer);
+ while (n != -1)
+ {
+ for (int i = 0; i < n; i++)
+ {
+ zipHolder.add((int)buffer[i]);
+ }
+ n = reader.read(buffer);
+ }
+
+ byte[] allCompressed = new byte[zipHolder.size()];
+ for (int i = 0; i < allCompressed.length; i++)
+ {
+ allCompressed[i] = (byte) zipHolder.get(i).intValue();
+ }
+
+ byte[] output = new byte[30];
+ Deflater compresser = new Deflater();
+ compresser.setInput(input);
+ compresser.finish();
+ int compressedDataLength = compresser.deflate(output);
+
+ compareByteArray(allCompressed, output, compressedDataLength);
+ }
+
+ public void testInflaterReader() throws Exception
+ {
+ String inputString = "blahblahblah??blahblahblahblahblah??blablahblah??blablahblah??bla";
+ byte[] input = inputString.getBytes("UTF-8");
+ byte[] output = new byte[30];
+ Deflater compresser = new Deflater();
+ compresser.setInput(input);
+ compresser.finish();
+ int compressedDataLength = compresser.deflate(output);
+
+ byte[] zipBytes = new byte[compressedDataLength];
+
+ System.arraycopy(output, 0, zipBytes, 0, compressedDataLength);
+ ByteArrayInputStream byteInput = new ByteArrayInputStream(zipBytes);
+
+ InflaterReader inflater = new InflaterReader(byteInput);
+ ArrayList<Integer> holder = new ArrayList<Integer>();
+ int read = inflater.read();
+
+ while (read != -1)
+ {
+ holder.add(read);
+ read = inflater.read();
+ }
+
+ byte[] result = new byte[holder.size()];
+
+ for (int i = 0; i < result.length; i++)
+ {
+ result[i] = holder.get(i).byteValue();
+ }
+
+ String txt = new String(result);
+
+ assertEquals(inputString, txt);
+
+ }
+
+ public void testInflaterWriter() throws Exception
+ {
+ String inputString = "blahblahblah??blahblahblahblahblah??blablahblah??blablahblah??bla";
+ byte[] input = inputString.getBytes("UTF-8");
+ byte[] output = new byte[30];
+ Deflater compresser = new Deflater();
+ compresser.setInput(input);
+ compresser.finish();
+ int compressedDataLength = compresser.deflate(output);
+
+ byte[] zipBytes = new byte[compressedDataLength];
+
+ System.arraycopy(output, 0, zipBytes, 0, compressedDataLength);
+ ByteArrayInputStream byteInput = new ByteArrayInputStream(zipBytes);
+
+ ByteArrayOutputStream byteOutput = new ByteArrayOutputStream();
+ InflaterWriter writer = new InflaterWriter(byteOutput);
+
+ byte[] zipBuffer = new byte[12];
+
+ int n = byteInput.read(zipBuffer);
+ while (n > 0)
+ {
+ writer.write(zipBuffer, 0, n);
+ n = byteInput.read(zipBuffer);
+ }
+
+ writer.close();
+
+ byte[] outcome = byteOutput.toByteArray();
+ String outStr = new String(outcome);
+
+ assertEquals(inputString, outStr);
+ }
+
+ private void compareByteArray(byte[] first, byte[] second, int length)
+ {
+ for (int i = 0; i < length; i++)
+ {
+ assertEquals(first[i], second[i]);
+ }
+ }
+}
15 years, 5 months
JBoss hornetq SVN: r9959 - in trunk/examples: jms and 9 other directories.
by do-not-reply@jboss.org
Author: ataylor
Date: 2010-12-01 07:23:36 -0500 (Wed, 01 Dec 2010)
New Revision: 9959
Added:
trunk/examples/jms/multiple-failover-failback/
trunk/examples/jms/multiple-failover-failback/build.bat
trunk/examples/jms/multiple-failover-failback/build.sh
trunk/examples/jms/multiple-failover-failback/build.xml
trunk/examples/jms/multiple-failover-failback/server0/
trunk/examples/jms/multiple-failover-failback/server0/client-jndi.properties
trunk/examples/jms/multiple-failover-failback/server0/hornetq-beans.xml
trunk/examples/jms/multiple-failover-failback/server0/hornetq-configuration.xml
trunk/examples/jms/multiple-failover-failback/server0/hornetq-jms.xml
trunk/examples/jms/multiple-failover-failback/server0/hornetq-users.xml
trunk/examples/jms/multiple-failover-failback/server1/
trunk/examples/jms/multiple-failover-failback/server1/client-jndi.properties
trunk/examples/jms/multiple-failover-failback/server1/hornetq-beans.xml
trunk/examples/jms/multiple-failover-failback/server1/hornetq-configuration.xml
trunk/examples/jms/multiple-failover-failback/server1/hornetq-jms.xml
trunk/examples/jms/multiple-failover-failback/server1/hornetq-users.xml
trunk/examples/jms/multiple-failover-failback/server2/
trunk/examples/jms/multiple-failover-failback/server2/client-jndi.properties
trunk/examples/jms/multiple-failover-failback/server2/hornetq-beans.xml
trunk/examples/jms/multiple-failover-failback/server2/hornetq-configuration.xml
trunk/examples/jms/multiple-failover-failback/server2/hornetq-jms.xml
trunk/examples/jms/multiple-failover-failback/server2/hornetq-users.xml
trunk/examples/jms/multiple-failover-failback/src/
trunk/examples/jms/multiple-failover-failback/src/org/
trunk/examples/jms/multiple-failover-failback/src/org/hornetq/
trunk/examples/jms/multiple-failover-failback/src/org/hornetq/jms/
trunk/examples/jms/multiple-failover-failback/src/org/hornetq/jms/example/
trunk/examples/jms/multiple-failover-failback/src/org/hornetq/jms/example/MultipleFailoverFailbackExample.java
Modified:
trunk/examples/common/src/org/hornetq/common/example/HornetQExample.java
Log:
added failback example
Modified: trunk/examples/common/src/org/hornetq/common/example/HornetQExample.java
===================================================================
--- trunk/examples/common/src/org/hornetq/common/example/HornetQExample.java 2010-12-01 11:00:36 UTC (rev 9958)
+++ trunk/examples/common/src/org/hornetq/common/example/HornetQExample.java 2010-12-01 12:23:36 UTC (rev 9959)
@@ -158,6 +158,26 @@
"hornetq-beans.xml");
}
+ protected void reStartServer(final int index) throws Exception
+ {
+ String config = configs[index];
+ HornetQExample.log.info("starting server with config '" + config + "' " + "logServerOutput " + logServerOutput);
+ File f = new File(config + "/KILL_ME");
+ f.delete();
+ String debugProp = System.getProperty("server" + index);
+ boolean debugServer= "true".equals(debugProp);
+ servers[index] = SpawnedVMSupport.spawnVM(serverClasspath,
+ "HornetQServer_" + index,
+ SpawnedHornetQServer.class.getName(),
+ serverProps,
+ logServerOutput,
+ "STARTED::",
+ "FAILED::",
+ config,
+ debugServer,
+ "hornetq-beans.xml");
+ }
+
protected void startServers() throws Exception
{
servers = new Process[configs.length];
Copied: trunk/examples/jms/multiple-failover-failback/build.bat (from rev 9955, trunk/examples/jms/multiple-failover/build.bat)
===================================================================
--- trunk/examples/jms/multiple-failover-failback/build.bat (rev 0)
+++ trunk/examples/jms/multiple-failover-failback/build.bat 2010-12-01 12:23:36 UTC (rev 9959)
@@ -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="
Copied: trunk/examples/jms/multiple-failover-failback/build.sh (from rev 9955, trunk/examples/jms/multiple-failover/build.sh)
===================================================================
--- trunk/examples/jms/multiple-failover-failback/build.sh (rev 0)
+++ trunk/examples/jms/multiple-failover-failback/build.sh 2010-12-01 12:23:36 UTC (rev 9959)
@@ -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
+
+
+
Copied: trunk/examples/jms/multiple-failover-failback/build.xml (from rev 9955, trunk/examples/jms/multiple-failover/build.xml)
===================================================================
--- trunk/examples/jms/multiple-failover-failback/build.xml (rev 0)
+++ trunk/examples/jms/multiple-failover-failback/build.xml 2010-12-01 12:23:36 UTC (rev 9959)
@@ -0,0 +1,43 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ 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.
+ -->
+
+<!DOCTYPE project [
+ <!ENTITY libraries SYSTEM "../../../thirdparty/libraries.ent">
+ ]>
+
+<project default="run" name="HornetQ JMS Non-transaction Multiple Failover Example">
+
+ <import file="../../common/build.xml"/>
+
+ <target name="run" depends="delete-files">
+ <antcall target="runExample">
+ <param name="example.classname" value="org.hornetq.jms.example.MultipleFailoverFailbackExample"/>
+ <param name="hornetq.example.beans.file" value="server0 server1 server2"/>
+ </antcall>
+ </target>
+
+ <target name="runRemote" depends="delete-files">
+ <antcall target="runExample">
+ <param name="example.classname" value="org.hornetq.jms.example.MultipleFailoverFailbackExample"/>
+ <param name="hornetq.example.runServer" value="false"/>
+ </antcall>
+ </target>
+
+ <target name="delete-files" depends="clean">
+ <delete file="./server0/KILL_ME"/>
+ <delete file="./server1/KILL_ME"/>
+ <delete file="./server2/KILL_ME"/>
+ </target>
+
+</project>
Added: trunk/examples/jms/multiple-failover-failback/server0/client-jndi.properties
===================================================================
--- trunk/examples/jms/multiple-failover-failback/server0/client-jndi.properties (rev 0)
+++ trunk/examples/jms/multiple-failover-failback/server0/client-jndi.properties 2010-12-01 12:23:36 UTC (rev 9959)
@@ -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: trunk/examples/jms/multiple-failover-failback/server0/hornetq-beans.xml
===================================================================
--- trunk/examples/jms/multiple-failover-failback/server0/hornetq-beans.xml (rev 0)
+++ trunk/examples/jms/multiple-failover-failback/server0/hornetq-beans.xml 2010-12-01 12:23:36 UTC (rev 9959)
@@ -0,0 +1,72 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+ ~ 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.
+ -->
+
+<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: trunk/examples/jms/multiple-failover-failback/server0/hornetq-configuration.xml
===================================================================
--- trunk/examples/jms/multiple-failover-failback/server0/hornetq-configuration.xml (rev 0)
+++ trunk/examples/jms/multiple-failover-failback/server0/hornetq-configuration.xml 2010-12-01 12:23:36 UTC (rev 9959)
@@ -0,0 +1,78 @@
+<!--
+ ~ 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.
+ -->
+
+<configuration xmlns="urn:hornetq"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="urn:hornetq /schema/hornetq-configuration.xsd">
+
+ <clustered>true</clustered>
+
+ <shared-store>true</shared-store>
+
+ <allow-failback>true</allow-failback>
+ <!-- Connectors -->
+
+ <connectors>
+ <connector name="netty-connector">
+ <factory-class>org.hornetq.core.remoting.impl.netty.NettyConnectorFactory</factory-class>
+ <param key="port" value="5445"/>
+ </connector>
+ </connectors>
+
+ <!-- Acceptors -->
+ <acceptors>
+ <acceptor name="netty-acceptor">
+ <factory-class>org.hornetq.core.remoting.impl.netty.NettyAcceptorFactory</factory-class>
+ <param key="port" value="5445"/>
+ </acceptor>
+ </acceptors>
+
+ <broadcast-groups>
+ <broadcast-group name="bg-group1">
+ <group-address>231.7.7.7</group-address>
+ <group-port>9876</group-port>
+ <broadcast-period>1000</broadcast-period>
+ <connector-ref>netty-connector</connector-ref>
+ </broadcast-group>
+ </broadcast-groups>
+
+ <discovery-groups>
+ <discovery-group name="dg-group1">
+ <group-address>231.7.7.7</group-address>
+ <group-port>9876</group-port>
+ <refresh-timeout>60000</refresh-timeout>
+ </discovery-group>
+ </discovery-groups>
+
+ <cluster-connections>
+ <cluster-connection name="my-cluster">
+ <address>jms</address>
+ <connector-ref>netty-connector</connector-ref>
+ <discovery-group-ref discovery-group-name="dg-group1"/>
+ </cluster-connection>
+ </cluster-connections>
+ <!-- Other config -->
+
+ <security-settings>
+ <!--security for example queue-->
+ <security-setting match="jms.queue.exampleQueue">
+ <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/multiple-failover-failback/server0/hornetq-jms.xml
===================================================================
--- trunk/examples/jms/multiple-failover-failback/server0/hornetq-jms.xml (rev 0)
+++ trunk/examples/jms/multiple-failover-failback/server0/hornetq-jms.xml 2010-12-01 12:23:36 UTC (rev 9959)
@@ -0,0 +1,33 @@
+<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>
+
+ <entries>
+ <entry name="ConnectionFactory"/>
+ </entries>
+
+ <ha>true</ha>
+ <!-- Pause 1 second between connect attempts -->
+ <retry-interval>1000</retry-interval>
+
+ <!-- Multiply subsequent reconnect pauses by this multiplier. This can be used to
+ implement an exponential back-off. For our purposes we just set to 1.0 so each reconnect
+ pause is the same length -->
+ <retry-interval-multiplier>1.0</retry-interval-multiplier>
+
+ <!-- Try reconnecting an unlimited number of times (-1 means "unlimited") -->
+ <reconnect-attempts>-1</reconnect-attempts>
+
+ </connection-factory>
+
+ <!--the queue used by the example-->
+ <queue name="exampleQueue">
+ <entry name="/queue/exampleQueue"/>
+ </queue>
+
+</configuration>
Added: trunk/examples/jms/multiple-failover-failback/server0/hornetq-users.xml
===================================================================
--- trunk/examples/jms/multiple-failover-failback/server0/hornetq-users.xml (rev 0)
+++ trunk/examples/jms/multiple-failover-failback/server0/hornetq-users.xml 2010-12-01 12:23:36 UTC (rev 9959)
@@ -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/multiple-failover-failback/server1/client-jndi.properties
===================================================================
--- trunk/examples/jms/multiple-failover-failback/server1/client-jndi.properties (rev 0)
+++ trunk/examples/jms/multiple-failover-failback/server1/client-jndi.properties 2010-12-01 12:23:36 UTC (rev 9959)
@@ -0,0 +1,3 @@
+java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
+java.naming.provider.url=jnp://localhost:2099
+java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces
Added: trunk/examples/jms/multiple-failover-failback/server1/hornetq-beans.xml
===================================================================
--- trunk/examples/jms/multiple-failover-failback/server1/hornetq-beans.xml (rev 0)
+++ trunk/examples/jms/multiple-failover-failback/server1/hornetq-beans.xml 2010-12-01 12:23:36 UTC (rev 9959)
@@ -0,0 +1,72 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+ ~ 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.
+ -->
+
+<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">2099</property>
+ <property name="bindAddress">localhost</property>
+ <property name="rmiPort">2098</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: trunk/examples/jms/multiple-failover-failback/server1/hornetq-configuration.xml
===================================================================
--- trunk/examples/jms/multiple-failover-failback/server1/hornetq-configuration.xml (rev 0)
+++ trunk/examples/jms/multiple-failover-failback/server1/hornetq-configuration.xml 2010-12-01 12:23:36 UTC (rev 9959)
@@ -0,0 +1,86 @@
+<!--
+ ~ 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.
+ -->
+
+<configuration xmlns="urn:hornetq"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="urn:hornetq ../../../src/schema/hornetq-configuration.xsd">
+
+ <clustered>true</clustered>
+
+ <backup>true</backup>
+
+ <shared-store>true</shared-store>
+
+ <allow-failback>true</allow-failback>
+
+ <!-- Connectors -->
+
+ <connectors>
+ <connector name="netty-connector">
+ <factory-class>org.hornetq.core.remoting.impl.netty.NettyConnectorFactory</factory-class>
+ <param key="port" value="5446"/>
+ </connector>
+ </connectors>
+
+ <!-- Acceptors -->
+ <acceptors>
+ <acceptor name="netty-acceptor">
+ <factory-class>org.hornetq.core.remoting.impl.netty.NettyAcceptorFactory</factory-class>
+ <param key="port" value="5446"/>
+ </acceptor>
+ </acceptors>
+
+ <broadcast-groups>
+ <broadcast-group name="bg-group1">
+ <group-address>231.7.7.7</group-address>
+ <group-port>9876</group-port>
+ <broadcast-period>1000</broadcast-period>
+ <connector-ref>netty-connector</connector-ref>
+ </broadcast-group>
+ </broadcast-groups>
+
+ <discovery-groups>
+ <discovery-group name="dg-group1">
+ <group-address>231.7.7.7</group-address>
+ <group-port>9876</group-port>
+ <refresh-timeout>60000</refresh-timeout>
+ </discovery-group>
+ </discovery-groups>
+
+ <cluster-connections>
+ <cluster-connection name="my-cluster">
+ <address>jms</address>
+ <connector-ref>netty-connector</connector-ref>
+ <discovery-group-ref discovery-group-name="dg-group1"/>
+ </cluster-connection>
+ </cluster-connections>
+ <!-- Other config -->
+
+ <large-messages-directory>../server0/data/large-messages</large-messages-directory>
+ <bindings-directory>../server0/data/bindings</bindings-directory>
+ <journal-directory>../server0/data/journal</journal-directory>
+ <paging-directory>../server0/data/paging</paging-directory>
+
+ <security-settings>
+ <!--security for example queue-->
+ <security-setting match="jms.queue.exampleQueue">
+ <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/multiple-failover-failback/server1/hornetq-jms.xml
===================================================================
--- trunk/examples/jms/multiple-failover-failback/server1/hornetq-jms.xml (rev 0)
+++ trunk/examples/jms/multiple-failover-failback/server1/hornetq-jms.xml 2010-12-01 12:23:36 UTC (rev 9959)
@@ -0,0 +1,32 @@
+<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>
+
+ <entries>
+ <entry name="ConnectionFactory"/>
+ </entries>
+
+ <ha>true</ha>
+ <!-- Pause 1 second between connect attempts -->
+ <retry-interval>1000</retry-interval>
+
+ <!-- Multiply subsequent reconnect pauses by this multiplier. This can be used to
+ implement an exponential back-off. For our purposes we just set to 1.0 so each reconnect
+ pause is the same length -->
+ <retry-interval-multiplier>1.0</retry-interval-multiplier>
+
+ <!-- Try reconnecting an unlimited number of times (-1 means "unlimited") -->
+ <reconnect-attempts>-1</reconnect-attempts>
+ </connection-factory>
+
+ <!--the queue used by the example-->
+ <queue name="exampleQueue">
+ <entry name="/queue/exampleQueue"/>
+ </queue>
+
+</configuration>
Added: trunk/examples/jms/multiple-failover-failback/server1/hornetq-users.xml
===================================================================
--- trunk/examples/jms/multiple-failover-failback/server1/hornetq-users.xml (rev 0)
+++ trunk/examples/jms/multiple-failover-failback/server1/hornetq-users.xml 2010-12-01 12:23:36 UTC (rev 9959)
@@ -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/multiple-failover-failback/server2/client-jndi.properties
===================================================================
--- trunk/examples/jms/multiple-failover-failback/server2/client-jndi.properties (rev 0)
+++ trunk/examples/jms/multiple-failover-failback/server2/client-jndi.properties 2010-12-01 12:23:36 UTC (rev 9959)
@@ -0,0 +1,16 @@
+#
+# 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.
+#
+
+java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
+java.naming.provider.url=jnp://localhost:3099
+java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces
Added: trunk/examples/jms/multiple-failover-failback/server2/hornetq-beans.xml
===================================================================
--- trunk/examples/jms/multiple-failover-failback/server2/hornetq-beans.xml (rev 0)
+++ trunk/examples/jms/multiple-failover-failback/server2/hornetq-beans.xml 2010-12-01 12:23:36 UTC (rev 9959)
@@ -0,0 +1,72 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+ ~ 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.
+ -->
+
+<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">3099</property>
+ <property name="bindAddress">localhost</property>
+ <property name="rmiPort">3098</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: trunk/examples/jms/multiple-failover-failback/server2/hornetq-configuration.xml
===================================================================
--- trunk/examples/jms/multiple-failover-failback/server2/hornetq-configuration.xml (rev 0)
+++ trunk/examples/jms/multiple-failover-failback/server2/hornetq-configuration.xml 2010-12-01 12:23:36 UTC (rev 9959)
@@ -0,0 +1,85 @@
+<!--
+ ~ 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.
+ -->
+
+<configuration xmlns="urn:hornetq"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="urn:hornetq ../../../src/schema/hornetq-configuration.xsd">
+ <!-- Connectors -->
+
+ <clustered>true</clustered>
+
+ <backup>true</backup>
+
+ <shared-store>true</shared-store>
+
+ <allow-failback>true</allow-failback>
+
+ <connectors>
+ <connector name="netty-connector">
+ <factory-class>org.hornetq.core.remoting.impl.netty.NettyConnectorFactory</factory-class>
+ <param key="port" value="5447"/>
+ </connector>
+ </connectors>
+
+ <!-- Acceptors -->
+ <acceptors>
+ <acceptor name="netty-acceptor">
+ <factory-class>org.hornetq.core.remoting.impl.netty.NettyAcceptorFactory</factory-class>
+ <param key="port" value="5447"/>
+ </acceptor>
+ </acceptors>
+
+ <broadcast-groups>
+ <broadcast-group name="bg-group1">
+ <group-address>231.7.7.7</group-address>
+ <group-port>9876</group-port>
+ <broadcast-period>1000</broadcast-period>
+ <connector-ref>netty-connector</connector-ref>
+ </broadcast-group>
+ </broadcast-groups>
+
+ <discovery-groups>
+ <discovery-group name="dg-group1">
+ <group-address>231.7.7.7</group-address>
+ <group-port>9876</group-port>
+ <refresh-timeout>60000</refresh-timeout>
+ </discovery-group>
+ </discovery-groups>
+
+ <cluster-connections>
+ <cluster-connection name="my-cluster">
+ <address>jms</address>
+ <connector-ref>netty-connector</connector-ref>
+ <discovery-group-ref discovery-group-name="dg-group1"/>
+ </cluster-connection>
+ </cluster-connections>
+
+ <large-messages-directory>../server0/data/large-messages</large-messages-directory>
+ <bindings-directory>../server0/data/bindings</bindings-directory>
+ <journal-directory>../server0/data/journal</journal-directory>
+ <paging-directory>../server0/data/paging</paging-directory>
+ <!-- Other config -->
+
+ <security-settings>
+ <!--security for example queue-->
+ <security-setting match="jms.queue.exampleQueue">
+ <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/multiple-failover-failback/server2/hornetq-jms.xml
===================================================================
--- trunk/examples/jms/multiple-failover-failback/server2/hornetq-jms.xml (rev 0)
+++ trunk/examples/jms/multiple-failover-failback/server2/hornetq-jms.xml 2010-12-01 12:23:36 UTC (rev 9959)
@@ -0,0 +1,32 @@
+<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>
+
+ <entries>
+ <entry name="ConnectionFactory"/>
+ </entries>
+
+ <ha>true</ha>
+ <!-- Pause 1 second between connect attempts -->
+ <retry-interval>1000</retry-interval>
+
+ <!-- Multiply subsequent reconnect pauses by this multiplier. This can be used to
+ implement an exponential back-off. For our purposes we just set to 1.0 so each reconnect
+ pause is the same length -->
+ <retry-interval-multiplier>1.0</retry-interval-multiplier>
+
+ <!-- Try reconnecting an unlimited number of times (-1 means "unlimited") -->
+ <reconnect-attempts>-1</reconnect-attempts>
+ </connection-factory>
+
+ <!--the queue used by the example-->
+ <queue name="exampleQueue">
+ <entry name="/queue/exampleQueue"/>
+ </queue>
+
+</configuration>
Added: trunk/examples/jms/multiple-failover-failback/server2/hornetq-users.xml
===================================================================
--- trunk/examples/jms/multiple-failover-failback/server2/hornetq-users.xml (rev 0)
+++ trunk/examples/jms/multiple-failover-failback/server2/hornetq-users.xml 2010-12-01 12:23:36 UTC (rev 9959)
@@ -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
Copied: trunk/examples/jms/multiple-failover-failback/src/org/hornetq/jms/example/MultipleFailoverFailbackExample.java (from rev 9957, trunk/examples/jms/multiple-failover/src/org/hornetq/jms/example/MultipleFailoverExample.java)
===================================================================
--- trunk/examples/jms/multiple-failover-failback/src/org/hornetq/jms/example/MultipleFailoverFailbackExample.java (rev 0)
+++ trunk/examples/jms/multiple-failover-failback/src/org/hornetq/jms/example/MultipleFailoverFailbackExample.java 2010-12-01 12:23:36 UTC (rev 9959)
@@ -0,0 +1,162 @@
+/*
+ * 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 org.hornetq.api.core.TransportConfiguration;
+import org.hornetq.common.example.HornetQExample;
+import org.hornetq.core.client.impl.DelegatingSession;
+import org.hornetq.jms.client.HornetQConnection;
+
+import javax.jms.*;
+import javax.naming.InitialContext;
+
+/**
+ * @author <a href="mailto:andy.taylor@jboss.com">Andy Taylor</a>
+ * Date: Nov 4, 2010
+ * Time: 10:51:45 AM
+ */
+public class MultipleFailoverFailbackExample extends HornetQExample
+{
+ public static void main(final String[] args)
+ {
+ new MultipleFailoverFailbackExample().run(args);
+ }
+
+ @Override
+ public boolean runExample() throws Exception
+ {
+ final int numMessages = 30;
+
+ Connection connection = null;
+
+ InitialContext initialContext = null;
+
+ try
+ {
+ // Step 1. Get an initial context for looking up JNDI from the server #1
+ initialContext = getContext(0);
+
+ // Step 2. Look up the JMS resources from JNDI
+ Queue queue = (Queue)initialContext.lookup("/queue/exampleQueue");
+ ConnectionFactory connectionFactory = (ConnectionFactory)initialContext.lookup("/ConnectionFactory");
+
+ // Step 3. Create a JMS Connection
+ connection = connectionFactory.createConnection();
+
+ // Step 4. Create a *non-transacted* JMS Session with client acknwoledgement
+ Session session = connection.createSession(false, Session.CLIENT_ACKNOWLEDGE);
+
+ // Step 5. Start the connection to ensure delivery occurs
+ connection.start();
+
+ // Step 6. Create a JMS MessageProducer and a MessageConsumer
+ MessageProducer producer = session.createProducer(queue);
+ MessageConsumer consumer = session.createConsumer(queue);
+
+ // Step 7. Send some messages to server #1, the live server
+ for (int i = 0; i < numMessages; i++)
+ {
+ TextMessage message = session.createTextMessage("This is text message " + i);
+ producer.send(message);
+ System.out.println("Sent message: " + message.getText());
+ }
+
+ // Step 8. Receive and acknowledge a third of the sent messages
+ TextMessage message0 = null;
+ for (int i = 0; i < numMessages / 3; i++)
+ {
+ message0 = (TextMessage)consumer.receive(5000);
+ System.out.println("Got message: " + message0.getText());
+ }
+ message0.acknowledge();
+
+ // Step 9. Receive the rest third of the sent messages but *do not* acknowledge them yet
+ for (int i = numMessages / 3; i < numMessages; i++)
+ {
+ message0 = (TextMessage)consumer.receive(5000);
+ System.out.println("Got message: " + message0.getText());
+ }
+
+ // Step 10. Crash server #1, the live server, and wait a little while to make sure
+ // it has really crashed
+ Thread.sleep(2000);
+ killServer(0);
+
+ // Step 11. Acknowledging the 2nd half of the sent messages will fail as failover to the
+ // backup server has occurred
+ try
+ {
+ message0.acknowledge();
+ }
+ catch (JMSException e)
+ {
+ System.err.println("Got exception while acknowledging message: " + e.getMessage());
+ }
+
+ // Step 12. Consume again the 2nd third of the messages again. Note that they are not considered as redelivered.
+ for (int i = numMessages / 3; i < (numMessages / 3) * 2; i++)
+ {
+ message0 = (TextMessage)consumer.receive(5000);
+ System.out.printf("Got message: %s (redelivered?: %s)\n", message0.getText(), message0.getJMSRedelivered());
+ }
+ message0.acknowledge();
+
+ Thread.sleep(2000);
+ reStartServer(0);
+
+ // Step 11. Acknowledging the 2nd half of the sent messages will fail as failover to the
+ // backup server has occurred
+ try
+ {
+ message0.acknowledge();
+ }
+ catch (JMSException e)
+ {
+ System.err.println("Got exception while acknowledging message: " + e.getMessage());
+ }
+
+ // Step 12. Consume again the 2nd third of the messages again. Note that they are not considered as redelivered.
+ for (int i = (numMessages / 3) * 2; i < numMessages; i++)
+ {
+ message0 = (TextMessage)consumer.receive(5000);
+ System.out.printf("Got message: %s (redelivered?: %s)\n", message0.getText(), message0.getJMSRedelivered());
+ }
+ message0.acknowledge();
+
+ return true;
+ }
+ finally
+ {
+ // Step 13. Be sure to close our resources!
+
+ if (connection != null)
+ {
+ connection.close();
+ }
+
+ if (initialContext != null)
+ {
+ initialContext.close();
+ }
+ }
+ }
+
+ private int getServer(Connection connection)
+ {
+ DelegatingSession session = (DelegatingSession) ((HornetQConnection) connection).getInitialSession();
+ TransportConfiguration transportConfiguration = session.getSessionFactory().getConnectorConfiguration();
+ String port = (String) transportConfiguration.getParams().get("port");
+ return Integer.valueOf(port) - 5445;
+ }
+}
15 years, 5 months
JBoss hornetq SVN: r9958 - in trunk: examples/jms/multiple-failover/server2 and 3 other directories.
by do-not-reply@jboss.org
Author: ataylor
Date: 2010-12-01 06:00:36 -0500 (Wed, 01 Dec 2010)
New Revision: 9958
Modified:
trunk/examples/jms/multiple-failover/server1/hornetq-jms.xml
trunk/examples/jms/multiple-failover/server2/hornetq-jms.xml
trunk/examples/jms/non-transaction-failover/server1/hornetq-jms.xml
trunk/examples/jms/transaction-failover/server1/hornetq-jms.xml
trunk/src/config/common/schema/hornetq-jms.xsd
Log:
removed backup connector config
Modified: trunk/examples/jms/multiple-failover/server1/hornetq-jms.xml
===================================================================
--- trunk/examples/jms/multiple-failover/server1/hornetq-jms.xml 2010-12-01 10:57:45 UTC (rev 9957)
+++ trunk/examples/jms/multiple-failover/server1/hornetq-jms.xml 2010-12-01 11:00:36 UTC (rev 9958)
@@ -4,7 +4,7 @@
<!--the connection factory used by the example-->
<connection-factory name="ConnectionFactory">
<connectors>
- <connector-ref connector-name="netty-connector" backup-connector-name="backup-connector"/>
+ <connector-ref connector-name="netty-connector"/>
</connectors>
<entries>
Modified: trunk/examples/jms/multiple-failover/server2/hornetq-jms.xml
===================================================================
--- trunk/examples/jms/multiple-failover/server2/hornetq-jms.xml 2010-12-01 10:57:45 UTC (rev 9957)
+++ trunk/examples/jms/multiple-failover/server2/hornetq-jms.xml 2010-12-01 11:00:36 UTC (rev 9958)
@@ -4,7 +4,7 @@
<!--the connection factory used by the example-->
<connection-factory name="ConnectionFactory">
<connectors>
- <connector-ref connector-name="netty-connector" backup-connector-name="backup-connector"/>
+ <connector-ref connector-name="netty-connector"/>
</connectors>
<entries>
Modified: trunk/examples/jms/non-transaction-failover/server1/hornetq-jms.xml
===================================================================
--- trunk/examples/jms/non-transaction-failover/server1/hornetq-jms.xml 2010-12-01 10:57:45 UTC (rev 9957)
+++ trunk/examples/jms/non-transaction-failover/server1/hornetq-jms.xml 2010-12-01 11:00:36 UTC (rev 9958)
@@ -4,7 +4,7 @@
<!--the connection factory used by the example-->
<connection-factory name="ConnectionFactory">
<connectors>
- <connector-ref connector-name="netty-connector" backup-connector-name="backup-connector"/>
+ <connector-ref connector-name="netty-connector"/>
</connectors>
<entries>
Modified: trunk/examples/jms/transaction-failover/server1/hornetq-jms.xml
===================================================================
--- trunk/examples/jms/transaction-failover/server1/hornetq-jms.xml 2010-12-01 10:57:45 UTC (rev 9957)
+++ trunk/examples/jms/transaction-failover/server1/hornetq-jms.xml 2010-12-01 11:00:36 UTC (rev 9958)
@@ -4,7 +4,7 @@
<!--the connection factory used by the example-->
<connection-factory name="ConnectionFactory">
<connectors>
- <connector-ref connector-name="netty-connector" backup-connector-name="backup-connector"/>
+ <connector-ref connector-name="netty-connector"/>
</connectors>
<entries>
<entry name="ConnectionFactory"/>
Modified: trunk/src/config/common/schema/hornetq-jms.xsd
===================================================================
--- trunk/src/config/common/schema/hornetq-jms.xsd 2010-12-01 10:57:45 UTC (rev 9957)
+++ trunk/src/config/common/schema/hornetq-jms.xsd 2010-12-01 11:00:36 UTC (rev 9958)
@@ -144,7 +144,6 @@
<xsd:complexType name="connector-refType">
<xsd:attribute name="connector-name" type="xsd:string" use="required"></xsd:attribute>
- <xsd:attribute name="backup-connector-name" type="xsd:string" use="optional"></xsd:attribute>
</xsd:complexType>
<xsd:complexType name="entryType">
15 years, 5 months
JBoss hornetq SVN: r9957 - in trunk/examples/jms/multiple-failover: server1 and 2 other directories.
by do-not-reply@jboss.org
Author: ataylor
Date: 2010-12-01 05:57:45 -0500 (Wed, 01 Dec 2010)
New Revision: 9957
Modified:
trunk/examples/jms/multiple-failover/server0/hornetq-configuration.xml
trunk/examples/jms/multiple-failover/server1/hornetq-configuration.xml
trunk/examples/jms/multiple-failover/server2/hornetq-configuration.xml
trunk/examples/jms/multiple-failover/src/org/hornetq/jms/example/MultipleFailoverExample.java
Log:
fixed example
Modified: trunk/examples/jms/multiple-failover/server0/hornetq-configuration.xml
===================================================================
--- trunk/examples/jms/multiple-failover/server0/hornetq-configuration.xml 2010-12-01 09:24:21 UTC (rev 9956)
+++ trunk/examples/jms/multiple-failover/server0/hornetq-configuration.xml 2010-12-01 10:57:45 UTC (rev 9957)
@@ -26,7 +26,7 @@
<broadcast-group name="bg-group1">
<group-address>231.7.7.7</group-address>
<group-port>9876</group-port>
- <broadcast-period>5000</broadcast-period>
+ <broadcast-period>1000</broadcast-period>
<connector-ref>netty-connector</connector-ref>
</broadcast-group>
</broadcast-groups>
Modified: trunk/examples/jms/multiple-failover/server1/hornetq-configuration.xml
===================================================================
--- trunk/examples/jms/multiple-failover/server1/hornetq-configuration.xml 2010-12-01 09:24:21 UTC (rev 9956)
+++ trunk/examples/jms/multiple-failover/server1/hornetq-configuration.xml 2010-12-01 10:57:45 UTC (rev 9957)
@@ -29,7 +29,7 @@
<broadcast-group name="bg-group1">
<group-address>231.7.7.7</group-address>
<group-port>9876</group-port>
- <broadcast-period>5000</broadcast-period>
+ <broadcast-period>1000</broadcast-period>
<connector-ref>netty-connector</connector-ref>
</broadcast-group>
</broadcast-groups>
Modified: trunk/examples/jms/multiple-failover/server2/hornetq-configuration.xml
===================================================================
--- trunk/examples/jms/multiple-failover/server2/hornetq-configuration.xml 2010-12-01 09:24:21 UTC (rev 9956)
+++ trunk/examples/jms/multiple-failover/server2/hornetq-configuration.xml 2010-12-01 10:57:45 UTC (rev 9957)
@@ -41,7 +41,7 @@
<broadcast-group name="bg-group1">
<group-address>231.7.7.7</group-address>
<group-port>9876</group-port>
- <broadcast-period>5000</broadcast-period>
+ <broadcast-period>1000</broadcast-period>
<connector-ref>netty-connector</connector-ref>
</broadcast-group>
</broadcast-groups>
Modified: trunk/examples/jms/multiple-failover/src/org/hornetq/jms/example/MultipleFailoverExample.java
===================================================================
--- trunk/examples/jms/multiple-failover/src/org/hornetq/jms/example/MultipleFailoverExample.java 2010-12-01 09:24:21 UTC (rev 9956)
+++ trunk/examples/jms/multiple-failover/src/org/hornetq/jms/example/MultipleFailoverExample.java 2010-12-01 10:57:45 UTC (rev 9957)
@@ -23,7 +23,11 @@
import javax.jms.TextMessage;
import javax.naming.InitialContext;
+import org.hornetq.api.core.TransportConfiguration;
import org.hornetq.common.example.HornetQExample;
+import org.hornetq.core.client.impl.ClientSessionImpl;
+import org.hornetq.core.client.impl.DelegatingSession;
+import org.hornetq.jms.client.HornetQConnection;
/**
* @author <a href="mailto:andy.taylor@jboss.com">Andy Taylor</a>
@@ -40,7 +44,6 @@
@Override
public boolean runExample() throws Exception
{
- Thread.sleep(10000);
final int numMessages = 30;
Connection connection = null;
@@ -95,6 +98,7 @@
// Step 10. Crash server #1, the live server, and wait a little while to make sure
// it has really crashed
+ Thread.sleep(2000);
killServer(0);
// Step 11. Acknowledging the 2nd half of the sent messages will fail as failover to the
@@ -108,14 +112,36 @@
System.err.println("Got exception while acknowledging message: " + e.getMessage());
}
- // Step 12. Consume again the 2nd half of the messages again. Note that they are not considered as redelivered.
- for (int i = numMessages / 3; i < numMessages; i++)
+ // Step 12. Consume again the 2nd third of the messages again. Note that they are not considered as redelivered.
+ for (int i = numMessages / 3; i < (numMessages / 3) * 2; i++)
{
message0 = (TextMessage)consumer.receive(5000);
System.out.printf("Got message: %s (redelivered?: %s)\n", message0.getText(), message0.getJMSRedelivered());
}
message0.acknowledge();
+ Thread.sleep(2000);
+ killServer(getServer(connection));
+
+ // Step 11. Acknowledging the 2nd half of the sent messages will fail as failover to the
+ // backup server has occurred
+ try
+ {
+ message0.acknowledge();
+ }
+ catch (JMSException e)
+ {
+ System.err.println("Got exception while acknowledging message: " + e.getMessage());
+ }
+
+ // Step 12. Consume again the 2nd third of the messages again. Note that they are not considered as redelivered.
+ for (int i = (numMessages / 3) * 2; i < numMessages; i++)
+ {
+ message0 = (TextMessage)consumer.receive(5000);
+ System.out.printf("Got message: %s (redelivered?: %s)\n", message0.getText(), message0.getJMSRedelivered());
+ }
+ message0.acknowledge();
+
return true;
}
finally
@@ -133,4 +159,12 @@
}
}
}
+
+ private int getServer(Connection connection)
+ {
+ DelegatingSession session = (DelegatingSession) ((HornetQConnection) connection).getInitialSession();
+ TransportConfiguration transportConfiguration = session.getSessionFactory().getConnectorConfiguration();
+ String port = (String) transportConfiguration.getParams().get("port");
+ return Integer.valueOf(port) - 5445;
+ }
}
15 years, 5 months
JBoss hornetq SVN: r9956 - trunk/tests/src/org/hornetq/tests/integration/jms/client.
by do-not-reply@jboss.org
Author: ataylor
Date: 2010-12-01 04:24:21 -0500 (Wed, 01 Dec 2010)
New Revision: 9956
Modified:
trunk/tests/src/org/hornetq/tests/integration/jms/client/ConnectionTest.java
Log:
close connection
Modified: trunk/tests/src/org/hornetq/tests/integration/jms/client/ConnectionTest.java
===================================================================
--- trunk/tests/src/org/hornetq/tests/integration/jms/client/ConnectionTest.java 2010-12-01 06:12:57 UTC (rev 9955)
+++ trunk/tests/src/org/hornetq/tests/integration/jms/client/ConnectionTest.java 2010-12-01 09:24:21 UTC (rev 9956)
@@ -45,6 +45,8 @@
conn.getClientID();
conn.setClientID("somethingElse");
+
+ conn.close();
}
15 years, 5 months