diff options
Diffstat (limited to 'plugins/org.eclipse.net4j.examples.installer/examples/org.eclipse.net4j.jms/src/org/eclipse')
49 files changed, 4542 insertions, 0 deletions
diff --git a/plugins/org.eclipse.net4j.examples.installer/examples/org.eclipse.net4j.jms/src/org/eclipse/net4j/internal/jms/BytesMessageImpl.java b/plugins/org.eclipse.net4j.examples.installer/examples/org.eclipse.net4j.jms/src/org/eclipse/net4j/internal/jms/BytesMessageImpl.java new file mode 100644 index 0000000000..afffcf9636 --- /dev/null +++ b/plugins/org.eclipse.net4j.examples.installer/examples/org.eclipse.net4j.jms/src/org/eclipse/net4j/internal/jms/BytesMessageImpl.java @@ -0,0 +1,185 @@ +/* + * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Eike Stepper - initial API and implementation + */ +package org.eclipse.net4j.internal.jms; + +import org.eclipse.net4j.util.io.ExtendedDataInputStream; +import org.eclipse.net4j.util.io.ExtendedDataOutputStream; + +import javax.jms.BytesMessage; +import javax.jms.JMSException; +import javax.jms.Message; + +import java.io.IOException; + +public class BytesMessageImpl extends MessageImpl implements BytesMessage +{ + public long getBodyLength() + { + throw new NotYetImplementedException(); + } + + public boolean readBoolean() + { + throw new NotYetImplementedException(); + } + + public byte readByte() + { + throw new NotYetImplementedException(); + } + + public int readBytes(byte[] value) + { + throw new NotYetImplementedException(); + } + + public int readBytes(byte[] value, int length) + { + throw new NotYetImplementedException(); + } + + public char readChar() + { + throw new NotYetImplementedException(); + } + + public double readDouble() + { + throw new NotYetImplementedException(); + } + + public float readFloat() + { + throw new NotYetImplementedException(); + } + + public int readInt() + { + throw new NotYetImplementedException(); + } + + public long readLong() + { + throw new NotYetImplementedException(); + } + + public short readShort() + { + throw new NotYetImplementedException(); + } + + public String readUTF() + { + throw new NotYetImplementedException(); + } + + public int readUnsignedByte() + { + throw new NotYetImplementedException(); + } + + public int readUnsignedShort() + { + throw new NotYetImplementedException(); + } + + public void reset() + { + throw new NotYetImplementedException(); + } + + public void writeBoolean(boolean value) + { + throw new NotYetImplementedException(); + } + + public void writeByte(byte value) + { + throw new NotYetImplementedException(); + } + + public void writeBytes(byte[] value) + { + throw new NotYetImplementedException(); + } + + public void writeBytes(byte[] value, int offset, int length) + { + throw new NotYetImplementedException(); + } + + public void writeChar(char value) + { + throw new NotYetImplementedException(); + } + + public void writeDouble(double value) + { + throw new NotYetImplementedException(); + } + + public void writeFloat(float value) + { + throw new NotYetImplementedException(); + } + + public void writeInt(int value) + { + throw new NotYetImplementedException(); + } + + public void writeLong(long value) + { + throw new NotYetImplementedException(); + } + + public void writeObject(Object value) + { + throw new NotYetImplementedException(); + } + + public void writeShort(short value) + { + throw new NotYetImplementedException(); + } + + public void writeUTF(String value) + { + throw new NotYetImplementedException(); + } + + @Override + public void populate(Message source) throws JMSException + { + super.populate(source); + byte[] buffer = new byte[512]; + BytesMessage bytes = (BytesMessage)source; + + bytes.reset(); + int count; + while ((count = bytes.readBytes(buffer)) != -1) + { + writeBytes(buffer, 0, count); + } + } + + @Override + public void write(ExtendedDataOutputStream out) throws IOException + { + super.write(out); + } + + @Override + public void read(ExtendedDataInputStream in) throws IOException + { + super.read(in); + } +} diff --git a/plugins/org.eclipse.net4j.examples.installer/examples/org.eclipse.net4j.jms/src/org/eclipse/net4j/internal/jms/ConnectionFactoryImpl.java b/plugins/org.eclipse.net4j.examples.installer/examples/org.eclipse.net4j.jms/src/org/eclipse/net4j/internal/jms/ConnectionFactoryImpl.java new file mode 100644 index 0000000000..763a62e0f2 --- /dev/null +++ b/plugins/org.eclipse.net4j.examples.installer/examples/org.eclipse.net4j.jms/src/org/eclipse/net4j/internal/jms/ConnectionFactoryImpl.java @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Eike Stepper - initial API and implementation + */ +package org.eclipse.net4j.internal.jms; + +import org.eclipse.net4j.util.container.IManagedContainer; + +import javax.jms.Connection; +import javax.jms.ConnectionFactory; +import javax.jms.JMSException; + +import java.io.Serializable; +import java.rmi.Remote; + +public class ConnectionFactoryImpl implements ConnectionFactory, Remote, Serializable +{ + private static final long serialVersionUID = 1L; + + private String connectorType; + + private String connectorDescription; + + private Object transportContainer; + + public ConnectionFactoryImpl(String connectorType, String connectorDescription) + { + this.connectorType = connectorType; + this.connectorDescription = connectorDescription; + } + + public String getConnectorType() + { + return connectorType; + } + + public String getConnectorDescription() + { + return connectorDescription; + } + + public Object getTransportContainer() + { + return transportContainer; + } + + public void setTransportContainer(Object transportContainer) + { + this.transportContainer = transportContainer; + } + + public Connection createConnection() throws JMSException + { + return createConnection(null, null); + } + + public Connection createConnection(String userName, String password) throws JMSException + { + return new ConnectionImpl((IManagedContainer)transportContainer, connectorType, connectorDescription, userName, + password); + } +} diff --git a/plugins/org.eclipse.net4j.examples.installer/examples/org.eclipse.net4j.jms/src/org/eclipse/net4j/internal/jms/ConnectionImpl.java b/plugins/org.eclipse.net4j.examples.installer/examples/org.eclipse.net4j.jms/src/org/eclipse/net4j/internal/jms/ConnectionImpl.java new file mode 100644 index 0000000000..a4f30d9496 --- /dev/null +++ b/plugins/org.eclipse.net4j.examples.installer/examples/org.eclipse.net4j.jms/src/org/eclipse/net4j/internal/jms/ConnectionImpl.java @@ -0,0 +1,407 @@ +/* + * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Eike Stepper - initial API and implementation + */ +package org.eclipse.net4j.internal.jms; + +import org.eclipse.net4j.Net4jUtil; +import org.eclipse.net4j.channel.IChannel; +import org.eclipse.net4j.connector.IConnector; +import org.eclipse.net4j.internal.jms.bundle.OM; +import org.eclipse.net4j.internal.jms.messages.Messages; +import org.eclipse.net4j.internal.jms.protocol.JMSClientProtocol; +import org.eclipse.net4j.internal.jms.protocol.JMSLogonRequest; +import org.eclipse.net4j.internal.jms.protocol.JMSOpenSessionRequest; +import org.eclipse.net4j.jms.JMSUtil; +import org.eclipse.net4j.util.container.Container; +import org.eclipse.net4j.util.container.IContainer; +import org.eclipse.net4j.util.container.IContainerDelta; +import org.eclipse.net4j.util.container.IContainerDelta.Kind; +import org.eclipse.net4j.util.container.IContainerEvent; +import org.eclipse.net4j.util.container.IManagedContainer; +import org.eclipse.net4j.util.container.LifecycleEventConverter; +import org.eclipse.net4j.util.container.SingleDeltaContainerEvent; +import org.eclipse.net4j.util.event.IListener; +import org.eclipse.net4j.util.lifecycle.ILifecycle; +import org.eclipse.net4j.util.lifecycle.LifecycleEventAdapter; + +import javax.jms.Connection; +import javax.jms.ConnectionConsumer; +import javax.jms.ConnectionMetaData; +import javax.jms.Destination; +import javax.jms.ExceptionListener; +import javax.jms.JMSException; +import javax.jms.ServerSessionPool; +import javax.jms.Session; +import javax.jms.Topic; + +import java.util.ArrayList; +import java.util.List; + +public class ConnectionImpl extends Container<Session> implements Connection +{ + private String connectorType; + + private String connectorDescription; + + private String userName; + + private String password; + + private ExceptionListener exceptionListener; + + private String clientID; + + private ConnectionMetaData metaData = new ConnectionMetaDataImpl(this); + + private long sendTimeout = 2500; + + private IManagedContainer transportContainer; + + private JMSClientProtocol protocol; + + private List<SessionImpl> sessions = new ArrayList<SessionImpl>(0); + + private transient IListener sessionListener = new LifecycleEventConverter<Session>(this) + { + @Override + protected IContainerEvent<Session> createContainerEvent(IContainer<Session> container, Session element, Kind kind) + { + if (kind == IContainerDelta.Kind.REMOVED) + { + removeSession((SessionImpl)element); + } + + return new SingleDeltaContainerEvent<Session>(container, element, kind); + } + }; + + private transient IListener channelListener = new LifecycleEventAdapter() + { + @Override + protected void onDeactivated(ILifecycle lifecycle) + { + close(); + } + }; + + private boolean modified; + + private boolean stopped = true; + + public ConnectionImpl(IManagedContainer transportContainer, String connectorType, String connectorDescription, + String userName, String password) throws JMSException + { + this.transportContainer = transportContainer == null ? JMSUtil.getTransportContainer() : transportContainer; + if (transportContainer == null) + { + throw new JMSException(Messages.getString("ConnectionImpl_0")); //$NON-NLS-1$ + } + + this.connectorType = connectorType; + this.connectorDescription = connectorDescription; + this.userName = userName; + this.password = password; + + IConnector connector = Net4jUtil.getConnector(transportContainer, connectorType, connectorDescription); + JMSClientProtocol protocol = new JMSClientProtocol(this); + IChannel channel = protocol.open(connector); + channel.addListener(channelListener); + + try + { + if (!new JMSLogonRequest(protocol, userName, password).send()) + { + throw new JMSException(Messages.getString("ConnectionImpl_1")); //$NON-NLS-1$ + } + } + catch (JMSException ex) + { + throw ex; + } + catch (Exception ex) + { + throw new JMSException(ex.getMessage()); + } + } + + public ConnectionConsumer createConnectionConsumer(Destination destination, String messageSelector, + ServerSessionPool sessionPool, int maxMessages) + { + throw new UnsupportedOperationException(); + } + + public ConnectionConsumer createDurableConnectionConsumer(Topic topic, String subscriptionName, + String messageSelector, ServerSessionPool sessionPool, int maxMessages) + { + throw new UnsupportedOperationException(); + } + + public Session createSession(boolean transacted, int acknowledgeMode) throws JMSException + { + ensureOpen(); + setModified(); + int sessionID = findFreeSessionID(); + SessionImpl session = new SessionImpl(this, sessionID, transacted, acknowledgeMode); + addSession(session); + + try + { + if (!new JMSOpenSessionRequest(protocol, sessionID).send()) + { + throw new JMSException(Messages.getString("ConnectionImpl_2")); //$NON-NLS-1$ + } + } + catch (JMSException ex) + { + throw ex; + } + catch (Exception ex) + { + throw new JMSException(ex.getMessage()); + } + + return session; + } + + public IManagedContainer getTransportContainer() + { + return transportContainer; + } + + public String getConnectorType() + { + return connectorType; + } + + public String getConnectorDescription() + { + return connectorDescription; + } + + public String getUserName() + { + return userName; + } + + public String getPassword() + { + return password; + } + + public ConnectionMetaData getMetaData() + { + ensureOpen(); + setModified(); + return metaData; + } + + public String getClientID() + { + ensureOpen(); + setModified(); + return clientID; + } + + public void setClientID(String clientID) + { + ensureOpen(); + if (clientID != null) + { + throw new IllegalStateException("clientID != null"); //$NON-NLS-1$ + } + + if (modified) + { + throw new IllegalStateException("modified == true"); //$NON-NLS-1$ + } + + this.clientID = clientID; + } + + public ExceptionListener getExceptionListener() + { + ensureOpen(); + setModified(); + return exceptionListener; + } + + public void setExceptionListener(ExceptionListener listener) + { + ensureOpen(); + setModified(); + exceptionListener = listener; + } + + public long getSendTimeout() + { + return sendTimeout; + } + + public void setSendTimeout(long sendTimeout) + { + this.sendTimeout = sendTimeout; + } + + public synchronized void start() throws JMSException + { + ensureOpen(); + setModified(); + if (stopped) + { + for (SessionImpl session : getSessions()) + { + try + { + session.activate(); + } + catch (Exception ex) + { + OM.LOG.error(ex); + throw new JMSException(ex.getMessage()); + } + } + + stopped = false; + } + } + + public synchronized void stop() + { + ensureOpen(); + setModified(); + if (!stopped) + { + for (SessionImpl session : getSessions()) + { + session.deactivate(); + } + + stopped = true; + } + } + + public synchronized void close() + { + if (protocol != null) + { + stop(); + for (SessionImpl session : getSessions()) + { + session.close(); + } + + protocol.getChannel().removeListener(channelListener); + protocol.close(); + protocol = null; + } + } + + /** + * @since 2.0 + */ + public JMSClientProtocol getProtocol() + { + return protocol; + } + + public void handleMessageFromSignal(int sessionID, long consumerID, MessageImpl message) + { + SessionImpl session = sessions.get(sessionID); + session.handleServerMessage(consumerID, message); + } + + public SessionImpl[] getSessions() + { + List<SessionImpl> result = new ArrayList<SessionImpl>(sessions.size()); + synchronized (sessions) + { + for (SessionImpl session : sessions) + { + if (session != null) + { + result.add(session); + } + } + } + + return result.toArray(new SessionImpl[result.size()]); + } + + public Session[] getElements() + { + return getSessions(); + } + + @Override + public boolean isEmpty() + { + return getSessions().length == 0; + } + + private int findFreeSessionID() + { + synchronized (sessions) + { + int size = sessions.size(); + for (int i = 0; i < size; i++) + { + if (sessions.get(i) == null) + { + return i; + } + } + + return size; + } + } + + private void addSession(SessionImpl session) + { + synchronized (sessions) + { + int sessionID = session.getID(); + while (sessionID >= sessions.size()) + { + sessions.add(null); + } + + sessions.set(sessionID, session); + } + } + + private boolean removeSession(SessionImpl session) + { + synchronized (sessions) + { + int sessionID = session.getID(); + if (sessions.get(sessionID) == session) + { + session.removeListener(sessionListener); + sessions.set(sessionID, null); + return true; + } + + return false; + } + } + + private void setModified() + { + modified = true; + } + + private void ensureOpen() throws IllegalStateException + { + if (protocol == null) + { + throw new IllegalStateException("protocol == null"); //$NON-NLS-1$ + } + } +} diff --git a/plugins/org.eclipse.net4j.examples.installer/examples/org.eclipse.net4j.jms/src/org/eclipse/net4j/internal/jms/ConnectionMetaDataImpl.java b/plugins/org.eclipse.net4j.examples.installer/examples/org.eclipse.net4j.jms/src/org/eclipse/net4j/internal/jms/ConnectionMetaDataImpl.java new file mode 100644 index 0000000000..fc7c611260 --- /dev/null +++ b/plugins/org.eclipse.net4j.examples.installer/examples/org.eclipse.net4j.jms/src/org/eclipse/net4j/internal/jms/ConnectionMetaDataImpl.java @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Eike Stepper - initial API and implementation + */ +package org.eclipse.net4j.internal.jms; + +import javax.jms.ConnectionMetaData; + +import java.util.Enumeration; +import java.util.StringTokenizer; + +public class ConnectionMetaDataImpl implements ConnectionMetaData +{ + private ConnectionImpl connection; + + public ConnectionMetaDataImpl(ConnectionImpl connection) + { + this.connection = connection; + } + + public ConnectionImpl getConnection() + { + return connection; + } + + public int getJMSMajorVersion() + { + return 1; + } + + public int getJMSMinorVersion() + { + return 1; + } + + public String getJMSVersion() + { + return "1.1"; //$NON-NLS-1$ + } + + public String getJMSProviderName() + { + return "Net4j JMS"; //$NON-NLS-1$ + } + + public int getProviderMajorVersion() + { + return 0; + } + + public int getProviderMinorVersion() + { + return 8; + } + + public String getProviderVersion() + { + return "0.8.0"; //$NON-NLS-1$ + } + + public Enumeration<?> getJMSXPropertyNames() + { + return new StringTokenizer(""); //$NON-NLS-1$ + } +} diff --git a/plugins/org.eclipse.net4j.examples.installer/examples/org.eclipse.net4j.jms/src/org/eclipse/net4j/internal/jms/DestinationImpl.java b/plugins/org.eclipse.net4j.examples.installer/examples/org.eclipse.net4j.jms/src/org/eclipse/net4j/internal/jms/DestinationImpl.java new file mode 100644 index 0000000000..1a7c5b3cd0 --- /dev/null +++ b/plugins/org.eclipse.net4j.examples.installer/examples/org.eclipse.net4j.jms/src/org/eclipse/net4j/internal/jms/DestinationImpl.java @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Eike Stepper - initial API and implementation + */ +package org.eclipse.net4j.internal.jms; + +import java.io.Serializable; +import java.rmi.Remote; + +public abstract class DestinationImpl implements JMSDestination, Remote, Serializable +{ + private static final long serialVersionUID = 1L; +} diff --git a/plugins/org.eclipse.net4j.examples.installer/examples/org.eclipse.net4j.jms/src/org/eclipse/net4j/internal/jms/JMSDestination.java b/plugins/org.eclipse.net4j.examples.installer/examples/org.eclipse.net4j.jms/src/org/eclipse/net4j/internal/jms/JMSDestination.java new file mode 100644 index 0000000000..8b760504c6 --- /dev/null +++ b/plugins/org.eclipse.net4j.examples.installer/examples/org.eclipse.net4j.jms/src/org/eclipse/net4j/internal/jms/JMSDestination.java @@ -0,0 +1,18 @@ +/* + * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Eike Stepper - initial API and implementation + */ +package org.eclipse.net4j.internal.jms; + +import javax.jms.Destination; + +public interface JMSDestination extends Destination +{ + public String getName(); +} diff --git a/plugins/org.eclipse.net4j.examples.installer/examples/org.eclipse.net4j.jms/src/org/eclipse/net4j/internal/jms/JMSTemporaryDestination.java b/plugins/org.eclipse.net4j.examples.installer/examples/org.eclipse.net4j.jms/src/org/eclipse/net4j/internal/jms/JMSTemporaryDestination.java new file mode 100644 index 0000000000..226c565383 --- /dev/null +++ b/plugins/org.eclipse.net4j.examples.installer/examples/org.eclipse.net4j.jms/src/org/eclipse/net4j/internal/jms/JMSTemporaryDestination.java @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Eike Stepper - initial API and implementation + */ +package org.eclipse.net4j.internal.jms; + +public interface JMSTemporaryDestination extends JMSDestination +{ + public ConnectionImpl getOwningConnection(); + + public long getConnectionId(); + + public boolean validForConnection(ConnectionImpl connection); +} diff --git a/plugins/org.eclipse.net4j.examples.installer/examples/org.eclipse.net4j.jms/src/org/eclipse/net4j/internal/jms/MapMessageImpl.java b/plugins/org.eclipse.net4j.examples.installer/examples/org.eclipse.net4j.jms/src/org/eclipse/net4j/internal/jms/MapMessageImpl.java new file mode 100644 index 0000000000..883bb6ddb1 --- /dev/null +++ b/plugins/org.eclipse.net4j.examples.installer/examples/org.eclipse.net4j.jms/src/org/eclipse/net4j/internal/jms/MapMessageImpl.java @@ -0,0 +1,175 @@ +/* + * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Eike Stepper - initial API and implementation + */ +package org.eclipse.net4j.internal.jms; + +import org.eclipse.net4j.util.io.ExtendedDataInputStream; +import org.eclipse.net4j.util.io.ExtendedDataOutputStream; + +import javax.jms.JMSException; +import javax.jms.MapMessage; +import javax.jms.Message; + +import java.io.IOException; +import java.util.Enumeration; + +public class MapMessageImpl extends MessageImpl implements MapMessage +{ + public boolean getBoolean(String name) + { + throw new NotYetImplementedException(); + } + + public byte getByte(String name) + { + throw new NotYetImplementedException(); + } + + public byte[] getBytes(String name) + { + throw new NotYetImplementedException(); + } + + public char getChar(String name) + { + throw new NotYetImplementedException(); + } + + public double getDouble(String name) + { + throw new NotYetImplementedException(); + } + + public float getFloat(String name) + { + throw new NotYetImplementedException(); + } + + public int getInt(String name) + { + throw new NotYetImplementedException(); + } + + public long getLong(String name) + { + throw new NotYetImplementedException(); + } + + public Enumeration<?> getMapNames() + { + throw new NotYetImplementedException(); + } + + public Object getObject(String name) + { + throw new NotYetImplementedException(); + } + + public short getShort(String name) + { + throw new NotYetImplementedException(); + } + + public String getString(String name) + { + throw new NotYetImplementedException(); + } + + public boolean itemExists(String name) + { + throw new NotYetImplementedException(); + } + + public void setBoolean(String name, boolean value) + { + throw new NotYetImplementedException(); + } + + public void setByte(String name, byte value) + { + throw new NotYetImplementedException(); + } + + public void setBytes(String name, byte[] value) + { + throw new NotYetImplementedException(); + } + + public void setBytes(String name, byte[] value, int offset, int length) + { + throw new NotYetImplementedException(); + } + + public void setChar(String name, char value) + { + throw new NotYetImplementedException(); + } + + public void setDouble(String name, double value) + { + throw new NotYetImplementedException(); + } + + public void setFloat(String name, float value) + { + throw new NotYetImplementedException(); + } + + public void setInt(String name, int value) + { + throw new NotYetImplementedException(); + } + + public void setLong(String name, long value) + { + throw new NotYetImplementedException(); + } + + public void setObject(String name, Object value) + { + throw new NotYetImplementedException(); + } + + public void setShort(String name, short value) + { + throw new NotYetImplementedException(); + } + + public void setString(String name, String value) + { + throw new NotYetImplementedException(); + } + + @Override + public void populate(Message source) throws JMSException + { + super.populate(source); + MapMessage map = (MapMessage)source; + Enumeration<?> e = map.getMapNames(); + while (e.hasMoreElements()) + { + String name = (String)e.nextElement(); + Object value = map.getObject(name); + setObject(name, value); + } + } + + @Override + public void write(ExtendedDataOutputStream out) throws IOException + { + super.write(out); + } + + @Override + public void read(ExtendedDataInputStream in) throws IOException + { + super.read(in); + } +} diff --git a/plugins/org.eclipse.net4j.examples.installer/examples/org.eclipse.net4j.jms/src/org/eclipse/net4j/internal/jms/MessageConsumerImpl.java b/plugins/org.eclipse.net4j.examples.installer/examples/org.eclipse.net4j.jms/src/org/eclipse/net4j/internal/jms/MessageConsumerImpl.java new file mode 100644 index 0000000000..e29160a7de --- /dev/null +++ b/plugins/org.eclipse.net4j.examples.installer/examples/org.eclipse.net4j.jms/src/org/eclipse/net4j/internal/jms/MessageConsumerImpl.java @@ -0,0 +1,160 @@ +/* + * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Eike Stepper - initial API and implementation + */ +package org.eclipse.net4j.internal.jms; + +import org.eclipse.net4j.internal.jms.bundle.OM; +import org.eclipse.net4j.internal.jms.messages.Messages; +import org.eclipse.net4j.util.lifecycle.Lifecycle; + +import javax.jms.JMSException; +import javax.jms.Message; +import javax.jms.MessageConsumer; +import javax.jms.MessageListener; +import javax.jms.Session; + +import java.util.concurrent.BlockingQueue; +import java.util.concurrent.LinkedBlockingQueue; +import java.util.concurrent.TimeUnit; + +public class MessageConsumerImpl extends Lifecycle implements MessageConsumer +{ + private static final long DO_NOT_WAIT = -1L; + + private SessionImpl session; + + private long consumerID; + + private DestinationImpl destination; + + private String messageSelector; + + private MessageListener messageListener; + + /** + * Incoming messages + */ + private BlockingQueue<MessageImpl> messages = new LinkedBlockingQueue<MessageImpl>(); + + public MessageConsumerImpl(SessionImpl session, long consumerID, DestinationImpl destination, String messageSelector) + { + this.session = session; + this.consumerID = consumerID; + this.destination = destination; + this.messageSelector = messageSelector; + } + + public SessionImpl getSession() + { + return session; + } + + public long getConsumerID() + { + return consumerID; + } + + public DestinationImpl getDestination() + { + return destination; + } + + public String getMessageSelector() + { + return messageSelector; + } + + public MessageListener getMessageListener() + { + return messageListener; + } + + public void setMessageListener(MessageListener listener) + { + messageListener = listener; + if (messageListener != null) + { + session.addWork(this); + } + } + + public Message receive() throws JMSException + { + return receive(Long.MAX_VALUE); + } + + public Message receive(long timeout) throws JMSException + { + if (messageListener != null) + { + throw new JMSException(Messages.getString("MessageConsumerImpl.0")); //$NON-NLS-1$ + } + + if (timeout == DO_NOT_WAIT) + { + return messages.poll(); + } + + try + { + return messages.poll(timeout, TimeUnit.MILLISECONDS); + } + catch (InterruptedException ex) + { + throw new JMSException(ex.getMessage()); + } + } + + public Message receiveNoWait() throws JMSException + { + return receive(DO_NOT_WAIT); + } + + public void close() + { + throw new NotYetImplementedException(); + } + + public void handleServerMessage(MessageImpl message) + { + messages.add(message); + if (messageListener != null) + { + session.addWork(this); + } + } + + public void dispatchMessage() + { + MessageListener listener = messageListener; + if (listener != null) + { + MessageImpl message = messages.poll(); + if (message == null) + { + OM.LOG.warn(Messages.getString("MessageConsumerImpl.1")); //$NON-NLS-1$ + return; + } + + try + { + listener.onMessage(message); + if (!session.getTransacted() && session.getAcknowledgeMode() != Session.CLIENT_ACKNOWLEDGE) + { + session.acknowledgeMessages(this); + } + } + catch (RuntimeException ex) + { + OM.LOG.warn(ex); + } + } + } +} diff --git a/plugins/org.eclipse.net4j.examples.installer/examples/org.eclipse.net4j.jms/src/org/eclipse/net4j/internal/jms/MessageImpl.java b/plugins/org.eclipse.net4j.examples.installer/examples/org.eclipse.net4j.jms/src/org/eclipse/net4j/internal/jms/MessageImpl.java new file mode 100644 index 0000000000..ef43d9489e --- /dev/null +++ b/plugins/org.eclipse.net4j.examples.installer/examples/org.eclipse.net4j.jms/src/org/eclipse/net4j/internal/jms/MessageImpl.java @@ -0,0 +1,464 @@ +/* + * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Eike Stepper - initial API and implementation + */ +package org.eclipse.net4j.internal.jms; + +import org.eclipse.net4j.internal.jms.messages.Messages; +import org.eclipse.net4j.internal.jms.util.DestinationUtil; +import org.eclipse.net4j.internal.jms.util.TypeUtil; +import org.eclipse.net4j.util.io.ExtendedDataInputStream; +import org.eclipse.net4j.util.io.ExtendedDataOutputStream; + +import javax.jms.Destination; +import javax.jms.JMSException; +import javax.jms.Message; +import javax.jms.MessageFormatException; +import javax.jms.Session; + +import java.io.IOException; +import java.text.MessageFormat; +import java.util.Collections; +import java.util.Enumeration; +import java.util.HashMap; +import java.util.Map; +import java.util.Map.Entry; + +public class MessageImpl implements Message, Comparable<MessageImpl> +{ + private static final String[] KEYWORDS = { "and", "between", "escape", "in", "is", "like", "false", "null", "or", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$ //$NON-NLS-9$ + "not", "true" }; //$NON-NLS-1$ //$NON-NLS-2$ + + private Map<String, Object> properties = new HashMap<String, Object>(); + + private byte[] correlationID; + + private int deliveryMode; + + private DestinationImpl destination; + + private long expiration; + + private String messageID; + + private int priority; + + private boolean redelivered; + + private DestinationImpl replyTo; + + private long timestamp; + + private String type; + + private SessionImpl receivingSession; + + private MessageConsumerImpl receivingConsumer; + + public MessageImpl() + { + } + + public SessionImpl getReceivingSession() + { + return receivingSession; + } + + public void setReceivingSession(SessionImpl receivingSession) + { + this.receivingSession = receivingSession; + } + + public MessageConsumerImpl getReceivingConsumer() + { + return receivingConsumer; + } + + public void setReceivingConsumer(MessageConsumerImpl receivingConsumer) + { + this.receivingConsumer = receivingConsumer; + } + + public String getJMSCorrelationID() + { + if (correlationID == null) + { + return null; + } + + return new String(correlationID); + } + + public void setJMSCorrelationID(String correlationID) + { + this.correlationID = correlationID == null ? null : correlationID.getBytes(); + } + + public byte[] getJMSCorrelationIDAsBytes() + { + return correlationID; + } + + public void setJMSCorrelationIDAsBytes(byte[] correlationID) + { + this.correlationID = correlationID; + } + + public int getJMSDeliveryMode() + { + return deliveryMode; + } + + public void setJMSDeliveryMode(int deliveryMode) + { + this.deliveryMode = deliveryMode; + } + + public Destination getJMSDestination() + { + return destination; + } + + public void setJMSDestination(Destination destination) throws JMSException + { + this.destination = DestinationUtil.convert(destination); + } + + public long getJMSExpiration() + { + return expiration; + } + + public void setJMSExpiration(long expiration) + { + this.expiration = expiration; + } + + public String getJMSMessageID() + { + return messageID; + } + + public void setJMSMessageID(String messageID) + { + this.messageID = messageID; + } + + public int getJMSPriority() + { + return priority; + } + + public void setJMSPriority(int priority) + { + this.priority = priority; + } + + public boolean getJMSRedelivered() + { + return redelivered; + } + + public void setJMSRedelivered(boolean redelivered) + { + this.redelivered = redelivered; + } + + public Destination getJMSReplyTo() + { + return replyTo; + } + + public void setJMSReplyTo(Destination replyTo) throws JMSException + { + this.replyTo = DestinationUtil.convert(replyTo); + } + + public long getJMSTimestamp() + { + return timestamp; + } + + public void setJMSTimestamp(long timestamp) + { + this.timestamp = timestamp; + } + + public String getJMSType() + { + return type; + } + + public void setJMSType(String type) + { + this.type = type; + } + + public void clearProperties() + { + properties.clear(); + } + + public boolean propertyExists(String name) + { + return properties.containsKey(name); + } + + public boolean getBooleanProperty(String name) throws MessageFormatException + { + return TypeUtil.getBoolean(properties.get(name)); + } + + public byte getByteProperty(String name) throws MessageFormatException + { + return TypeUtil.getByte(properties.get(name)); + } + + public short getShortProperty(String name) throws MessageFormatException + { + return TypeUtil.getShort(properties.get(name)); + } + + public int getIntProperty(String name) throws MessageFormatException + { + return TypeUtil.getInt(properties.get(name)); + } + + public long getLongProperty(String name) throws MessageFormatException + { + return TypeUtil.getLong(properties.get(name)); + } + + public float getFloatProperty(String name) throws MessageFormatException + { + return TypeUtil.getFloat(properties.get(name)); + } + + public double getDoubleProperty(String name) throws MessageFormatException + { + return TypeUtil.getDouble(properties.get(name)); + } + + public String getStringProperty(String name) throws MessageFormatException + { + return TypeUtil.getString(properties.get(name)); + } + + public Object getObjectProperty(String name) + { + return properties.get(name); + } + + public Enumeration<String> getPropertyNames() + { + return Collections.enumeration(properties.keySet()); + } + + public void setBooleanProperty(String name, boolean value) throws JMSException + { + setProperty(name, value); + } + + public void setByteProperty(String name, byte value) throws JMSException + { + setProperty(name, value); + } + + public void setShortProperty(String name, short value) throws JMSException + { + setProperty(name, value); + } + + public void setIntProperty(String name, int value) throws JMSException + { + setProperty(name, value); + } + + public void setLongProperty(String name, long value) throws JMSException + { + setProperty(name, value); + } + + public void setFloatProperty(String name, float value) throws JMSException + { + setProperty(name, value); + } + + public void setDoubleProperty(String name, double value) throws JMSException + { + setProperty(name, value); + } + + public void setStringProperty(String name, String value) throws JMSException + { + setProperty(name, value); + } + + public void setObjectProperty(String name, Object value) throws JMSException + { + if (value instanceof Boolean || value instanceof Byte || value instanceof Short || value instanceof Integer + || value instanceof Long || value instanceof Float || value instanceof Double || value instanceof String + || value == null) + { + setProperty(name, value); + } + else + { + throw new MessageFormatException(MessageFormat.format( + Messages.getString("MessageImpl_11"), value.getClass().getName())); //$NON-NLS-1$ + } + } + + protected void setProperty(String name, Object value) throws JMSException + { + if (name == null) + { + throw new JMSException(MessageFormat.format(Messages.getString("MessageImpl_13"), name)); //$NON-NLS-1$ + } + + char[] chars = name.toCharArray(); + if (chars.length == 0) + { + throw new JMSException(MessageFormat.format(Messages.getString("MessageImpl_13"), name)); //$NON-NLS-1$ + } + + if (!Character.isJavaIdentifierStart(chars[0])) + { + throw new JMSException(MessageFormat.format(Messages.getString("MessageImpl_13"), name)); //$NON-NLS-1$ + } + + for (int i = 1; i < chars.length; ++i) + { + if (!Character.isJavaIdentifierPart(chars[i])) + { + throw new JMSException(MessageFormat.format(Messages.getString("MessageImpl_13"), name)); //$NON-NLS-1$ + } + } + + for (int i = 0; i < KEYWORDS.length; ++i) + { + if (name.equalsIgnoreCase(KEYWORDS[i])) + { + throw new JMSException(MessageFormat.format(Messages.getString("MessageImpl_13"), name)); //$NON-NLS-1$ + } + } + + properties.put(name, value); + } + + public void acknowledge() + { + if (receivingSession == null) + { + return; + } + + if (!receivingSession.isActive()) + { + return; + } + + if (receivingSession.getTransacted()) + { + return; + } + + if (receivingSession.getAcknowledgeMode() != Session.CLIENT_ACKNOWLEDGE) + { + return; + } + + receivingSession.acknowledgeMessages(receivingConsumer); + } + + public void clearBody() + { + throw new NotYetImplementedException(); + } + + public int compareTo(MessageImpl obj) + { + if (priority < obj.priority) + { + return -1; + } + + if (priority > obj.priority) + { + return 1; + } + + return 0; + } + + @SuppressWarnings("unchecked") + public void populate(Message source) throws JMSException + { + setJMSMessageID(source.getJMSMessageID()); + setJMSDestination(source.getJMSDestination()); + setJMSTimestamp(source.getJMSTimestamp()); + setJMSPriority(source.getJMSPriority()); + setJMSExpiration(source.getJMSExpiration()); + setJMSDeliveryMode(source.getJMSDeliveryMode()); + setJMSCorrelationID(source.getJMSCorrelationID()); + setJMSType(source.getJMSType()); + setJMSReplyTo(source.getJMSReplyTo()); + + Enumeration<String> e = source.getPropertyNames(); + while (e.hasMoreElements()) + { + String name = e.nextElement(); + Object value = source.getObjectProperty(name); + setObjectProperty(name, value); + } + } + + public void write(ExtendedDataOutputStream out) throws IOException + { + out.writeByteArray(correlationID); + out.writeByte(deliveryMode); + DestinationUtil.write(out, destination); + out.writeLong(expiration); + out.writeString(messageID); + out.writeByte(priority); + out.writeBoolean(redelivered); + DestinationUtil.write(out, replyTo); + out.writeLong(timestamp); + out.writeString(type); + + out.writeInt(properties.size()); + for (Entry<String, Object> entry : properties.entrySet()) + { + out.writeString(entry.getKey()); + TypeUtil.write(out, entry.getValue()); + } + } + + public void read(ExtendedDataInputStream in) throws IOException + { + correlationID = in.readByteArray(); + deliveryMode = in.readByte(); + destination = DestinationUtil.read(in); + expiration = in.readLong(); + messageID = in.readString(); + priority = in.readByte(); + redelivered = in.readBoolean(); + replyTo = DestinationUtil.read(in); + timestamp = in.readLong(); + type = in.readString(); + + int size = in.readInt(); + for (int i = 0; i < size; i++) + { + String key = in.readString(); + Object value = TypeUtil.read(in); + properties.put(key, value); + } + } +} diff --git a/plugins/org.eclipse.net4j.examples.installer/examples/org.eclipse.net4j.jms/src/org/eclipse/net4j/internal/jms/MessageProducerImpl.java b/plugins/org.eclipse.net4j.examples.installer/examples/org.eclipse.net4j.jms/src/org/eclipse/net4j/internal/jms/MessageProducerImpl.java new file mode 100644 index 0000000000..9f5d1b3ddc --- /dev/null +++ b/plugins/org.eclipse.net4j.examples.installer/examples/org.eclipse.net4j.jms/src/org/eclipse/net4j/internal/jms/MessageProducerImpl.java @@ -0,0 +1,160 @@ +/* + * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Eike Stepper - initial API and implementation + */ +package org.eclipse.net4j.internal.jms; + +import org.eclipse.net4j.internal.jms.messages.Messages; +import org.eclipse.net4j.util.lifecycle.Lifecycle; + +import javax.jms.DeliveryMode; +import javax.jms.Destination; +import javax.jms.JMSException; +import javax.jms.Message; +import javax.jms.MessageFormatException; +import javax.jms.MessageProducer; + +import java.util.Date; + +public class MessageProducerImpl extends Lifecycle implements MessageProducer +{ + private SessionImpl session; + + private DestinationImpl destination; + + private int deliveryMode = DeliveryMode.PERSISTENT; + + private int priority = Message.DEFAULT_PRIORITY; + + private long timeToLive; + + private boolean disableMessageTimestamp; + + private boolean disableMessageID; + + public MessageProducerImpl(SessionImpl session, DestinationImpl destination) + { + this.session = session; + this.destination = destination; + } + + public SessionImpl getSession() + { + return session; + } + + public int getDeliveryMode() + { + return deliveryMode; + } + + public void setDeliveryMode(int deliveryMode) + { + this.deliveryMode = deliveryMode; + } + + public int getPriority() + { + return priority; + } + + public void setPriority(int priority) + { + this.priority = priority; + } + + public long getTimeToLive() + { + return timeToLive; + } + + public void setTimeToLive(long timeToLive) + { + this.timeToLive = timeToLive; + } + + public DestinationImpl getDestination() + { + return destination; + } + + public boolean getDisableMessageID() + { + return disableMessageID; + } + + public void setDisableMessageID(boolean disableMessageID) + { + this.disableMessageID = disableMessageID; + } + + public boolean getDisableMessageTimestamp() + { + return disableMessageTimestamp; + } + + public void setDisableMessageTimestamp(boolean disableMessageTimestamp) + { + this.disableMessageTimestamp = disableMessageTimestamp; + } + + public void send(Message message) throws JMSException + { + send(getDestination(), message, getDeliveryMode(), getPriority(), getTimeToLive()); + } + + public void send(Message message, int deliveryMode, int priority, long timeToLive) throws JMSException + { + send(getDestination(), message, getDeliveryMode(), getPriority(), getTimeToLive()); + } + + public void send(Destination destination, Message message) throws JMSException + { + send(destination, message, getDeliveryMode(), getPriority(), getTimeToLive()); + } + + public void send(Destination destination, Message message, int deliveryMode, int priority, long timeToLive) + throws JMSException + { + if (message == null) + { + throw new MessageFormatException(Messages.getString("MessageProducerImpl_0")); //$NON-NLS-1$ + } + + // message.setJMSMessageID(MessageId.create()); + message.setJMSDestination(destination); + message.setJMSTimestamp(new Date().getTime()); + message.setJMSPriority(priority); + + if (timeToLive > 0) + { + message.setJMSExpiration(System.currentTimeMillis() + timeToLive); + } + else + { + message.setJMSExpiration(0); + } + + if (destination instanceof JMSTemporaryDestination) + { + message.setJMSDeliveryMode(DeliveryMode.NON_PERSISTENT); + } + else + { + message.setJMSDeliveryMode(deliveryMode); + } + + session.sendMessage(message); + } + + public void close() + { + throw new NotYetImplementedException(); + } +} diff --git a/plugins/org.eclipse.net4j.examples.installer/examples/org.eclipse.net4j.jms/src/org/eclipse/net4j/internal/jms/NotYetImplementedException.java b/plugins/org.eclipse.net4j.examples.installer/examples/org.eclipse.net4j.jms/src/org/eclipse/net4j/internal/jms/NotYetImplementedException.java new file mode 100644 index 0000000000..37df50ca25 --- /dev/null +++ b/plugins/org.eclipse.net4j.examples.installer/examples/org.eclipse.net4j.jms/src/org/eclipse/net4j/internal/jms/NotYetImplementedException.java @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Eike Stepper - initial API and implementation + */ +package org.eclipse.net4j.internal.jms; + +public class NotYetImplementedException extends RuntimeException +{ + private static final long serialVersionUID = 1L; + + public NotYetImplementedException() + { + } + + public NotYetImplementedException(String message) + { + super(message); + } + + public NotYetImplementedException(Throwable cause) + { + super(cause); + } + + public NotYetImplementedException(String message, Throwable cause) + { + super(message, cause); + } +} diff --git a/plugins/org.eclipse.net4j.examples.installer/examples/org.eclipse.net4j.jms/src/org/eclipse/net4j/internal/jms/ObjectMessageImpl.java b/plugins/org.eclipse.net4j.examples.installer/examples/org.eclipse.net4j.jms/src/org/eclipse/net4j/internal/jms/ObjectMessageImpl.java new file mode 100644 index 0000000000..c9193c0575 --- /dev/null +++ b/plugins/org.eclipse.net4j.examples.installer/examples/org.eclipse.net4j.jms/src/org/eclipse/net4j/internal/jms/ObjectMessageImpl.java @@ -0,0 +1,92 @@ +/* + * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Eike Stepper - initial API and implementation + */ +package org.eclipse.net4j.internal.jms; + +import org.eclipse.net4j.internal.jms.bundle.OM; +import org.eclipse.net4j.util.io.ExtendedDataInputStream; +import org.eclipse.net4j.util.io.ExtendedDataOutputStream; + +import javax.jms.JMSException; +import javax.jms.Message; +import javax.jms.ObjectMessage; + +import java.io.IOException; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; +import java.io.Serializable; + +public class ObjectMessageImpl extends MessageImpl implements ObjectMessage +{ + private Serializable object; + + public ObjectMessageImpl() + { + } + + public ObjectMessageImpl(Serializable object) + { + this.object = object; + } + + public Serializable getObject() + { + return object; + } + + public void setObject(Serializable object) + { + this.object = object; + } + + @Override + public void populate(Message source) throws JMSException + { + super.populate(source); + ObjectMessage object = (ObjectMessage)source; + setObject(object.getObject()); + } + + @Override + public void write(ExtendedDataOutputStream out) throws IOException + { + super.write(out); + if (object != null) + { + out.writeBoolean(true); + ObjectOutputStream stream = new ObjectOutputStream(out); + stream.writeObject(object); + } + else + { + out.writeBoolean(false); + } + } + + @Override + public void read(ExtendedDataInputStream in) throws IOException + { + super.read(in); + boolean notNull = in.readBoolean(); + if (notNull) + { + try + { + ObjectInputStream stream = new ObjectInputStream(in); + object = (Serializable)stream.readObject(); + } + catch (ClassNotFoundException ex) + { + OM.LOG.error(ex); + throw new IOException(ex.getMessage()); + } + } + } +} diff --git a/plugins/org.eclipse.net4j.examples.installer/examples/org.eclipse.net4j.jms/src/org/eclipse/net4j/internal/jms/QueueBrowserImpl.java b/plugins/org.eclipse.net4j.examples.installer/examples/org.eclipse.net4j.jms/src/org/eclipse/net4j/internal/jms/QueueBrowserImpl.java new file mode 100644 index 0000000000..5ae59878ae --- /dev/null +++ b/plugins/org.eclipse.net4j.examples.installer/examples/org.eclipse.net4j.jms/src/org/eclipse/net4j/internal/jms/QueueBrowserImpl.java @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Eike Stepper - initial API and implementation + */ +package org.eclipse.net4j.internal.jms; + +import javax.jms.Queue; +import javax.jms.QueueBrowser; + +import java.util.Enumeration; + +public class QueueBrowserImpl implements QueueBrowser +{ + private Queue queue; + + private String messageSelector; + + public QueueBrowserImpl(Queue queue, String messageSelector) + { + this.queue = queue; + this.messageSelector = messageSelector; + } + + public QueueBrowserImpl(Queue queue) + { + this(queue, null); + } + + public Queue getQueue() + { + return queue; + } + + public String getMessageSelector() + { + return messageSelector; + } + + public void close() + { + throw new NotYetImplementedException(); + } + + public Enumeration<?> getEnumeration() + { + throw new NotYetImplementedException(); + } +} diff --git a/plugins/org.eclipse.net4j.examples.installer/examples/org.eclipse.net4j.jms/src/org/eclipse/net4j/internal/jms/QueueImpl.java b/plugins/org.eclipse.net4j.examples.installer/examples/org.eclipse.net4j.jms/src/org/eclipse/net4j/internal/jms/QueueImpl.java new file mode 100644 index 0000000000..e3df26bd08 --- /dev/null +++ b/plugins/org.eclipse.net4j.examples.installer/examples/org.eclipse.net4j.jms/src/org/eclipse/net4j/internal/jms/QueueImpl.java @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Eike Stepper - initial API and implementation + */ +package org.eclipse.net4j.internal.jms; + +import javax.jms.Queue; + +public class QueueImpl extends DestinationImpl implements Queue +{ + private static final long serialVersionUID = 1L; + + private String queueName; + + public QueueImpl(String queueName) + { + this.queueName = queueName; + } + + public String getQueueName() + { + return queueName; + } + + public String getName() + { + return queueName; + } +} diff --git a/plugins/org.eclipse.net4j.examples.installer/examples/org.eclipse.net4j.jms/src/org/eclipse/net4j/internal/jms/QueueReceiverImpl.java b/plugins/org.eclipse.net4j.examples.installer/examples/org.eclipse.net4j.jms/src/org/eclipse/net4j/internal/jms/QueueReceiverImpl.java new file mode 100644 index 0000000000..cee70ee771 --- /dev/null +++ b/plugins/org.eclipse.net4j.examples.installer/examples/org.eclipse.net4j.jms/src/org/eclipse/net4j/internal/jms/QueueReceiverImpl.java @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Eike Stepper - initial API and implementation + */ +package org.eclipse.net4j.internal.jms; + +import javax.jms.QueueReceiver; + +public class QueueReceiverImpl extends MessageConsumerImpl implements QueueReceiver +{ + public QueueReceiverImpl(SessionImpl session, int id, QueueImpl queue, String messageSelector) + { + super(session, id, queue, messageSelector); + } + + public QueueImpl getQueue() + { + return (QueueImpl)getDestination(); + } +} diff --git a/plugins/org.eclipse.net4j.examples.installer/examples/org.eclipse.net4j.jms/src/org/eclipse/net4j/internal/jms/QueueSenderImpl.java b/plugins/org.eclipse.net4j.examples.installer/examples/org.eclipse.net4j.jms/src/org/eclipse/net4j/internal/jms/QueueSenderImpl.java new file mode 100644 index 0000000000..b240c1daca --- /dev/null +++ b/plugins/org.eclipse.net4j.examples.installer/examples/org.eclipse.net4j.jms/src/org/eclipse/net4j/internal/jms/QueueSenderImpl.java @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Eike Stepper - initial API and implementation + */ +package org.eclipse.net4j.internal.jms; + +import javax.jms.JMSException; +import javax.jms.Message; +import javax.jms.Queue; +import javax.jms.QueueSender; + +public class QueueSenderImpl extends MessageProducerImpl implements QueueSender +{ + public QueueSenderImpl(SessionImpl session, QueueImpl queue) + { + super(session, queue); + } + + public QueueImpl getQueue() + { + return (QueueImpl)getDestination(); + } + + public void send(Queue queue, Message message) throws JMSException + { + send(queue, message, getDeliveryMode(), getPriority(), getTimeToLive()); + } + + public void send(Queue queue, Message message, int deliveryMode, int priority, long timeToLive) throws JMSException + { + super.send(queue, message, deliveryMode, priority, timeToLive); + } +} diff --git a/plugins/org.eclipse.net4j.examples.installer/examples/org.eclipse.net4j.jms/src/org/eclipse/net4j/internal/jms/SessionImpl.java b/plugins/org.eclipse.net4j.examples.installer/examples/org.eclipse.net4j.jms/src/org/eclipse/net4j/internal/jms/SessionImpl.java new file mode 100644 index 0000000000..c1ec43bd5b --- /dev/null +++ b/plugins/org.eclipse.net4j.examples.installer/examples/org.eclipse.net4j.jms/src/org/eclipse/net4j/internal/jms/SessionImpl.java @@ -0,0 +1,455 @@ +/* + * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Eike Stepper - initial API and implementation + */ +package org.eclipse.net4j.internal.jms; + +import org.eclipse.net4j.internal.jms.bundle.OM; +import org.eclipse.net4j.internal.jms.messages.Messages; +import org.eclipse.net4j.internal.jms.protocol.JMSAcknowledgeRequest; +import org.eclipse.net4j.internal.jms.protocol.JMSClientMessageRequest; +import org.eclipse.net4j.internal.jms.protocol.JMSCommitRequest; +import org.eclipse.net4j.internal.jms.protocol.JMSRecoverRequest; +import org.eclipse.net4j.internal.jms.protocol.JMSRegisterConsumerRequest; +import org.eclipse.net4j.internal.jms.protocol.JMSRollbackRequest; +import org.eclipse.net4j.internal.jms.util.DestinationUtil; +import org.eclipse.net4j.internal.jms.util.MessageUtil; +import org.eclipse.net4j.util.concurrent.QueueWorker; +import org.eclipse.net4j.util.lifecycle.LifecycleUtil; +import org.eclipse.net4j.util.om.log.OMLogger; + +import javax.jms.BytesMessage; +import javax.jms.Destination; +import javax.jms.IllegalStateException; +import javax.jms.JMSException; +import javax.jms.MapMessage; +import javax.jms.Message; +import javax.jms.MessageConsumer; +import javax.jms.MessageListener; +import javax.jms.MessageProducer; +import javax.jms.ObjectMessage; +import javax.jms.Queue; +import javax.jms.QueueBrowser; +import javax.jms.Session; +import javax.jms.StreamMessage; +import javax.jms.TemporaryQueue; +import javax.jms.TemporaryTopic; +import javax.jms.TextMessage; +import javax.jms.Topic; +import javax.jms.TopicSubscriber; +import javax.transaction.TransactionRolledbackException; + +import java.io.Serializable; +import java.text.MessageFormat; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + +public class SessionImpl extends QueueWorker<MessageConsumerImpl> implements Session +{ + private ConnectionImpl connection; + + private int id; + + private boolean transacted; + + private int acknowledgeMode; + + private Map<Long, MessageConsumerImpl> consumers = new HashMap<Long, MessageConsumerImpl>(); + + /** + * Outgoing transacted messages + */ + private List<MessageImpl> messages = new ArrayList<MessageImpl>(); + + private Set<MessageProducerImpl> producers = new HashSet<MessageProducerImpl>(); + + public SessionImpl(ConnectionImpl connection, int id, boolean transacted, int acknowledgeMode) throws JMSException + { + this.connection = connection; + this.id = id; + this.transacted = transacted; + this.acknowledgeMode = acknowledgeMode; + + try + { + activate(); + } + catch (Exception ex) + { + throw new JMSException(ex.getMessage()); + } + } + + public ConnectionImpl getConnection() + { + return connection; + } + + public int getID() + { + return id; + } + + public boolean getTransacted() + { + return transacted; + } + + public int getAcknowledgeMode() + { + return acknowledgeMode; + } + + public MessageListener getMessageListener() + { + return null; + } + + public void setMessageListener(MessageListener listener) + { + throw new UnsupportedOperationException(); + } + + public MessageProducer createProducer(Destination destination) throws JMSException + { + DestinationImpl dest = DestinationUtil.convert(destination); + MessageProducerImpl producer = new MessageProducerImpl(this, dest); + producers.add(producer); + return producer; + } + + public MessageConsumer createConsumer(Destination destination) throws JMSException + { + return createConsumer(destination, null); + } + + public MessageConsumer createConsumer(Destination destination, String messageSelector) throws JMSException + { + return createConsumer(destination, null, false); + } + + public MessageConsumer createConsumer(Destination destination, String messageSelector, boolean noLocal) + throws JMSException + { + DestinationImpl dest = DestinationUtil.convert(destination); + long consumerID = registerConsumer(dest, messageSelector, noLocal, false); + MessageConsumerImpl consumer = new MessageConsumerImpl(this, consumerID, dest, messageSelector); + consumers.put(consumerID, consumer); + return consumer; + } + + public Queue createQueue(String queueName) + { + return new QueueImpl(queueName); + } + + public TemporaryQueue createTemporaryQueue() + { + return new TemporaryQueueImpl(); + } + + public QueueBrowser createBrowser(Queue queue) + { + return new QueueBrowserImpl(queue); + } + + public QueueBrowser createBrowser(Queue queue, String messageSelector) + { + return new QueueBrowserImpl(queue, messageSelector); + } + + public Topic createTopic(String topicName) + { + return new TopicImpl(topicName); + } + + public TemporaryTopic createTemporaryTopic() + { + return new TemporaryTopicImpl(); + } + + public TopicSubscriber createDurableSubscriber(Topic topic, String name) throws JMSException + { + return createDurableSubscriber(topic, name, null, false); + } + + public TopicSubscriber createDurableSubscriber(Topic topic, String name, String messageSelector, boolean noLocal) + throws JMSException + { + TopicImpl dest = (TopicImpl)DestinationUtil.convert(topic); + long consumerID = registerConsumer(dest, messageSelector, noLocal, true); + TopicSubscriberImpl subscriber = new TopicSubscriberImpl(this, consumerID, dest, name, messageSelector, noLocal); + consumers.put(consumerID, subscriber); + return subscriber; + } + + public void unsubscribe(String name) + { + throw new NotYetImplementedException(); + } + + public Message createMessage() + { + return new MessageImpl(); + } + + public StreamMessage createStreamMessage() + { + return new StreamMessageImpl(); + } + + public BytesMessage createBytesMessage() + { + return new BytesMessageImpl(); + } + + public MapMessage createMapMessage() + { + return new MapMessageImpl(); + } + + public ObjectMessage createObjectMessage() + { + return createObjectMessage(null); + } + + public ObjectMessage createObjectMessage(Serializable object) + { + return new ObjectMessageImpl(object); + } + + public TextMessage createTextMessage() + { + return createTextMessage(null); + } + + public TextMessage createTextMessage(String text) + { + return new TextMessageImpl(text); + } + + public void recover() throws JMSException + { + ensureNotTransacted(); + try + { + stop(); + new JMSRecoverRequest(connection.getProtocol(), id).send(); + start(); + } + catch (Exception ex) + { + OM.LOG.error(ex); + close(); + } + } + + public void commit() throws JMSException + { + ensureTransacted(); + synchronized (messages) + { + try + { + String[] messageIDs = new JMSCommitRequest(connection.getProtocol(), id, messages).send(); + if (messageIDs == null) + { + throw new TransactionRolledbackException(Messages.getString("SessionImpl_0")); //$NON-NLS-1$ + } + + for (int i = 0; i < messageIDs.length; i++) + { + messages.get(i).setJMSMessageID(messageIDs[i]); + } + + messages.clear(); + } + catch (JMSException ex) + { + throw ex; + } + catch (RuntimeException ex) + { + throw ex; + } + catch (Exception ex) + { + throw new JMSException(ex.getMessage()); + } + } + } + + public void rollback() throws JMSException + { + ensureTransacted(); + synchronized (messages) + { + try + { + if (!new JMSRollbackRequest(connection.getProtocol(), id).send()) + { + throw new JMSException(Messages.getString("SessionImpl_1")); //$NON-NLS-1$ + } + + messages.clear(); + } + catch (JMSException ex) + { + throw ex; + } + catch (RuntimeException ex) + { + throw ex; + } + catch (Exception ex) + { + throw new JMSException(ex.getMessage()); + } + } + } + + public void close() + { + LifecycleUtil.deactivate(this, OMLogger.Level.DEBUG); + } + + public void run() + { + throw new UnsupportedOperationException(); + } + + public long registerConsumer(DestinationImpl destination, String messageSelector, boolean noLocal, boolean durable) + throws JMSException + { + try + { + return new JMSRegisterConsumerRequest(connection.getProtocol(), id, destination, messageSelector, noLocal, + durable).send(); + } + catch (Exception ex) + { + throw new JMSException(ex.getMessage()); + } + } + + public void sendMessage(Message message) throws JMSException + { + if (getTransacted()) + { + synchronized (messages) + { + if (message instanceof MessageImpl) + { + messages.add(MessageUtil.copy(message)); + } + else + { + messages.add(MessageUtil.convert(message)); + } + } + } + else + { + try + { + MessageImpl impl = MessageUtil.convert(message); + JMSClientMessageRequest request = new JMSClientMessageRequest(connection.getProtocol(), impl); + String messageID = request.send(connection.getSendTimeout()); + if (messageID == null) + { + throw new JMSException(Messages.getString("SessionImpl_2")); //$NON-NLS-1$ + } + + message.setJMSMessageID(messageID); + } + catch (JMSException ex) + { + throw ex; + } + catch (RuntimeException ex) + { + throw ex; + } + catch (Exception ex) + { + throw new JMSException(ex.getMessage()); + } + } + } + + public boolean acknowledgeMessages(MessageConsumerImpl consumer) + { + try + { + new JMSAcknowledgeRequest(connection.getProtocol(), id).sendAsync(); + return true; + } + catch (Exception ex) + { + OM.LOG.error(ex); + return true; + } + } + + public void handleServerMessage(long consumerID, MessageImpl message) + { + message.setReceivingSession(this); + MessageConsumerImpl consumer = consumers.get(consumerID); + if (consumer == null) + { + OM.LOG.warn(MessageFormat.format(Messages.getString("SessionImpl_3"), consumerID)); //$NON-NLS-1$ + return; + } + + consumer.handleServerMessage(message); + } + + @Override + protected String getThreadName() + { + return "jms-session"; //$NON-NLS-1$ + } + + /** + * @since 2.0 + */ + @Override + protected void work(WorkContext context, MessageConsumerImpl consumer) + { + consumer.dispatchMessage(); + } + + private void ensureTransacted() throws IllegalStateException + { + if (!transacted) + { + throw new IllegalStateException("Session " + id + " not transacted"); //$NON-NLS-1$ //$NON-NLS-2$ + } + } + + private void ensureNotTransacted() throws IllegalStateException + { + if (transacted) + { + throw new IllegalStateException("Session " + id + " transacted"); //$NON-NLS-1$ //$NON-NLS-2$ + } + } + + private void start() + { + } + + private void stop() + { + } +} diff --git a/plugins/org.eclipse.net4j.examples.installer/examples/org.eclipse.net4j.jms/src/org/eclipse/net4j/internal/jms/StreamMessageImpl.java b/plugins/org.eclipse.net4j.examples.installer/examples/org.eclipse.net4j.jms/src/org/eclipse/net4j/internal/jms/StreamMessageImpl.java new file mode 100644 index 0000000000..2c0c6ac554 --- /dev/null +++ b/plugins/org.eclipse.net4j.examples.installer/examples/org.eclipse.net4j.jms/src/org/eclipse/net4j/internal/jms/StreamMessageImpl.java @@ -0,0 +1,175 @@ +/* + * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Eike Stepper - initial API and implementation + */ +package org.eclipse.net4j.internal.jms; + +import org.eclipse.net4j.util.io.ExtendedDataInputStream; +import org.eclipse.net4j.util.io.ExtendedDataOutputStream; + +import javax.jms.JMSException; +import javax.jms.Message; +import javax.jms.MessageEOFException; +import javax.jms.StreamMessage; + +import java.io.IOException; + +public class StreamMessageImpl extends MessageImpl implements StreamMessage +{ + public boolean readBoolean() + { + throw new NotYetImplementedException(); + } + + public byte readByte() + { + throw new NotYetImplementedException(); + } + + public int readBytes(byte[] value) + { + throw new NotYetImplementedException(); + } + + public char readChar() + { + throw new NotYetImplementedException(); + } + + public double readDouble() + { + throw new NotYetImplementedException(); + } + + public float readFloat() + { + throw new NotYetImplementedException(); + } + + public int readInt() + { + throw new NotYetImplementedException(); + } + + public long readLong() + { + throw new NotYetImplementedException(); + } + + public Object readObject() + { + throw new NotYetImplementedException(); + } + + public short readShort() + { + throw new NotYetImplementedException(); + } + + public String readString() + { + throw new NotYetImplementedException(); + } + + public void reset() + { + throw new NotYetImplementedException(); + } + + public void writeBoolean(boolean value) + { + throw new NotYetImplementedException(); + } + + public void writeByte(byte value) + { + throw new NotYetImplementedException(); + } + + public void writeBytes(byte[] value) + { + throw new NotYetImplementedException(); + } + + public void writeBytes(byte[] value, int offset, int length) + { + throw new NotYetImplementedException(); + } + + public void writeChar(char value) + { + throw new NotYetImplementedException(); + } + + public void writeDouble(double value) + { + throw new NotYetImplementedException(); + } + + public void writeFloat(float value) + { + throw new NotYetImplementedException(); + } + + public void writeInt(int value) + { + throw new NotYetImplementedException(); + } + + public void writeLong(long value) + { + throw new NotYetImplementedException(); + } + + public void writeObject(Object value) + { + throw new NotYetImplementedException(); + } + + public void writeShort(short value) + { + throw new NotYetImplementedException(); + } + + public void writeString(String value) + { + throw new NotYetImplementedException(); + } + + @Override + public void populate(Message source) throws JMSException + { + super.populate(source); + StreamMessage from = (StreamMessage)source; + from.reset(); + try + { + while (true) + { + Object object = from.readObject(); + writeObject(object); + } + } + catch (MessageEOFException ignore) + { + } + } + + @Override + public void write(ExtendedDataOutputStream out) throws IOException + { + super.write(out); + } + + @Override + public void read(ExtendedDataInputStream in) throws IOException + { + super.read(in); + } +} diff --git a/plugins/org.eclipse.net4j.examples.installer/examples/org.eclipse.net4j.jms/src/org/eclipse/net4j/internal/jms/TemporaryQueueImpl.java b/plugins/org.eclipse.net4j.examples.installer/examples/org.eclipse.net4j.jms/src/org/eclipse/net4j/internal/jms/TemporaryQueueImpl.java new file mode 100644 index 0000000000..781c6b65a8 --- /dev/null +++ b/plugins/org.eclipse.net4j.examples.installer/examples/org.eclipse.net4j.jms/src/org/eclipse/net4j/internal/jms/TemporaryQueueImpl.java @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Eike Stepper - initial API and implementation + */ +package org.eclipse.net4j.internal.jms; + +import javax.jms.TemporaryQueue; + +public class TemporaryQueueImpl extends QueueImpl implements TemporaryQueue +{ + private static final long serialVersionUID = 1L; + + private static int counter; + + public TemporaryQueueImpl() + { + super("TempQueue" + ++counter); //$NON-NLS-1$ + } + + public void delete() + { + throw new NotYetImplementedException(); + } +} diff --git a/plugins/org.eclipse.net4j.examples.installer/examples/org.eclipse.net4j.jms/src/org/eclipse/net4j/internal/jms/TemporaryTopicImpl.java b/plugins/org.eclipse.net4j.examples.installer/examples/org.eclipse.net4j.jms/src/org/eclipse/net4j/internal/jms/TemporaryTopicImpl.java new file mode 100644 index 0000000000..5d877f2098 --- /dev/null +++ b/plugins/org.eclipse.net4j.examples.installer/examples/org.eclipse.net4j.jms/src/org/eclipse/net4j/internal/jms/TemporaryTopicImpl.java @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Eike Stepper - initial API and implementation + */ +package org.eclipse.net4j.internal.jms; + +import javax.jms.TemporaryTopic; + +public class TemporaryTopicImpl extends TopicImpl implements TemporaryTopic +{ + private static final long serialVersionUID = 1L; + + private static int counter; + + public TemporaryTopicImpl() + { + super("TempTopic" + ++counter); //$NON-NLS-1$ + } + + public void delete() + { + throw new NotYetImplementedException(); + } +} diff --git a/plugins/org.eclipse.net4j.examples.installer/examples/org.eclipse.net4j.jms/src/org/eclipse/net4j/internal/jms/TextMessageImpl.java b/plugins/org.eclipse.net4j.examples.installer/examples/org.eclipse.net4j.jms/src/org/eclipse/net4j/internal/jms/TextMessageImpl.java new file mode 100644 index 0000000000..eb077e24ea --- /dev/null +++ b/plugins/org.eclipse.net4j.examples.installer/examples/org.eclipse.net4j.jms/src/org/eclipse/net4j/internal/jms/TextMessageImpl.java @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Eike Stepper - initial API and implementation + */ +package org.eclipse.net4j.internal.jms; + +import org.eclipse.net4j.util.io.ExtendedDataInputStream; +import org.eclipse.net4j.util.io.ExtendedDataOutputStream; + +import javax.jms.JMSException; +import javax.jms.Message; +import javax.jms.TextMessage; + +import java.io.IOException; + +public class TextMessageImpl extends MessageImpl implements TextMessage +{ + private String text; + + public TextMessageImpl() + { + } + + public TextMessageImpl(String text) + { + this.text = text; + } + + public String getText() + { + return text; + } + + public void setText(String text) + { + this.text = text; + } + + @Override + public void populate(Message source) throws JMSException + { + super.populate(source); + TextMessage text = (TextMessage)source; + setText(text.getText()); + } + + @Override + public void write(ExtendedDataOutputStream out) throws IOException + { + super.write(out); + out.writeString(text); + } + + @Override + public void read(ExtendedDataInputStream in) throws IOException + { + super.read(in); + text = in.readString(); + } +} diff --git a/plugins/org.eclipse.net4j.examples.installer/examples/org.eclipse.net4j.jms/src/org/eclipse/net4j/internal/jms/TopicImpl.java b/plugins/org.eclipse.net4j.examples.installer/examples/org.eclipse.net4j.jms/src/org/eclipse/net4j/internal/jms/TopicImpl.java new file mode 100644 index 0000000000..13fc819620 --- /dev/null +++ b/plugins/org.eclipse.net4j.examples.installer/examples/org.eclipse.net4j.jms/src/org/eclipse/net4j/internal/jms/TopicImpl.java @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Eike Stepper - initial API and implementation + */ +package org.eclipse.net4j.internal.jms; + +import javax.jms.Topic; + +public class TopicImpl extends DestinationImpl implements Topic +{ + private static final long serialVersionUID = 1L; + + private String topicName; + + public TopicImpl(String topicName) + { + this.topicName = topicName; + } + + public String getTopicName() + { + return topicName; + } + + public String getName() + { + return topicName; + } +} diff --git a/plugins/org.eclipse.net4j.examples.installer/examples/org.eclipse.net4j.jms/src/org/eclipse/net4j/internal/jms/TopicPublisherImpl.java b/plugins/org.eclipse.net4j.examples.installer/examples/org.eclipse.net4j.jms/src/org/eclipse/net4j/internal/jms/TopicPublisherImpl.java new file mode 100644 index 0000000000..aada738620 --- /dev/null +++ b/plugins/org.eclipse.net4j.examples.installer/examples/org.eclipse.net4j.jms/src/org/eclipse/net4j/internal/jms/TopicPublisherImpl.java @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Eike Stepper - initial API and implementation + */ +package org.eclipse.net4j.internal.jms; + +import javax.jms.JMSException; +import javax.jms.Message; +import javax.jms.Topic; +import javax.jms.TopicPublisher; + +public class TopicPublisherImpl extends MessageProducerImpl implements TopicPublisher +{ + public TopicPublisherImpl(SessionImpl session, TopicImpl topic) + { + super(session, topic); + } + + public TopicImpl getTopic() + { + return (TopicImpl)getDestination(); + } + + public void publish(Message message) throws JMSException + { + publish(getTopic(), message, getDeliveryMode(), getPriority(), getTimeToLive()); + } + + public void publish(Message message, int deliveryMode, int priority, long timeToLive) throws JMSException + { + publish(getTopic(), message, deliveryMode, priority, timeToLive); + } + + public void publish(Topic topic, Message message) throws JMSException + { + publish(topic, message, getDeliveryMode(), getPriority(), getTimeToLive()); + } + + public void publish(Topic topic, Message message, int deliveryMode, int priority, long timeToLive) + throws JMSException + { + send(topic, message, deliveryMode, priority, timeToLive); + } +} diff --git a/plugins/org.eclipse.net4j.examples.installer/examples/org.eclipse.net4j.jms/src/org/eclipse/net4j/internal/jms/TopicSubscriberImpl.java b/plugins/org.eclipse.net4j.examples.installer/examples/org.eclipse.net4j.jms/src/org/eclipse/net4j/internal/jms/TopicSubscriberImpl.java new file mode 100644 index 0000000000..08c4c2184e --- /dev/null +++ b/plugins/org.eclipse.net4j.examples.installer/examples/org.eclipse.net4j.jms/src/org/eclipse/net4j/internal/jms/TopicSubscriberImpl.java @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Eike Stepper - initial API and implementation + */ +package org.eclipse.net4j.internal.jms; + +import javax.jms.TopicSubscriber; + +public class TopicSubscriberImpl extends MessageConsumerImpl implements TopicSubscriber +{ + private String name; + + private boolean noLocal; + + public TopicSubscriberImpl(SessionImpl session, long id, TopicImpl topic, String name, String messageSelector, + boolean noLocal) + { + super(session, id, topic, messageSelector); + this.name = name; + this.noLocal = noLocal; + } + + public boolean getNoLocal() + { + return noLocal; + } + + public TopicImpl getTopic() + { + return (TopicImpl)getDestination(); + } + + public String getName() + { + return name; + } +} diff --git a/plugins/org.eclipse.net4j.examples.installer/examples/org.eclipse.net4j.jms/src/org/eclipse/net4j/internal/jms/bundle/OM.java b/plugins/org.eclipse.net4j.examples.installer/examples/org.eclipse.net4j.jms/src/org/eclipse/net4j/internal/jms/bundle/OM.java new file mode 100644 index 0000000000..26aed04d24 --- /dev/null +++ b/plugins/org.eclipse.net4j.examples.installer/examples/org.eclipse.net4j.jms/src/org/eclipse/net4j/internal/jms/bundle/OM.java @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Eike Stepper - initial API and implementation + */ +package org.eclipse.net4j.internal.jms.bundle; + +import org.eclipse.net4j.jms.JMSUtil; +import org.eclipse.net4j.util.container.IPluginContainer; +import org.eclipse.net4j.util.om.OMBundle; +import org.eclipse.net4j.util.om.OMPlatform; +import org.eclipse.net4j.util.om.OSGiActivator; +import org.eclipse.net4j.util.om.log.OMLogger; +import org.eclipse.net4j.util.om.trace.OMTracer; + +/** + * The <em>Operations & Maintenance</em> class of this bundle. + * + * @author Eike Stepper + */ +public abstract class OM +{ + public static final String BUNDLE_ID = "org.eclipse.net4j.jms"; //$NON-NLS-1$ + + public static final OMBundle BUNDLE = OMPlatform.INSTANCE.bundle(BUNDLE_ID, OM.class); + + public static final OMTracer DEBUG = BUNDLE.tracer("debug"); //$NON-NLS-1$ + + public static final OMTracer DEBUG_PROTOCOL = DEBUG.tracer("protocol"); //$NON-NLS-1$ + + public static final OMLogger LOG = BUNDLE.logger(); + + static void start() throws Exception + { + JMSUtil.setTransportContainer(IPluginContainer.INSTANCE); + } + + /** + * @author Eike Stepper + */ + public static final class Activator extends OSGiActivator + { + public Activator() + { + super(BUNDLE); + } + } +} diff --git a/plugins/org.eclipse.net4j.examples.installer/examples/org.eclipse.net4j.jms/src/org/eclipse/net4j/internal/jms/messages/Messages.java b/plugins/org.eclipse.net4j.examples.installer/examples/org.eclipse.net4j.jms/src/org/eclipse/net4j/internal/jms/messages/Messages.java new file mode 100644 index 0000000000..3ff414fbec --- /dev/null +++ b/plugins/org.eclipse.net4j.examples.installer/examples/org.eclipse.net4j.jms/src/org/eclipse/net4j/internal/jms/messages/Messages.java @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Victor Roldan Betancort - initial API and implementation + * Eike Stepper - maintenance + */ +package org.eclipse.net4j.internal.jms.messages; + +import java.util.MissingResourceException; +import java.util.ResourceBundle; + +/** + * @author Victor Roldan Betancort + */ +public class Messages +{ + private static final String BUNDLE_NAME = "org.eclipse.net4j.internal.jms.messages.messages"; //$NON-NLS-1$ + + private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle.getBundle(BUNDLE_NAME); + + private Messages() + { + } + + public static String getString(String key) + { + try + { + return RESOURCE_BUNDLE.getString(key); + } + catch (MissingResourceException e) + { + return '!' + key + '!'; + } + } +} diff --git a/plugins/org.eclipse.net4j.examples.installer/examples/org.eclipse.net4j.jms/src/org/eclipse/net4j/internal/jms/messages/messages.properties b/plugins/org.eclipse.net4j.examples.installer/examples/org.eclipse.net4j.jms/src/org/eclipse/net4j/internal/jms/messages/messages.properties new file mode 100644 index 0000000000..3523f413c3 --- /dev/null +++ b/plugins/org.eclipse.net4j.examples.installer/examples/org.eclipse.net4j.jms/src/org/eclipse/net4j/internal/jms/messages/messages.properties @@ -0,0 +1,22 @@ +# Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others. +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Eclipse Public License v1.0 +# which accompanies this distribution, and is available at +# http://www.eclipse.org/legal/epl-v10.html +# +# Contributors: +# Victor Roldan Betancort - initial API and implementation +# Eike Stepper - maintenance + +ConnectionImpl_0=No transport container available +ConnectionImpl_1=Server rejected logon request +ConnectionImpl_2=Server rejected open session request +MessageConsumerImpl.0=Consumer is configured for asynchronous delivery +MessageConsumerImpl.1=No message to dispatch +MessageImpl_11=Values of type {0} are not supported +MessageImpl_13=Invalid property name {0} +MessageProducerImpl_0=Null message +SessionImpl_0=Transaction rolled back by JMS server +SessionImpl_1=JMS server failed to rolled back transaction +SessionImpl_2=Message not accepted by JMS server +SessionImpl_3=Consumer {0} not found. Discarding message. diff --git a/plugins/org.eclipse.net4j.examples.installer/examples/org.eclipse.net4j.jms/src/org/eclipse/net4j/internal/jms/protocol/JMSAcknowledgeRequest.java b/plugins/org.eclipse.net4j.examples.installer/examples/org.eclipse.net4j.jms/src/org/eclipse/net4j/internal/jms/protocol/JMSAcknowledgeRequest.java new file mode 100644 index 0000000000..12725979fc --- /dev/null +++ b/plugins/org.eclipse.net4j.examples.installer/examples/org.eclipse.net4j.jms/src/org/eclipse/net4j/internal/jms/protocol/JMSAcknowledgeRequest.java @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Eike Stepper - initial API and implementation + */ +package org.eclipse.net4j.internal.jms.protocol; + +import org.eclipse.net4j.jms.JMSProtocolConstants; +import org.eclipse.net4j.signal.Request; +import org.eclipse.net4j.util.io.ExtendedDataOutputStream; + +/** + * @author Eike Stepper + */ +public class JMSAcknowledgeRequest extends Request +{ + private int sessionID; + + /** + * @since 2.0 + */ + public JMSAcknowledgeRequest(JMSClientProtocol protocol, int sessionID) + { + super(protocol, JMSProtocolConstants.SIGNAL_ACKNOWLEDGE); + this.sessionID = sessionID; + } + + @Override + protected void requesting(ExtendedDataOutputStream out) throws Exception + { + out.writeInt(sessionID); + } +} diff --git a/plugins/org.eclipse.net4j.examples.installer/examples/org.eclipse.net4j.jms/src/org/eclipse/net4j/internal/jms/protocol/JMSClientMessageRequest.java b/plugins/org.eclipse.net4j.examples.installer/examples/org.eclipse.net4j.jms/src/org/eclipse/net4j/internal/jms/protocol/JMSClientMessageRequest.java new file mode 100644 index 0000000000..e69dbe9138 --- /dev/null +++ b/plugins/org.eclipse.net4j.examples.installer/examples/org.eclipse.net4j.jms/src/org/eclipse/net4j/internal/jms/protocol/JMSClientMessageRequest.java @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Eike Stepper - initial API and implementation + */ +package org.eclipse.net4j.internal.jms.protocol; + +import org.eclipse.net4j.internal.jms.MessageImpl; +import org.eclipse.net4j.internal.jms.util.MessageUtil; +import org.eclipse.net4j.jms.JMSProtocolConstants; +import org.eclipse.net4j.signal.RequestWithConfirmation; +import org.eclipse.net4j.util.io.ExtendedDataInputStream; +import org.eclipse.net4j.util.io.ExtendedDataOutputStream; + +/** + * @author Eike Stepper + */ +public class JMSClientMessageRequest extends RequestWithConfirmation<String> +{ + private MessageImpl message; + + /** + * @since 2.0 + */ + public JMSClientMessageRequest(JMSClientProtocol protocol, MessageImpl message) + { + super(protocol, JMSProtocolConstants.SIGNAL_CLIENT_MESSAGE); + this.message = message; + } + + @Override + protected void requesting(ExtendedDataOutputStream out) throws Exception + { + MessageUtil.write(out, message); + } + + @Override + protected String confirming(ExtendedDataInputStream in) throws Exception + { + return in.readString(); + } +} diff --git a/plugins/org.eclipse.net4j.examples.installer/examples/org.eclipse.net4j.jms/src/org/eclipse/net4j/internal/jms/protocol/JMSClientProtocol.java b/plugins/org.eclipse.net4j.examples.installer/examples/org.eclipse.net4j.jms/src/org/eclipse/net4j/internal/jms/protocol/JMSClientProtocol.java new file mode 100644 index 0000000000..6781d677ed --- /dev/null +++ b/plugins/org.eclipse.net4j.examples.installer/examples/org.eclipse.net4j.jms/src/org/eclipse/net4j/internal/jms/protocol/JMSClientProtocol.java @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Eike Stepper - initial API and implementation + */ +package org.eclipse.net4j.internal.jms.protocol; + +import org.eclipse.net4j.internal.jms.ConnectionImpl; +import org.eclipse.net4j.jms.JMSProtocolConstants; +import org.eclipse.net4j.signal.SignalProtocol; +import org.eclipse.net4j.signal.SignalReactor; + +/** + * @author Eike Stepper + */ +public class JMSClientProtocol extends SignalProtocol<ConnectionImpl> +{ + /** + * @since 2.0 + */ + public JMSClientProtocol(ConnectionImpl connection) + { + super(JMSProtocolConstants.PROTOCOL_NAME); + setInfraStructure(connection); + } + + @Override + protected SignalReactor createSignalReactor(short signalID) + { + switch (signalID) + { + case JMSProtocolConstants.SIGNAL_SERVER_MESSAGE: + return new JMSServerMessageIndication(this); + + default: + return super.createSignalReactor(signalID); + } + } +} diff --git a/plugins/org.eclipse.net4j.examples.installer/examples/org.eclipse.net4j.jms/src/org/eclipse/net4j/internal/jms/protocol/JMSCloseSessionRequest.java b/plugins/org.eclipse.net4j.examples.installer/examples/org.eclipse.net4j.jms/src/org/eclipse/net4j/internal/jms/protocol/JMSCloseSessionRequest.java new file mode 100644 index 0000000000..d751b7c286 --- /dev/null +++ b/plugins/org.eclipse.net4j.examples.installer/examples/org.eclipse.net4j.jms/src/org/eclipse/net4j/internal/jms/protocol/JMSCloseSessionRequest.java @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Eike Stepper - initial API and implementation + */ +package org.eclipse.net4j.internal.jms.protocol; + +import org.eclipse.net4j.jms.JMSProtocolConstants; +import org.eclipse.net4j.signal.RequestWithConfirmation; +import org.eclipse.net4j.util.io.ExtendedDataInputStream; +import org.eclipse.net4j.util.io.ExtendedDataOutputStream; + +/** + * @author Eike Stepper + */ +public class JMSCloseSessionRequest extends RequestWithConfirmation<Boolean> +{ + private int sessionID; + + /** + * @since 2.0 + */ + public JMSCloseSessionRequest(JMSClientProtocol protocol, int sessionID) + { + super(protocol, JMSProtocolConstants.SIGNAL_CLOSE_SESSION); + this.sessionID = sessionID; + } + + @Override + protected void requesting(ExtendedDataOutputStream out) throws Exception + { + out.writeInt(sessionID); + } + + @Override + protected Boolean confirming(ExtendedDataInputStream in) throws Exception + { + return in.readBoolean(); + } +} diff --git a/plugins/org.eclipse.net4j.examples.installer/examples/org.eclipse.net4j.jms/src/org/eclipse/net4j/internal/jms/protocol/JMSCommitRequest.java b/plugins/org.eclipse.net4j.examples.installer/examples/org.eclipse.net4j.jms/src/org/eclipse/net4j/internal/jms/protocol/JMSCommitRequest.java new file mode 100644 index 0000000000..9e61552ddf --- /dev/null +++ b/plugins/org.eclipse.net4j.examples.installer/examples/org.eclipse.net4j.jms/src/org/eclipse/net4j/internal/jms/protocol/JMSCommitRequest.java @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Eike Stepper - initial API and implementation + */ +package org.eclipse.net4j.internal.jms.protocol; + +import org.eclipse.net4j.internal.jms.MessageImpl; +import org.eclipse.net4j.internal.jms.util.MessageUtil; +import org.eclipse.net4j.jms.JMSProtocolConstants; +import org.eclipse.net4j.signal.RequestWithConfirmation; +import org.eclipse.net4j.util.io.ExtendedDataInputStream; +import org.eclipse.net4j.util.io.ExtendedDataOutputStream; + +import java.util.List; + +/** + * @author Eike Stepper + */ +public class JMSCommitRequest extends RequestWithConfirmation<String[]> +{ + private int sessionID; + + private List<MessageImpl> messages; + + /** + * @since 2.0 + */ + public JMSCommitRequest(JMSClientProtocol protocol, int sessionID, List<MessageImpl> messages) + { + super(protocol, JMSProtocolConstants.SIGNAL_COMMIT); + this.sessionID = sessionID; + this.messages = messages; + } + + @Override + protected void requesting(ExtendedDataOutputStream out) throws Exception + { + out.writeInt(sessionID); + out.writeInt(messages.size()); + for (MessageImpl message : messages) + { + MessageUtil.write(out, message); + } + } + + @Override + protected String[] confirming(ExtendedDataInputStream in) throws Exception + { + int size = in.readInt(); + if (size == -1) + { + return null; + } + + String[] messageIDs = new String[size]; + for (int i = 0; i < size; i++) + { + messageIDs[i] = in.readString(); + } + + return messageIDs; + } +} diff --git a/plugins/org.eclipse.net4j.examples.installer/examples/org.eclipse.net4j.jms/src/org/eclipse/net4j/internal/jms/protocol/JMSDeregisterConsumerRequest.java b/plugins/org.eclipse.net4j.examples.installer/examples/org.eclipse.net4j.jms/src/org/eclipse/net4j/internal/jms/protocol/JMSDeregisterConsumerRequest.java new file mode 100644 index 0000000000..312b76c621 --- /dev/null +++ b/plugins/org.eclipse.net4j.examples.installer/examples/org.eclipse.net4j.jms/src/org/eclipse/net4j/internal/jms/protocol/JMSDeregisterConsumerRequest.java @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Eike Stepper - initial API and implementation + */ +package org.eclipse.net4j.internal.jms.protocol; + +import org.eclipse.net4j.jms.JMSProtocolConstants; +import org.eclipse.net4j.signal.RequestWithConfirmation; +import org.eclipse.net4j.util.io.ExtendedDataInputStream; +import org.eclipse.net4j.util.io.ExtendedDataOutputStream; + +/** + * @author Eike Stepper + */ +public class JMSDeregisterConsumerRequest extends RequestWithConfirmation<Boolean> +{ + private int sessionID; + + private long consumerID; + + /** + * @since 2.0 + */ + public JMSDeregisterConsumerRequest(JMSClientProtocol protocol, int sessionID, long consumerID) + { + super(protocol, JMSProtocolConstants.SIGNAL_DEREGISTER_CONSUMER); + this.sessionID = sessionID; + this.consumerID = consumerID; + } + + @Override + protected void requesting(ExtendedDataOutputStream out) throws Exception + { + out.writeInt(sessionID); + out.writeLong(consumerID); + } + + @Override + protected Boolean confirming(ExtendedDataInputStream in) throws Exception + { + return in.readBoolean(); + } +} diff --git a/plugins/org.eclipse.net4j.examples.installer/examples/org.eclipse.net4j.jms/src/org/eclipse/net4j/internal/jms/protocol/JMSLogoffRequest.java b/plugins/org.eclipse.net4j.examples.installer/examples/org.eclipse.net4j.jms/src/org/eclipse/net4j/internal/jms/protocol/JMSLogoffRequest.java new file mode 100644 index 0000000000..f555a4c92a --- /dev/null +++ b/plugins/org.eclipse.net4j.examples.installer/examples/org.eclipse.net4j.jms/src/org/eclipse/net4j/internal/jms/protocol/JMSLogoffRequest.java @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Eike Stepper - initial API and implementation + */ +package org.eclipse.net4j.internal.jms.protocol; + +import org.eclipse.net4j.jms.JMSProtocolConstants; +import org.eclipse.net4j.signal.Request; +import org.eclipse.net4j.util.io.ExtendedDataOutputStream; + +/** + * @author Eike Stepper + */ +public class JMSLogoffRequest extends Request +{ + /** + * @since 2.0 + */ + public JMSLogoffRequest(JMSClientProtocol protocol) + { + super(protocol, JMSProtocolConstants.SIGNAL_LOGOFF); + } + + @Override + protected void requesting(ExtendedDataOutputStream out) throws Exception + { + } +} diff --git a/plugins/org.eclipse.net4j.examples.installer/examples/org.eclipse.net4j.jms/src/org/eclipse/net4j/internal/jms/protocol/JMSLogonRequest.java b/plugins/org.eclipse.net4j.examples.installer/examples/org.eclipse.net4j.jms/src/org/eclipse/net4j/internal/jms/protocol/JMSLogonRequest.java new file mode 100644 index 0000000000..a175e9e1c8 --- /dev/null +++ b/plugins/org.eclipse.net4j.examples.installer/examples/org.eclipse.net4j.jms/src/org/eclipse/net4j/internal/jms/protocol/JMSLogonRequest.java @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Eike Stepper - initial API and implementation + */ +package org.eclipse.net4j.internal.jms.protocol; + +import org.eclipse.net4j.jms.JMSProtocolConstants; +import org.eclipse.net4j.signal.RequestWithConfirmation; +import org.eclipse.net4j.util.io.ExtendedDataInputStream; +import org.eclipse.net4j.util.io.ExtendedDataOutputStream; + +/** + * @author Eike Stepper + */ +public class JMSLogonRequest extends RequestWithConfirmation<Boolean> +{ + private String userName; + + private String password; + + /** + * @since 2.0 + */ + public JMSLogonRequest(JMSClientProtocol protocol, String userName, String password) + { + super(protocol, JMSProtocolConstants.SIGNAL_LOGON); + this.userName = userName; + this.password = password; + } + + @Override + protected void requesting(ExtendedDataOutputStream out) throws Exception + { + out.writeString(userName); + out.writeString(password); + } + + @Override + protected Boolean confirming(ExtendedDataInputStream in) throws Exception + { + return in.readBoolean(); + } +} diff --git a/plugins/org.eclipse.net4j.examples.installer/examples/org.eclipse.net4j.jms/src/org/eclipse/net4j/internal/jms/protocol/JMSOpenSessionRequest.java b/plugins/org.eclipse.net4j.examples.installer/examples/org.eclipse.net4j.jms/src/org/eclipse/net4j/internal/jms/protocol/JMSOpenSessionRequest.java new file mode 100644 index 0000000000..d12d93fca3 --- /dev/null +++ b/plugins/org.eclipse.net4j.examples.installer/examples/org.eclipse.net4j.jms/src/org/eclipse/net4j/internal/jms/protocol/JMSOpenSessionRequest.java @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Eike Stepper - initial API and implementation + */ +package org.eclipse.net4j.internal.jms.protocol; + +import org.eclipse.net4j.jms.JMSProtocolConstants; +import org.eclipse.net4j.signal.RequestWithConfirmation; +import org.eclipse.net4j.util.io.ExtendedDataInputStream; +import org.eclipse.net4j.util.io.ExtendedDataOutputStream; + +/** + * @author Eike Stepper + */ +public class JMSOpenSessionRequest extends RequestWithConfirmation<Boolean> +{ + private int sessionID; + + /** + * @since 2.0 + */ + public JMSOpenSessionRequest(JMSClientProtocol protocol, int sessionID) + { + super(protocol, JMSProtocolConstants.SIGNAL_OPEN_SESSION); + this.sessionID = sessionID; + } + + @Override + protected void requesting(ExtendedDataOutputStream out) throws Exception + { + out.writeInt(sessionID); + } + + @Override + protected Boolean confirming(ExtendedDataInputStream in) throws Exception + { + return in.readBoolean(); + } +} diff --git a/plugins/org.eclipse.net4j.examples.installer/examples/org.eclipse.net4j.jms/src/org/eclipse/net4j/internal/jms/protocol/JMSRecoverRequest.java b/plugins/org.eclipse.net4j.examples.installer/examples/org.eclipse.net4j.jms/src/org/eclipse/net4j/internal/jms/protocol/JMSRecoverRequest.java new file mode 100644 index 0000000000..c7e5010958 --- /dev/null +++ b/plugins/org.eclipse.net4j.examples.installer/examples/org.eclipse.net4j.jms/src/org/eclipse/net4j/internal/jms/protocol/JMSRecoverRequest.java @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Eike Stepper - initial API and implementation + */ +package org.eclipse.net4j.internal.jms.protocol; + +import org.eclipse.net4j.jms.JMSProtocolConstants; +import org.eclipse.net4j.signal.RequestWithConfirmation; +import org.eclipse.net4j.util.io.ExtendedDataInputStream; +import org.eclipse.net4j.util.io.ExtendedDataOutputStream; + +/** + * @author Eike Stepper + */ +public class JMSRecoverRequest extends RequestWithConfirmation<Object> +{ + private int sessionID; + + /** + * @since 2.0 + */ + public JMSRecoverRequest(JMSClientProtocol protocol, int sessionID) + { + super(protocol, JMSProtocolConstants.SIGNAL_RECOVER); + this.sessionID = sessionID; + } + + @Override + protected void requesting(ExtendedDataOutputStream out) throws Exception + { + out.writeInt(sessionID); + } + + @Override + protected Object confirming(ExtendedDataInputStream in) throws Exception + { + return null; + } +} diff --git a/plugins/org.eclipse.net4j.examples.installer/examples/org.eclipse.net4j.jms/src/org/eclipse/net4j/internal/jms/protocol/JMSRegisterConsumerRequest.java b/plugins/org.eclipse.net4j.examples.installer/examples/org.eclipse.net4j.jms/src/org/eclipse/net4j/internal/jms/protocol/JMSRegisterConsumerRequest.java new file mode 100644 index 0000000000..d1ad44e456 --- /dev/null +++ b/plugins/org.eclipse.net4j.examples.installer/examples/org.eclipse.net4j.jms/src/org/eclipse/net4j/internal/jms/protocol/JMSRegisterConsumerRequest.java @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Eike Stepper - initial API and implementation + */ +package org.eclipse.net4j.internal.jms.protocol; + +import org.eclipse.net4j.internal.jms.DestinationImpl; +import org.eclipse.net4j.internal.jms.util.DestinationUtil; +import org.eclipse.net4j.jms.JMSProtocolConstants; +import org.eclipse.net4j.signal.RequestWithConfirmation; +import org.eclipse.net4j.util.io.ExtendedDataInputStream; +import org.eclipse.net4j.util.io.ExtendedDataOutputStream; + +/** + * @author Eike Stepper + */ +public class JMSRegisterConsumerRequest extends RequestWithConfirmation<Long> +{ + private int sessionID; + + private DestinationImpl destination; + + private String messageSelector; + + private boolean noLocal; + + private boolean durable; + + /** + * @since 2.0 + */ + public JMSRegisterConsumerRequest(JMSClientProtocol protocol, int sessionID, DestinationImpl destination, + String messageSelector, boolean noLocal, boolean durable) + { + super(protocol, JMSProtocolConstants.SIGNAL_REGISTER_CONSUMER); + this.sessionID = sessionID; + this.destination = destination; + this.messageSelector = messageSelector; + this.noLocal = noLocal; + this.durable = durable; + } + + @Override + protected void requesting(ExtendedDataOutputStream out) throws Exception + { + out.writeInt(sessionID); + DestinationUtil.write(out, destination); + out.writeString(messageSelector); + out.writeBoolean(noLocal); + out.writeBoolean(durable); + } + + @Override + protected Long confirming(ExtendedDataInputStream in) throws Exception + { + return in.readLong(); + } +} diff --git a/plugins/org.eclipse.net4j.examples.installer/examples/org.eclipse.net4j.jms/src/org/eclipse/net4j/internal/jms/protocol/JMSRollbackRequest.java b/plugins/org.eclipse.net4j.examples.installer/examples/org.eclipse.net4j.jms/src/org/eclipse/net4j/internal/jms/protocol/JMSRollbackRequest.java new file mode 100644 index 0000000000..18c6e9beb4 --- /dev/null +++ b/plugins/org.eclipse.net4j.examples.installer/examples/org.eclipse.net4j.jms/src/org/eclipse/net4j/internal/jms/protocol/JMSRollbackRequest.java @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Eike Stepper - initial API and implementation + */ +package org.eclipse.net4j.internal.jms.protocol; + +import org.eclipse.net4j.jms.JMSProtocolConstants; +import org.eclipse.net4j.signal.RequestWithConfirmation; +import org.eclipse.net4j.util.io.ExtendedDataInputStream; +import org.eclipse.net4j.util.io.ExtendedDataOutputStream; + +/** + * @author Eike Stepper + */ +public class JMSRollbackRequest extends RequestWithConfirmation<Boolean> +{ + private int sessionID; + + /** + * @since 2.0 + */ + public JMSRollbackRequest(JMSClientProtocol protocol, int sessionID) + { + super(protocol, JMSProtocolConstants.SIGNAL_ROLLBACK); + this.sessionID = sessionID; + } + + @Override + protected void requesting(ExtendedDataOutputStream out) throws Exception + { + out.writeInt(sessionID); + } + + @Override + protected Boolean confirming(ExtendedDataInputStream in) throws Exception + { + return in.readBoolean(); + } +} diff --git a/plugins/org.eclipse.net4j.examples.installer/examples/org.eclipse.net4j.jms/src/org/eclipse/net4j/internal/jms/protocol/JMSServerMessageIndication.java b/plugins/org.eclipse.net4j.examples.installer/examples/org.eclipse.net4j.jms/src/org/eclipse/net4j/internal/jms/protocol/JMSServerMessageIndication.java new file mode 100644 index 0000000000..3f1da2b156 --- /dev/null +++ b/plugins/org.eclipse.net4j.examples.installer/examples/org.eclipse.net4j.jms/src/org/eclipse/net4j/internal/jms/protocol/JMSServerMessageIndication.java @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Eike Stepper - initial API and implementation + */ +package org.eclipse.net4j.internal.jms.protocol; + +import org.eclipse.net4j.internal.jms.ConnectionImpl; +import org.eclipse.net4j.internal.jms.MessageImpl; +import org.eclipse.net4j.internal.jms.util.MessageUtil; +import org.eclipse.net4j.jms.JMSProtocolConstants; +import org.eclipse.net4j.signal.Indication; +import org.eclipse.net4j.util.io.ExtendedDataInputStream; + +/** + * @author Eike Stepper + */ +public class JMSServerMessageIndication extends Indication +{ + /** + * @since 2.0 + */ + public JMSServerMessageIndication(JMSClientProtocol protocol) + { + super(protocol, JMSProtocolConstants.SIGNAL_SERVER_MESSAGE); + } + + @Override + protected void indicating(ExtendedDataInputStream in) throws Exception + { + int sessionID = in.readInt(); + long consumerID = in.readLong(); + MessageImpl message = MessageUtil.read(in); + JMSClientProtocol protocol = (JMSClientProtocol)getProtocol(); + ConnectionImpl connection = protocol.getInfraStructure(); + connection.handleMessageFromSignal(sessionID, consumerID, message); + } +} diff --git a/plugins/org.eclipse.net4j.examples.installer/examples/org.eclipse.net4j.jms/src/org/eclipse/net4j/internal/jms/protocol/JMSSyncRequest.java b/plugins/org.eclipse.net4j.examples.installer/examples/org.eclipse.net4j.jms/src/org/eclipse/net4j/internal/jms/protocol/JMSSyncRequest.java new file mode 100644 index 0000000000..cf62439a22 --- /dev/null +++ b/plugins/org.eclipse.net4j.examples.installer/examples/org.eclipse.net4j.jms/src/org/eclipse/net4j/internal/jms/protocol/JMSSyncRequest.java @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Eike Stepper - initial API and implementation + */ +package org.eclipse.net4j.internal.jms.protocol; + +import org.eclipse.net4j.jms.JMSProtocolConstants; +import org.eclipse.net4j.signal.RequestWithConfirmation; +import org.eclipse.net4j.util.io.ExtendedDataInputStream; +import org.eclipse.net4j.util.io.ExtendedDataOutputStream; + +/** + * @author Eike Stepper + */ +public class JMSSyncRequest extends RequestWithConfirmation<Long> +{ + private long clientTime0; + + /** + * @since 2.0 + */ + public JMSSyncRequest(JMSClientProtocol protocol) + { + super(protocol, JMSProtocolConstants.SIGNAL_SYNC); + } + + @Override + protected void requesting(ExtendedDataOutputStream out) throws Exception + { + clientTime0 = System.currentTimeMillis(); + } + + @Override + protected Long confirming(ExtendedDataInputStream in) throws Exception + { + long serverTime = in.readLong(); + long clientTime1 = System.currentTimeMillis(); + long roundTripDuration = clientTime1 - clientTime0; + return serverTime + roundTripDuration / 2; + } +} diff --git a/plugins/org.eclipse.net4j.examples.installer/examples/org.eclipse.net4j.jms/src/org/eclipse/net4j/internal/jms/util/DestinationUtil.java b/plugins/org.eclipse.net4j.examples.installer/examples/org.eclipse.net4j.jms/src/org/eclipse/net4j/internal/jms/util/DestinationUtil.java new file mode 100644 index 0000000000..711d978525 --- /dev/null +++ b/plugins/org.eclipse.net4j.examples.installer/examples/org.eclipse.net4j.jms/src/org/eclipse/net4j/internal/jms/util/DestinationUtil.java @@ -0,0 +1,145 @@ +/* + * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Eike Stepper - initial API and implementation + */ +package org.eclipse.net4j.internal.jms.util; + +import org.eclipse.net4j.internal.jms.DestinationImpl; +import org.eclipse.net4j.internal.jms.QueueImpl; +import org.eclipse.net4j.internal.jms.TopicImpl; +import org.eclipse.net4j.jms.JMSProtocolConstants; +import org.eclipse.net4j.util.io.ExtendedDataInputStream; +import org.eclipse.net4j.util.io.ExtendedDataOutputStream; + +import javax.jms.Destination; +import javax.jms.JMSException; +import javax.jms.Queue; +import javax.jms.Topic; + +import java.io.IOException; + +public final class DestinationUtil +{ + private DestinationUtil() + { + } + + public static byte getType(Destination destination) + { + if (destination instanceof Queue) + { + return JMSProtocolConstants.DESTINATION_TYPE_QUEUE; + } + + if (destination instanceof Topic) + { + return JMSProtocolConstants.DESTINATION_TYPE_TOPIC; + } + + if (destination == null) + { + return JMSProtocolConstants.DESTINATION_TYPE_NULL; + } + + throw new IllegalArgumentException("destination: " + destination); //$NON-NLS-1$ + } + + public static String getTypeName(byte type) + { + switch (type) + { + case JMSProtocolConstants.DESTINATION_TYPE_NULL: + return "NULL_DESTINATION"; //$NON-NLS-1$ + + case JMSProtocolConstants.DESTINATION_TYPE_QUEUE: + return "QUEUE_DESTINATION"; //$NON-NLS-1$ + + case JMSProtocolConstants.DESTINATION_TYPE_TOPIC: + return "TOPIC_DESTINATION"; //$NON-NLS-1$ + } + + throw new IllegalArgumentException("type: " + type); //$NON-NLS-1$ + } + + public static String getName(Destination destination) throws JMSException + { + byte type = getType(destination); + switch (type) + { + case JMSProtocolConstants.DESTINATION_TYPE_QUEUE: + return ((Queue)destination).getQueueName(); + + case JMSProtocolConstants.DESTINATION_TYPE_TOPIC: + return ((Topic)destination).getTopicName(); + } + + return null; + } + + public static DestinationImpl create(byte type, String name) + { + switch (type) + { + case JMSProtocolConstants.DESTINATION_TYPE_QUEUE: + return new QueueImpl(name); + + case JMSProtocolConstants.DESTINATION_TYPE_TOPIC: + return new TopicImpl(name); + } + + return null; + } + + public static DestinationImpl copy(Destination source) throws JMSException + { + byte type = getType(source); + switch (type) + { + case JMSProtocolConstants.DESTINATION_TYPE_QUEUE: + return new QueueImpl(((Queue)source).getQueueName()); + + case JMSProtocolConstants.DESTINATION_TYPE_TOPIC: + return new TopicImpl(((Topic)source).getTopicName()); + } + + return null; + } + + public static DestinationImpl convert(Destination source) throws JMSException + { + if (source instanceof DestinationImpl) + { + return (DestinationImpl)source; + } + + return copy(source); + } + + public static void write(ExtendedDataOutputStream out, DestinationImpl destination) throws IOException + { + byte type = getType(destination); + out.writeByte(type); + if (type != JMSProtocolConstants.DESTINATION_TYPE_NULL) + { + out.writeString(destination.getName()); + } + } + + public static DestinationImpl read(ExtendedDataInputStream in) throws IOException + { + byte type = in.readByte(); + String name = null; + if (type != JMSProtocolConstants.DESTINATION_TYPE_NULL) + { + name = in.readString(); + } + + return create(type, name); + } +} diff --git a/plugins/org.eclipse.net4j.examples.installer/examples/org.eclipse.net4j.jms/src/org/eclipse/net4j/internal/jms/util/MessageUtil.java b/plugins/org.eclipse.net4j.examples.installer/examples/org.eclipse.net4j.jms/src/org/eclipse/net4j/internal/jms/util/MessageUtil.java new file mode 100644 index 0000000000..5b2bf45e86 --- /dev/null +++ b/plugins/org.eclipse.net4j.examples.installer/examples/org.eclipse.net4j.jms/src/org/eclipse/net4j/internal/jms/util/MessageUtil.java @@ -0,0 +1,161 @@ +/* + * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Eike Stepper - initial API and implementation + */ +package org.eclipse.net4j.internal.jms.util; + +import org.eclipse.net4j.internal.jms.BytesMessageImpl; +import org.eclipse.net4j.internal.jms.MapMessageImpl; +import org.eclipse.net4j.internal.jms.MessageImpl; +import org.eclipse.net4j.internal.jms.ObjectMessageImpl; +import org.eclipse.net4j.internal.jms.StreamMessageImpl; +import org.eclipse.net4j.internal.jms.TextMessageImpl; +import org.eclipse.net4j.internal.jms.bundle.OM; +import org.eclipse.net4j.jms.JMSProtocolConstants; +import org.eclipse.net4j.util.io.ExtendedDataInputStream; +import org.eclipse.net4j.util.io.ExtendedDataOutputStream; +import org.eclipse.net4j.util.om.trace.ContextTracer; + +import javax.jms.BytesMessage; +import javax.jms.JMSException; +import javax.jms.MapMessage; +import javax.jms.Message; +import javax.jms.ObjectMessage; +import javax.jms.StreamMessage; +import javax.jms.TextMessage; + +import java.io.IOException; + +public final class MessageUtil +{ + private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG_PROTOCOL, MessageUtil.class); + + private MessageUtil() + { + } + + public static byte getType(Message message) + { + if (message instanceof BytesMessage) + { + return JMSProtocolConstants.MESSAGE_TYPE_BYTES; + } + + if (message instanceof MapMessage) + { + return JMSProtocolConstants.MESSAGE_TYPE_MAP; + } + + if (message instanceof ObjectMessage) + { + return JMSProtocolConstants.MESSAGE_TYPE_OBJECT; + } + + if (message instanceof StreamMessage) + { + return JMSProtocolConstants.MESSAGE_TYPE_STREAM; + } + + if (message instanceof TextMessage) + { + return JMSProtocolConstants.MESSAGE_TYPE_TEXT; + } + + throw new IllegalArgumentException("message: " + message); //$NON-NLS-1$ + } + + public static String getTypeName(byte type) + { + switch (type) + { + case JMSProtocolConstants.MESSAGE_TYPE_BYTES: + return "BYTES_MESSAGE"; //$NON-NLS-1$ + + case JMSProtocolConstants.MESSAGE_TYPE_MAP: + return "MAP_MESSAGE"; //$NON-NLS-1$ + + case JMSProtocolConstants.MESSAGE_TYPE_OBJECT: + return "OBJECT_MESSAGE"; //$NON-NLS-1$ + + case JMSProtocolConstants.MESSAGE_TYPE_STREAM: + return "STREAM_MESSAGE"; //$NON-NLS-1$ + + case JMSProtocolConstants.MESSAGE_TYPE_TEXT: + return "TEXT_MESSAGE"; //$NON-NLS-1$ + } + + throw new IllegalArgumentException("type: " + type); //$NON-NLS-1$ + } + + public static MessageImpl create(byte type) + { + switch (type) + { + case JMSProtocolConstants.MESSAGE_TYPE_BYTES: + return new BytesMessageImpl(); + + case JMSProtocolConstants.MESSAGE_TYPE_MAP: + return new MapMessageImpl(); + + case JMSProtocolConstants.MESSAGE_TYPE_OBJECT: + return new ObjectMessageImpl(); + + case JMSProtocolConstants.MESSAGE_TYPE_STREAM: + return new StreamMessageImpl(); + + case JMSProtocolConstants.MESSAGE_TYPE_TEXT: + return new TextMessageImpl(); + } + + throw new IllegalArgumentException("type: " + type); //$NON-NLS-1$ + } + + public static MessageImpl copy(Message source) throws JMSException + { + byte type = getType(source); + MessageImpl result = create(type); + result.populate(source); + return result; + } + + public static MessageImpl convert(Message source) throws JMSException + { + if (source instanceof MessageImpl) + { + return (MessageImpl)source; + } + + return copy(source); + } + + public static void write(ExtendedDataOutputStream out, MessageImpl message) throws IOException + { + byte type = getType(message); + if (TRACER.isEnabled()) + { + TRACER.format("Writing {0}", getTypeName(type)); //$NON-NLS-1$ + } + + out.writeByte(type); + message.write(out); + } + + public static MessageImpl read(ExtendedDataInputStream in) throws IOException + { + byte type = in.readByte(); + if (TRACER.isEnabled()) + { + TRACER.format("Reading {0}", getTypeName(type)); //$NON-NLS-1$ + } + + MessageImpl message = create(type); + message.read(in); + return message; + } +} diff --git a/plugins/org.eclipse.net4j.examples.installer/examples/org.eclipse.net4j.jms/src/org/eclipse/net4j/internal/jms/util/TypeUtil.java b/plugins/org.eclipse.net4j.examples.installer/examples/org.eclipse.net4j.jms/src/org/eclipse/net4j/internal/jms/util/TypeUtil.java new file mode 100644 index 0000000000..99d260008b --- /dev/null +++ b/plugins/org.eclipse.net4j.examples.installer/examples/org.eclipse.net4j.jms/src/org/eclipse/net4j/internal/jms/util/TypeUtil.java @@ -0,0 +1,301 @@ +/* + * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Eike Stepper - initial API and implementation + */ +package org.eclipse.net4j.internal.jms.util; + +import org.eclipse.net4j.jms.JMSProtocolConstants; +import org.eclipse.net4j.util.io.ExtendedDataInputStream; +import org.eclipse.net4j.util.io.ExtendedDataOutputStream; + +import javax.jms.MessageFormatException; + +import java.io.IOException; + +public final class TypeUtil +{ + private TypeUtil() + { + } + + public static boolean getBoolean(Object value) throws MessageFormatException + { + if (value instanceof Boolean) + { + return (Boolean)value; + } + else if (value instanceof String) + { + return Boolean.valueOf((String)value); + } + else if (value == null) + { + throw new IllegalArgumentException("value == null"); //$NON-NLS-1$ + } + + throw new MessageFormatException(conversionProblem(boolean.class, value)); + } + + public static byte getByte(Object value) throws MessageFormatException + { + if (value instanceof Byte) + { + return (Byte)value; + } + else if (value instanceof String) + { + return Byte.parseByte((String)value); + } + else if (value == null) + { + throw new IllegalArgumentException("value == null"); //$NON-NLS-1$ + } + + throw new MessageFormatException(conversionProblem(byte.class, value)); + } + + public static short getShort(Object value) throws MessageFormatException + { + if (value instanceof Short) + { + return (Short)value; + } + else if (value instanceof Byte) + { + return (Byte)value; + } + else if (value instanceof String) + { + return Short.parseShort((String)value); + } + else if (value == null) + { + throw new IllegalArgumentException("value == null"); //$NON-NLS-1$ + } + + throw new MessageFormatException(conversionProblem(short.class, value)); + } + + public static char getChar(Object value) throws MessageFormatException + { + if (value instanceof Character) + { + return (Character)value; + } + else if (value == null) + { + throw new IllegalArgumentException("value == null"); //$NON-NLS-1$ + } + + throw new MessageFormatException(conversionProblem(char.class, value)); + } + + public static int getInt(Object value) throws MessageFormatException + { + if (value instanceof Integer) + { + return (Integer)value; + } + else if (value instanceof Short) + { + return (Short)value; + } + else if (value instanceof Byte) + { + return (Byte)value; + } + else if (value instanceof String) + { + return Integer.parseInt((String)value); + } + else if (value == null) + { + throw new IllegalArgumentException("value == null"); //$NON-NLS-1$ + } + + throw new MessageFormatException(conversionProblem(int.class, value)); + } + + public static long getLong(Object value) throws MessageFormatException + { + if (value instanceof Long) + { + return (Long)value; + } + else if (value instanceof Integer) + { + return (Integer)value; + } + else if (value instanceof Short) + { + return (Short)value; + } + else if (value instanceof Byte) + { + return (Byte)value; + } + else if (value instanceof String) + { + return Long.parseLong((String)value); + } + else if (value == null) + { + throw new IllegalArgumentException("value == null"); //$NON-NLS-1$ + } + + throw new MessageFormatException(conversionProblem(long.class, value)); + } + + public static float getFloat(Object value) throws MessageFormatException + { + if (value instanceof Float) + { + return (Float)value; + } + else if (value instanceof String) + { + return Float.parseFloat((String)value); + } + else if (value == null) + { + throw new IllegalArgumentException("value == null"); //$NON-NLS-1$ + } + + throw new MessageFormatException(conversionProblem(float.class, value)); + } + + public static double getDouble(Object value) throws MessageFormatException + { + if (value instanceof Double) + { + return (Double)value; + } + else if (value instanceof Float) + { + return (Float)value; + } + else if (value instanceof String) + { + return Double.parseDouble((String)value); + } + else if (value == null) + { + throw new IllegalArgumentException("value == null"); //$NON-NLS-1$ + } + + throw new MessageFormatException(conversionProblem(double.class, value)); + } + + public static String getString(Object value) throws MessageFormatException + { + if (value instanceof byte[]) + { + throw new MessageFormatException(conversionProblem(String.class, value)); + } + else if (value == null) + { + throw new IllegalArgumentException("value == null"); //$NON-NLS-1$ + } + + return String.valueOf(value); + } + + public static byte[] getBytes(Object value) throws MessageFormatException + { + if (value instanceof byte[]) + { + byte[] bytes = (byte[])value; + byte[] result = new byte[bytes.length]; + System.arraycopy(bytes, 0, result, 0, bytes.length); + } + else if (value == null) + { + throw new IllegalArgumentException("value == null"); //$NON-NLS-1$ + } + + throw new MessageFormatException(conversionProblem(byte[].class, value)); + } + + public static void write(ExtendedDataOutputStream out, Object value) throws IOException + { + if (value instanceof Boolean) + { + out.writeByte(JMSProtocolConstants.TYPE_BOOLEAN); + out.writeBoolean((Boolean)value); + } + else if (value instanceof Byte) + { + out.writeByte(JMSProtocolConstants.TYPE_BYTE); + out.writeByte((Byte)value); + } + else if (value instanceof Character) + { + out.writeByte(JMSProtocolConstants.TYPE_CHAR); + out.writeChar((Character)value); + } + else if (value instanceof Double) + { + out.writeByte(JMSProtocolConstants.TYPE_DOUBLE); + out.writeDouble((Double)value); + } + else if (value instanceof Float) + { + out.writeByte(JMSProtocolConstants.TYPE_FLOAT); + out.writeFloat((Float)value); + } + else if (value instanceof Long) + { + out.writeByte(JMSProtocolConstants.TYPE_LONG); + out.writeLong((Long)value); + } + else if (value instanceof Short) + { + out.writeByte(JMSProtocolConstants.TYPE_SHORT); + out.writeShort((Short)value); + } + else if (value instanceof String) + { + out.writeByte(JMSProtocolConstants.TYPE_STRING); + out.writeString((String)value); + } + + throw new IllegalArgumentException("value: " + value); //$NON-NLS-1$ + } + + public static Object read(ExtendedDataInputStream in) throws IOException + { + byte type = in.readByte(); + switch (type) + { + case JMSProtocolConstants.TYPE_BOOLEAN: + return in.readBoolean(); + case JMSProtocolConstants.TYPE_BYTE: + return in.readByte(); + case JMSProtocolConstants.TYPE_CHAR: + return in.readChar(); + case JMSProtocolConstants.TYPE_DOUBLE: + return in.readDouble(); + case JMSProtocolConstants.TYPE_FLOAT: + return in.readFloat(); + case JMSProtocolConstants.TYPE_LONG: + return in.readLong(); + case JMSProtocolConstants.TYPE_SHORT: + return in.readShort(); + case JMSProtocolConstants.TYPE_STRING: + return in.readString(); + } + + throw new IOException("Invalid type: " + type); //$NON-NLS-1$ + } + + private static String conversionProblem(Class<?> type, Object value) + { + return "Cannot convert values of type " + value.getClass().getName() + " to " + type.getName(); //$NON-NLS-1$ //$NON-NLS-2$ + } +} diff --git a/plugins/org.eclipse.net4j.examples.installer/examples/org.eclipse.net4j.jms/src/org/eclipse/net4j/jms/JMSAdminProtocolConstants.java b/plugins/org.eclipse.net4j.examples.installer/examples/org.eclipse.net4j.jms/src/org/eclipse/net4j/jms/JMSAdminProtocolConstants.java new file mode 100644 index 0000000000..72d23ce783 --- /dev/null +++ b/plugins/org.eclipse.net4j.examples.installer/examples/org.eclipse.net4j.jms/src/org/eclipse/net4j/jms/JMSAdminProtocolConstants.java @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Eike Stepper - initial API and implementation + */ +package org.eclipse.net4j.jms; + +/** + * @author Eike Stepper + */ +public interface JMSAdminProtocolConstants +{ + public static final String PROTOCOL_NAME = "jmsadmin"; //$NON-NLS-1$ + + public static final short SIGNAL_CREATE_DESTINATION = 1; + + public static final byte DESTINATION_TYPE_QUEUE = JMSProtocolConstants.DESTINATION_TYPE_QUEUE; + + public static final byte DESTINATION_TYPE_TOPIC = JMSProtocolConstants.DESTINATION_TYPE_TOPIC; +} diff --git a/plugins/org.eclipse.net4j.examples.installer/examples/org.eclipse.net4j.jms/src/org/eclipse/net4j/jms/JMSInitialContext.java b/plugins/org.eclipse.net4j.examples.installer/examples/org.eclipse.net4j.jms/src/org/eclipse/net4j/jms/JMSInitialContext.java new file mode 100644 index 0000000000..a58d7e24ac --- /dev/null +++ b/plugins/org.eclipse.net4j.examples.installer/examples/org.eclipse.net4j.jms/src/org/eclipse/net4j/jms/JMSInitialContext.java @@ -0,0 +1,85 @@ +/* + * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Eike Stepper - initial API and implementation + */ +package org.eclipse.net4j.jms; + +import org.eclipse.net4j.internal.jms.ConnectionFactoryImpl; +import org.eclipse.net4j.util.container.IManagedContainer; + +import javax.naming.InitialContext; +import javax.naming.Name; +import javax.naming.NamingException; + +import java.util.Hashtable; + +/** + * @author Eike Stepper + */ +public class JMSInitialContext extends InitialContext +{ + private IManagedContainer transportContainer; + + public JMSInitialContext(IManagedContainer transportContainer) throws NamingException + { + this.transportContainer = transportContainer; + } + + public JMSInitialContext(boolean lazy, IManagedContainer transportContainer) throws NamingException + { + super(lazy); + this.transportContainer = transportContainer; + } + + public JMSInitialContext(Hashtable<?, ?> environment, IManagedContainer transportContainer) throws NamingException + { + super(environment); + this.transportContainer = transportContainer; + } + + public IManagedContainer getTransportContainer() + { + return transportContainer; + } + + @Override + public Object lookup(Name name) throws NamingException + { + return postProcess(super.lookup(name)); + } + + @Override + public Object lookup(String name) throws NamingException + { + return postProcess(super.lookup(name)); + } + + @Override + public Object lookupLink(Name name) throws NamingException + { + return postProcess(super.lookupLink(name)); + } + + @Override + public Object lookupLink(String name) throws NamingException + { + return postProcess(super.lookupLink(name)); + } + + protected Object postProcess(Object object) + { + if (object instanceof ConnectionFactoryImpl) + { + ConnectionFactoryImpl factory = (ConnectionFactoryImpl)object; + factory.setTransportContainer(transportContainer); + } + + return object; + } +} diff --git a/plugins/org.eclipse.net4j.examples.installer/examples/org.eclipse.net4j.jms/src/org/eclipse/net4j/jms/JMSProtocolConstants.java b/plugins/org.eclipse.net4j.examples.installer/examples/org.eclipse.net4j.jms/src/org/eclipse/net4j/jms/JMSProtocolConstants.java new file mode 100644 index 0000000000..34f794f5f3 --- /dev/null +++ b/plugins/org.eclipse.net4j.examples.installer/examples/org.eclipse.net4j.jms/src/org/eclipse/net4j/jms/JMSProtocolConstants.java @@ -0,0 +1,85 @@ +/* + * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Eike Stepper - initial API and implementation + */ +package org.eclipse.net4j.jms; + +/** + * @author Eike Stepper + */ +public interface JMSProtocolConstants +{ + public static final String PROTOCOL_NAME = "jms"; //$NON-NLS-1$ + + // Signals + + public static final short SIGNAL_SYNC = 1; + + public static final short SIGNAL_LOGON = 2; + + public static final short SIGNAL_LOGOFF = 3; + + public static final short SIGNAL_OPEN_SESSION = 4; + + public static final short SIGNAL_CLOSE_SESSION = 5; + + public static final short SIGNAL_REGISTER_CONSUMER = 6; + + public static final short SIGNAL_DEREGISTER_CONSUMER = 7; + + public static final short SIGNAL_CLIENT_MESSAGE = 8; + + public static final short SIGNAL_SERVER_MESSAGE = 9; + + public static final short SIGNAL_ACKNOWLEDGE = 10; + + public static final short SIGNAL_RECOVER = 11; + + public static final short SIGNAL_COMMIT = 12; + + public static final short SIGNAL_ROLLBACK = 13; + + // Message Types + + public static final byte MESSAGE_TYPE_BYTES = 1; + + public static final byte MESSAGE_TYPE_MAP = 2; + + public static final byte MESSAGE_TYPE_OBJECT = 3; + + public static final byte MESSAGE_TYPE_STREAM = 4; + + public static final byte MESSAGE_TYPE_TEXT = 5; + + // Destination Types + + public static final byte DESTINATION_TYPE_NULL = 0; + + public static final byte DESTINATION_TYPE_QUEUE = 1; + + public static final byte DESTINATION_TYPE_TOPIC = 2; + + // Data Types + + public static final byte TYPE_BOOLEAN = 1; + + public static final byte TYPE_BYTE = 2; + + public static final byte TYPE_CHAR = 3; + + public static final byte TYPE_DOUBLE = 4; + + public static final byte TYPE_FLOAT = 5; + + public static final byte TYPE_LONG = 6; + + public static final byte TYPE_SHORT = 7; + + public static final byte TYPE_STRING = 8; +} diff --git a/plugins/org.eclipse.net4j.examples.installer/examples/org.eclipse.net4j.jms/src/org/eclipse/net4j/jms/JMSUtil.java b/plugins/org.eclipse.net4j.examples.installer/examples/org.eclipse.net4j.jms/src/org/eclipse/net4j/jms/JMSUtil.java new file mode 100644 index 0000000000..0b4305c814 --- /dev/null +++ b/plugins/org.eclipse.net4j.examples.installer/examples/org.eclipse.net4j.jms/src/org/eclipse/net4j/jms/JMSUtil.java @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Eike Stepper - initial API and implementation + */ +package org.eclipse.net4j.jms; + +import org.eclipse.net4j.util.container.IManagedContainer; + +import javax.naming.Context; +import javax.naming.NamingException; + +/** + * @author Eike Stepper + */ +public final class JMSUtil +{ + private static IManagedContainer transportContainer; + + private JMSUtil() + { + } + + public static Context createInitialContext() throws NamingException + { + if (transportContainer == null) + { + throw new IllegalStateException("transportContainer == null"); //$NON-NLS-1$ + } + + return new JMSInitialContext(transportContainer); + } + + public static IManagedContainer getTransportContainer() + { + return transportContainer; + } + + public static void setTransportContainer(IManagedContainer transportContainer) + { + JMSUtil.transportContainer = transportContainer; + } +} |