You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by ph...@apache.org on 2013/06/04 14:10:16 UTC
svn commit: r1489398 [2/2] - in /qpid/jms/trunk: ./
src/main/java/org/apache/qpid/jms/ src/main/java/org/apache/qpid/jms/engine/
src/main/java/org/apache/qpid/jms/impl/
Modified: qpid/jms/trunk/src/main/java/org/apache/qpid/jms/engine/ConnectionException.java
URL: http://svn.apache.org/viewvc/qpid/jms/trunk/src/main/java/org/apache/qpid/jms/engine/ConnectionException.java?rev=1489398&r1=1489397&r2=1489398&view=diff
==============================================================================
--- qpid/jms/trunk/src/main/java/org/apache/qpid/jms/engine/ConnectionException.java (original)
+++ qpid/jms/trunk/src/main/java/org/apache/qpid/jms/engine/ConnectionException.java Tue Jun 4 12:10:15 2013
@@ -1,31 +1,31 @@
-/*
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
- */
-package org.apache.qpid.jms.engine;
-
-public class ConnectionException extends Exception
-{
- private static final long serialVersionUID = 419676688719664719L;
-
- public ConnectionException(String msg)
- {
- super(msg);
- }
-}
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.qpid.jms.engine;
+
+public class ConnectionException extends Exception
+{
+ private static final long serialVersionUID = 419676688719664719L;
+
+ public ConnectionException(String msg)
+ {
+ super(msg);
+ }
+}
Modified: qpid/jms/trunk/src/main/java/org/apache/qpid/jms/engine/SaslEngine.java
URL: http://svn.apache.org/viewvc/qpid/jms/trunk/src/main/java/org/apache/qpid/jms/engine/SaslEngine.java?rev=1489398&r1=1489397&r2=1489398&view=diff
==============================================================================
--- qpid/jms/trunk/src/main/java/org/apache/qpid/jms/engine/SaslEngine.java (original)
+++ qpid/jms/trunk/src/main/java/org/apache/qpid/jms/engine/SaslEngine.java Tue Jun 4 12:10:15 2013
@@ -1,28 +1,28 @@
-/*
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
- */
-package org.apache.qpid.jms.engine;
-
-public interface SaslEngine
-{
- String getMechanism();
-
- byte[] getResponse(byte[] challenge);
-}
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.qpid.jms.engine;
+
+public interface SaslEngine
+{
+ String getMechanism();
+
+ byte[] getResponse(byte[] challenge);
+}
Modified: qpid/jms/trunk/src/main/java/org/apache/qpid/jms/engine/SaslEngineFactory.java
URL: http://svn.apache.org/viewvc/qpid/jms/trunk/src/main/java/org/apache/qpid/jms/engine/SaslEngineFactory.java?rev=1489398&r1=1489397&r2=1489398&view=diff
==============================================================================
--- qpid/jms/trunk/src/main/java/org/apache/qpid/jms/engine/SaslEngineFactory.java (original)
+++ qpid/jms/trunk/src/main/java/org/apache/qpid/jms/engine/SaslEngineFactory.java Tue Jun 4 12:10:15 2013
@@ -1,32 +1,32 @@
-/*
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
- */
-package org.apache.qpid.jms.engine;
-
-import java.util.Map;
-
-public interface SaslEngineFactory
-{
- public static final String USERNAME_PROPERTY = "username";
- public static final String PASSWORD_PROPERTY = "password";
- public static final String PREFERRED_MECHANISMS_PROPERTY = "preferredMechanisms";
-
- SaslEngine createSaslEngine(Map<String,Object> properties, String... mechanisms);
-}
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.qpid.jms.engine;
+
+import java.util.Map;
+
+public interface SaslEngineFactory
+{
+ public static final String USERNAME_PROPERTY = "username";
+ public static final String PASSWORD_PROPERTY = "password";
+ public static final String PREFERRED_MECHANISMS_PROPERTY = "preferredMechanisms";
+
+ SaslEngine createSaslEngine(Map<String,Object> properties, String... mechanisms);
+}
Modified: qpid/jms/trunk/src/main/java/org/apache/qpid/jms/engine/SaslEngineFactoryImpl.java
URL: http://svn.apache.org/viewvc/qpid/jms/trunk/src/main/java/org/apache/qpid/jms/engine/SaslEngineFactoryImpl.java?rev=1489398&r1=1489397&r2=1489398&view=diff
==============================================================================
--- qpid/jms/trunk/src/main/java/org/apache/qpid/jms/engine/SaslEngineFactoryImpl.java (original)
+++ qpid/jms/trunk/src/main/java/org/apache/qpid/jms/engine/SaslEngineFactoryImpl.java Tue Jun 4 12:10:15 2013
@@ -1,255 +1,255 @@
-/*
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
- */
-package org.apache.qpid.jms.engine;
-
-import java.io.UnsupportedEncodingException;
-import java.security.InvalidKeyException;
-import java.security.NoSuchAlgorithmException;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.List;
-import java.util.Map;
-
-import javax.crypto.Mac;
-import javax.crypto.spec.SecretKeySpec;
-
-public class SaslEngineFactoryImpl implements SaslEngineFactory
-{
- private static final String CRAM_MD5 = "CRAM-MD5";
- private static final String PLAIN = "PLAIN";
- private static final String ANONYMOUS = "ANONYMOUS";
-
- private static final String ASCII = "ASCII";
-
- private static final byte[] EMPTY_BYTES = new byte[0];
-
- private static final Collection<String> DEFAULT_MECHS = Arrays.asList(CRAM_MD5, PLAIN, ANONYMOUS);
-
- private interface PropertyUsingSaslEngine extends SaslEngine
- {
- void setProperties(Map<String,Object> properties);
-
- boolean isValid();
- }
-
- abstract public class AbstractUsernamePasswordEngine implements PropertyUsingSaslEngine
- {
- private String _username;
- private String _password;
-
- public String getUsername()
- {
- return _username;
- }
-
- public String getPassword()
- {
- return _password;
- }
-
- @Override
- public void setProperties(Map<String, Object> properties)
- {
- Object user = properties.get(USERNAME_PROPERTY);
- if(user instanceof String)
- {
- _username = (String) user;
- }
- Object pass = properties.get(PASSWORD_PROPERTY);
- if(pass instanceof String)
- {
- _password = (String) pass;
- }
- }
-
- @Override
- public boolean isValid()
- {
- return _username != null && _password != null;
- }
- }
-
- public class CRAMMD5Engine extends AbstractUsernamePasswordEngine
- {
- private static final String HMACMD5 = "HMACMD5";
-
- private boolean _sentResponse;
-
- @Override
- public String getMechanism()
- {
- return CRAM_MD5;
- }
-
- @Override
- public byte[] getResponse(byte[] challenge)
- {
- if(!_sentResponse && challenge != null && challenge.length != 0)
- {
- try
- {
- SecretKeySpec key = new SecretKeySpec(getPassword().getBytes(ASCII), HMACMD5);
- Mac mac = Mac.getInstance(HMACMD5);
- mac.init(key);
-
- byte[] bytes = mac.doFinal(challenge);
-
- StringBuffer hash = new StringBuffer(getUsername());
- hash.append(' ');
- for (int i = 0; i < bytes.length; i++)
- {
- String hex = Integer.toHexString(0xFF & bytes[i]);
- if (hex.length() == 1)
- {
- hash.append('0');
- }
- hash.append(hex);
- }
-
- _sentResponse = true;
- return hash.toString().getBytes(ASCII);
- }
- catch (UnsupportedEncodingException e)
- {
- throw new SaslFailureException(e);
- }
- catch (InvalidKeyException e)
- {
- throw new SaslFailureException(e);
- }
- catch (NoSuchAlgorithmException e)
- {
- throw new SaslFailureException(e);
- }
- }
- else
- {
- return EMPTY_BYTES;
- }
- }
- }
-
- public class PlainEngine extends AbstractUsernamePasswordEngine
- {
- private boolean _sentInitialResponse;
-
- @Override
- public String getMechanism()
- {
- return PLAIN;
- }
-
- @Override
- public byte[] getResponse(byte[] challenge)
- {
- if(!_sentInitialResponse)
- {
- byte[] usernameBytes = getUsername().getBytes();
- byte[] passwordBytes = getPassword().getBytes();
- byte[] data = new byte[usernameBytes.length+passwordBytes.length+2];
- System.arraycopy(usernameBytes, 0, data, 1, usernameBytes.length);
- System.arraycopy(passwordBytes, 0, data, 2+usernameBytes.length, passwordBytes.length);
- _sentInitialResponse = true;
- return data;
- }
-
- return EMPTY_BYTES;
- }
- }
-
- public class AnonymousEngine implements PropertyUsingSaslEngine
- {
- @Override
- public String getMechanism()
- {
- return ANONYMOUS;
- }
-
- @Override
- public void setProperties(Map<String, Object> properties)
- {
- }
-
- @Override
- public byte[] getResponse(byte[] challenge)
- {
- return EMPTY_BYTES;
- }
-
- @Override
- public boolean isValid()
- {
- return true;
- }
- }
-
- @SuppressWarnings("unchecked")
- @Override
- public SaslEngine createSaslEngine(Map<String,Object> properties, String... mechanisms)
- {
- List<String> mechanismList = Arrays.asList(mechanisms);
-
- Collection<String> preferredMechs;
- if(properties.get(PREFERRED_MECHANISMS_PROPERTY) instanceof Collection)
- {
- preferredMechs = (Collection<String>) properties.get(PREFERRED_MECHANISMS_PROPERTY);
- }
- else
- {
- preferredMechs = DEFAULT_MECHS;
- }
-
- PropertyUsingSaslEngine engine = null;
- for(String mech : preferredMechs)
- {
- if(mechanismList.contains(mech))
- {
- if(CRAM_MD5.equals(mech))
- {
- engine = new CRAMMD5Engine();
- }
- else if(PLAIN.equals(mech))
- {
- engine = new PlainEngine();
- }
- else if(ANONYMOUS.equals(mech))
- {
- engine = new AnonymousEngine();
- }
- if(engine != null)
- {
- engine.setProperties(properties);
- if(engine.isValid())
- {
- break;
- }
- else
- {
- engine = null;
- }
- }
-
- }
- }
-
- return engine;
- }
-}
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.qpid.jms.engine;
+
+import java.io.UnsupportedEncodingException;
+import java.security.InvalidKeyException;
+import java.security.NoSuchAlgorithmException;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+
+import javax.crypto.Mac;
+import javax.crypto.spec.SecretKeySpec;
+
+public class SaslEngineFactoryImpl implements SaslEngineFactory
+{
+ private static final String CRAM_MD5 = "CRAM-MD5";
+ private static final String PLAIN = "PLAIN";
+ private static final String ANONYMOUS = "ANONYMOUS";
+
+ private static final String ASCII = "ASCII";
+
+ private static final byte[] EMPTY_BYTES = new byte[0];
+
+ private static final Collection<String> DEFAULT_MECHS = Arrays.asList(CRAM_MD5, PLAIN, ANONYMOUS);
+
+ private interface PropertyUsingSaslEngine extends SaslEngine
+ {
+ void setProperties(Map<String,Object> properties);
+
+ boolean isValid();
+ }
+
+ abstract public class AbstractUsernamePasswordEngine implements PropertyUsingSaslEngine
+ {
+ private String _username;
+ private String _password;
+
+ public String getUsername()
+ {
+ return _username;
+ }
+
+ public String getPassword()
+ {
+ return _password;
+ }
+
+ @Override
+ public void setProperties(Map<String, Object> properties)
+ {
+ Object user = properties.get(USERNAME_PROPERTY);
+ if(user instanceof String)
+ {
+ _username = (String) user;
+ }
+ Object pass = properties.get(PASSWORD_PROPERTY);
+ if(pass instanceof String)
+ {
+ _password = (String) pass;
+ }
+ }
+
+ @Override
+ public boolean isValid()
+ {
+ return _username != null && _password != null;
+ }
+ }
+
+ public class CRAMMD5Engine extends AbstractUsernamePasswordEngine
+ {
+ private static final String HMACMD5 = "HMACMD5";
+
+ private boolean _sentResponse;
+
+ @Override
+ public String getMechanism()
+ {
+ return CRAM_MD5;
+ }
+
+ @Override
+ public byte[] getResponse(byte[] challenge)
+ {
+ if(!_sentResponse && challenge != null && challenge.length != 0)
+ {
+ try
+ {
+ SecretKeySpec key = new SecretKeySpec(getPassword().getBytes(ASCII), HMACMD5);
+ Mac mac = Mac.getInstance(HMACMD5);
+ mac.init(key);
+
+ byte[] bytes = mac.doFinal(challenge);
+
+ StringBuffer hash = new StringBuffer(getUsername());
+ hash.append(' ');
+ for (int i = 0; i < bytes.length; i++)
+ {
+ String hex = Integer.toHexString(0xFF & bytes[i]);
+ if (hex.length() == 1)
+ {
+ hash.append('0');
+ }
+ hash.append(hex);
+ }
+
+ _sentResponse = true;
+ return hash.toString().getBytes(ASCII);
+ }
+ catch (UnsupportedEncodingException e)
+ {
+ throw new SaslFailureException(e);
+ }
+ catch (InvalidKeyException e)
+ {
+ throw new SaslFailureException(e);
+ }
+ catch (NoSuchAlgorithmException e)
+ {
+ throw new SaslFailureException(e);
+ }
+ }
+ else
+ {
+ return EMPTY_BYTES;
+ }
+ }
+ }
+
+ public class PlainEngine extends AbstractUsernamePasswordEngine
+ {
+ private boolean _sentInitialResponse;
+
+ @Override
+ public String getMechanism()
+ {
+ return PLAIN;
+ }
+
+ @Override
+ public byte[] getResponse(byte[] challenge)
+ {
+ if(!_sentInitialResponse)
+ {
+ byte[] usernameBytes = getUsername().getBytes();
+ byte[] passwordBytes = getPassword().getBytes();
+ byte[] data = new byte[usernameBytes.length+passwordBytes.length+2];
+ System.arraycopy(usernameBytes, 0, data, 1, usernameBytes.length);
+ System.arraycopy(passwordBytes, 0, data, 2+usernameBytes.length, passwordBytes.length);
+ _sentInitialResponse = true;
+ return data;
+ }
+
+ return EMPTY_BYTES;
+ }
+ }
+
+ public class AnonymousEngine implements PropertyUsingSaslEngine
+ {
+ @Override
+ public String getMechanism()
+ {
+ return ANONYMOUS;
+ }
+
+ @Override
+ public void setProperties(Map<String, Object> properties)
+ {
+ }
+
+ @Override
+ public byte[] getResponse(byte[] challenge)
+ {
+ return EMPTY_BYTES;
+ }
+
+ @Override
+ public boolean isValid()
+ {
+ return true;
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public SaslEngine createSaslEngine(Map<String,Object> properties, String... mechanisms)
+ {
+ List<String> mechanismList = Arrays.asList(mechanisms);
+
+ Collection<String> preferredMechs;
+ if(properties.get(PREFERRED_MECHANISMS_PROPERTY) instanceof Collection)
+ {
+ preferredMechs = (Collection<String>) properties.get(PREFERRED_MECHANISMS_PROPERTY);
+ }
+ else
+ {
+ preferredMechs = DEFAULT_MECHS;
+ }
+
+ PropertyUsingSaslEngine engine = null;
+ for(String mech : preferredMechs)
+ {
+ if(mechanismList.contains(mech))
+ {
+ if(CRAM_MD5.equals(mech))
+ {
+ engine = new CRAMMD5Engine();
+ }
+ else if(PLAIN.equals(mech))
+ {
+ engine = new PlainEngine();
+ }
+ else if(ANONYMOUS.equals(mech))
+ {
+ engine = new AnonymousEngine();
+ }
+ if(engine != null)
+ {
+ engine.setProperties(properties);
+ if(engine.isValid())
+ {
+ break;
+ }
+ else
+ {
+ engine = null;
+ }
+ }
+
+ }
+ }
+
+ return engine;
+ }
+}
Modified: qpid/jms/trunk/src/main/java/org/apache/qpid/jms/engine/SaslFailureException.java
URL: http://svn.apache.org/viewvc/qpid/jms/trunk/src/main/java/org/apache/qpid/jms/engine/SaslFailureException.java?rev=1489398&r1=1489397&r2=1489398&view=diff
==============================================================================
--- qpid/jms/trunk/src/main/java/org/apache/qpid/jms/engine/SaslFailureException.java (original)
+++ qpid/jms/trunk/src/main/java/org/apache/qpid/jms/engine/SaslFailureException.java Tue Jun 4 12:10:15 2013
@@ -1,45 +1,45 @@
-/*
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
- */
-package org.apache.qpid.jms.engine;
-
-public class SaslFailureException extends RuntimeException
-{
- private static final long serialVersionUID = 1L;
-
- public SaslFailureException()
- {
- }
-
- public SaslFailureException(String message)
- {
- super(message);
- }
-
- public SaslFailureException(Throwable cause)
- {
- super(cause == null ? null : cause.getMessage(), cause);
- }
-
- public SaslFailureException(String message, Throwable cause)
- {
- super(message, cause);
- }
-}
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.qpid.jms.engine;
+
+public class SaslFailureException extends RuntimeException
+{
+ private static final long serialVersionUID = 1L;
+
+ public SaslFailureException()
+ {
+ }
+
+ public SaslFailureException(String message)
+ {
+ super(message);
+ }
+
+ public SaslFailureException(Throwable cause)
+ {
+ super(cause == null ? null : cause.getMessage(), cause);
+ }
+
+ public SaslFailureException(String message, Throwable cause)
+ {
+ super(message, cause);
+ }
+}
Modified: qpid/jms/trunk/src/main/java/org/apache/qpid/jms/impl/ConnectionImpl.java
URL: http://svn.apache.org/viewvc/qpid/jms/trunk/src/main/java/org/apache/qpid/jms/impl/ConnectionImpl.java?rev=1489398&r1=1489397&r2=1489398&view=diff
==============================================================================
--- qpid/jms/trunk/src/main/java/org/apache/qpid/jms/impl/ConnectionImpl.java (original)
+++ qpid/jms/trunk/src/main/java/org/apache/qpid/jms/impl/ConnectionImpl.java Tue Jun 4 12:10:15 2013
@@ -1,190 +1,190 @@
-/*
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
- */
-package org.apache.qpid.jms.impl;
-
-import java.io.IOException;
-
-import org.apache.qpid.jms.engine.AmqpConnection;
-import org.apache.qpid.jms.engine.AmqpConnectionDriver;
-import org.apache.qpid.jms.engine.AmqpSession;
-import org.apache.qpid.jms.engine.ConnectionException;
-import org.apache.qpid.proton.TimeoutException;
-
-public class ConnectionImpl
-{
- private AmqpConnection _amqpConnection;
- private AmqpConnectionDriver _amqpConnectionDriver;
- private ConnectionLock _connectionLock;
-
- public ConnectionImpl(String clientName, String remoteHost, int port, String username, String password)
- {
- _amqpConnection = new AmqpConnection(clientName, remoteHost, port);
- _amqpConnection.setUsername(username);
- _amqpConnection.setPassword(password);
-
- try
- {
- _amqpConnectionDriver = new AmqpConnectionDriver();
- _amqpConnectionDriver.registerConnection(_amqpConnection);
- }
- catch (IOException e)
- {
- // TODO this will eventually be moved elsewhere
- throw new RuntimeException(e);
- }
-
- _connectionLock = new ConnectionLock(this);
- _connectionLock.setConnectionStateChangeListener(new ConnectionStateChangeListener()
- {
- public void stateChanged(ConnectionImpl connection)
- {
- connection._amqpConnectionDriver.updated(connection._amqpConnection);
- connection._amqpConnectionDriver.wakeup();
- }
- });
- }
-
- void waitUntil(Predicate condition, long timeout) throws TimeoutException, InterruptedException
- {
- long deadline = timeout < 0 ? Long.MAX_VALUE : System.currentTimeMillis() + timeout;
-
- boolean wait = deadline > System.currentTimeMillis();
- boolean first = true;
- boolean done = false;
-
- synchronized (_amqpConnection)
- {
- while (first || (!done && wait))
- {
- if (wait && !done && !first)
- {
- _amqpConnection.wait(timeout < 0 ? 0 : deadline - System.currentTimeMillis());
- }
-
- wait = deadline > System.currentTimeMillis();
- done = done || condition.test();
- first = false;
- }
- }
- if (!done)
- {
- throw new TimeoutException();
- }
- }
-
- public void connect() throws IOException, ConnectionException, TimeoutException, InterruptedException
- {
- lock();
- try
- {
- waitUntil(new Predicate()
- {
- public boolean test()
- {
- return _amqpConnection.isConnected() || _amqpConnection.isAuthenticationError() || _amqpConnection.getConnectionError().getCondition() != null;
- }
- }, AmqpConnection.TIMEOUT);
-
- if(_amqpConnection.getConnectionError().getCondition() != null)
- {
- throw new ConnectionException("Connection failed: 1 " + _amqpConnection.getConnectionError());
- }
-
- if(_amqpConnection.isAuthenticationError())
- {
- throw new ConnectionException("Connection failed: 2");
- }
-
- if(!_amqpConnection.isConnected())
- {
- throw new ConnectionException("Connection failed: 3");
- }
- }
- finally
- {
- releaseLock();
- }
- }
-
- public void close() throws TimeoutException, InterruptedException, ConnectionException
- {
- lock();
- try
- {
- _amqpConnection.close();
- stateChanged();
- while(!_amqpConnection.isClosed())
- {
- waitUntil(new Predicate()
- {
- public boolean test()
- {
- return _amqpConnection.isClosed();
- }
- }, AmqpConnection.TIMEOUT);
- }
-
- if(_amqpConnection.getConnectionError().getCondition() != null)
- {
- throw new ConnectionException("Connection close failed: " + _amqpConnection.getConnectionError());
- }
- }
- finally
- {
- releaseLock();
- }
- }
-
- public SessionImpl createSession() throws TimeoutException, InterruptedException
- {
- lock();
- try
- {
- AmqpSession amqpSession = _amqpConnection.createSession();
-
- SessionImpl session = new SessionImpl(amqpSession, this);
- stateChanged();
- session.establish();
-
- return session;
- }
- finally
- {
- releaseLock();
- }
- }
-
- void lock()
- {
- _connectionLock.lock();
- }
-
- void releaseLock()
- {
- _connectionLock.unlock();
- }
-
- void stateChanged()
- {
- _connectionLock.stateChanged();
- }
-
-}
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.qpid.jms.impl;
+
+import java.io.IOException;
+
+import org.apache.qpid.jms.engine.AmqpConnection;
+import org.apache.qpid.jms.engine.AmqpConnectionDriver;
+import org.apache.qpid.jms.engine.AmqpSession;
+import org.apache.qpid.jms.engine.ConnectionException;
+import org.apache.qpid.proton.TimeoutException;
+
+public class ConnectionImpl
+{
+ private AmqpConnection _amqpConnection;
+ private AmqpConnectionDriver _amqpConnectionDriver;
+ private ConnectionLock _connectionLock;
+
+ public ConnectionImpl(String clientName, String remoteHost, int port, String username, String password)
+ {
+ _amqpConnection = new AmqpConnection(clientName, remoteHost, port);
+ _amqpConnection.setUsername(username);
+ _amqpConnection.setPassword(password);
+
+ try
+ {
+ _amqpConnectionDriver = new AmqpConnectionDriver();
+ _amqpConnectionDriver.registerConnection(_amqpConnection);
+ }
+ catch (IOException e)
+ {
+ // TODO this will eventually be moved elsewhere
+ throw new RuntimeException(e);
+ }
+
+ _connectionLock = new ConnectionLock(this);
+ _connectionLock.setConnectionStateChangeListener(new ConnectionStateChangeListener()
+ {
+ public void stateChanged(ConnectionImpl connection)
+ {
+ connection._amqpConnectionDriver.updated(connection._amqpConnection);
+ connection._amqpConnectionDriver.wakeup();
+ }
+ });
+ }
+
+ void waitUntil(Predicate condition, long timeout) throws TimeoutException, InterruptedException
+ {
+ long deadline = timeout < 0 ? Long.MAX_VALUE : System.currentTimeMillis() + timeout;
+
+ boolean wait = deadline > System.currentTimeMillis();
+ boolean first = true;
+ boolean done = false;
+
+ synchronized (_amqpConnection)
+ {
+ while (first || (!done && wait))
+ {
+ if (wait && !done && !first)
+ {
+ _amqpConnection.wait(timeout < 0 ? 0 : deadline - System.currentTimeMillis());
+ }
+
+ wait = deadline > System.currentTimeMillis();
+ done = done || condition.test();
+ first = false;
+ }
+ }
+ if (!done)
+ {
+ throw new TimeoutException();
+ }
+ }
+
+ public void connect() throws IOException, ConnectionException, TimeoutException, InterruptedException
+ {
+ lock();
+ try
+ {
+ waitUntil(new Predicate()
+ {
+ public boolean test()
+ {
+ return _amqpConnection.isConnected() || _amqpConnection.isAuthenticationError() || _amqpConnection.getConnectionError().getCondition() != null;
+ }
+ }, AmqpConnection.TIMEOUT);
+
+ if(_amqpConnection.getConnectionError().getCondition() != null)
+ {
+ throw new ConnectionException("Connection failed: 1 " + _amqpConnection.getConnectionError());
+ }
+
+ if(_amqpConnection.isAuthenticationError())
+ {
+ throw new ConnectionException("Connection failed: 2");
+ }
+
+ if(!_amqpConnection.isConnected())
+ {
+ throw new ConnectionException("Connection failed: 3");
+ }
+ }
+ finally
+ {
+ releaseLock();
+ }
+ }
+
+ public void close() throws TimeoutException, InterruptedException, ConnectionException
+ {
+ lock();
+ try
+ {
+ _amqpConnection.close();
+ stateChanged();
+ while(!_amqpConnection.isClosed())
+ {
+ waitUntil(new Predicate()
+ {
+ public boolean test()
+ {
+ return _amqpConnection.isClosed();
+ }
+ }, AmqpConnection.TIMEOUT);
+ }
+
+ if(_amqpConnection.getConnectionError().getCondition() != null)
+ {
+ throw new ConnectionException("Connection close failed: " + _amqpConnection.getConnectionError());
+ }
+ }
+ finally
+ {
+ releaseLock();
+ }
+ }
+
+ public SessionImpl createSession() throws TimeoutException, InterruptedException
+ {
+ lock();
+ try
+ {
+ AmqpSession amqpSession = _amqpConnection.createSession();
+
+ SessionImpl session = new SessionImpl(amqpSession, this);
+ stateChanged();
+ session.establish();
+
+ return session;
+ }
+ finally
+ {
+ releaseLock();
+ }
+ }
+
+ void lock()
+ {
+ _connectionLock.lock();
+ }
+
+ void releaseLock()
+ {
+ _connectionLock.unlock();
+ }
+
+ void stateChanged()
+ {
+ _connectionLock.stateChanged();
+ }
+
+}
Modified: qpid/jms/trunk/src/main/java/org/apache/qpid/jms/impl/ConnectionLock.java
URL: http://svn.apache.org/viewvc/qpid/jms/trunk/src/main/java/org/apache/qpid/jms/impl/ConnectionLock.java?rev=1489398&r1=1489397&r2=1489398&view=diff
==============================================================================
--- qpid/jms/trunk/src/main/java/org/apache/qpid/jms/impl/ConnectionLock.java (original)
+++ qpid/jms/trunk/src/main/java/org/apache/qpid/jms/impl/ConnectionLock.java Tue Jun 4 12:10:15 2013
@@ -1,49 +1,49 @@
-/*
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
- */
-package org.apache.qpid.jms.impl;
-
-import java.util.concurrent.locks.ReentrantLock;
-
-public class ConnectionLock extends ReentrantLock
-{
- private static final long serialVersionUID = 1006213282468441380L;
-
- private ConnectionStateChangeListener _listener;
- private ConnectionImpl _connection;
-
- public ConnectionLock(ConnectionImpl connection)
- {
- _connection = connection;
- }
-
- public void setConnectionStateChangeListener(ConnectionStateChangeListener listener)
- {
- _listener = listener;
- }
-
- public void stateChanged()
- {
- if(_listener != null)
- {
- _listener.stateChanged(_connection);
- }
- }
-}
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.qpid.jms.impl;
+
+import java.util.concurrent.locks.ReentrantLock;
+
+public class ConnectionLock extends ReentrantLock
+{
+ private static final long serialVersionUID = 1006213282468441380L;
+
+ private ConnectionStateChangeListener _listener;
+ private ConnectionImpl _connection;
+
+ public ConnectionLock(ConnectionImpl connection)
+ {
+ _connection = connection;
+ }
+
+ public void setConnectionStateChangeListener(ConnectionStateChangeListener listener)
+ {
+ _listener = listener;
+ }
+
+ public void stateChanged()
+ {
+ if(_listener != null)
+ {
+ _listener.stateChanged(_connection);
+ }
+ }
+}
Modified: qpid/jms/trunk/src/main/java/org/apache/qpid/jms/impl/ConnectionStateChangeListener.java
URL: http://svn.apache.org/viewvc/qpid/jms/trunk/src/main/java/org/apache/qpid/jms/impl/ConnectionStateChangeListener.java?rev=1489398&r1=1489397&r2=1489398&view=diff
==============================================================================
--- qpid/jms/trunk/src/main/java/org/apache/qpid/jms/impl/ConnectionStateChangeListener.java (original)
+++ qpid/jms/trunk/src/main/java/org/apache/qpid/jms/impl/ConnectionStateChangeListener.java Tue Jun 4 12:10:15 2013
@@ -1,26 +1,26 @@
-/*
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
- */
-package org.apache.qpid.jms.impl;
-
-public interface ConnectionStateChangeListener
-{
- void stateChanged(ConnectionImpl connection);
-}
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.qpid.jms.impl;
+
+public interface ConnectionStateChangeListener
+{
+ void stateChanged(ConnectionImpl connection);
+}
Modified: qpid/jms/trunk/src/main/java/org/apache/qpid/jms/impl/LinkImpl.java
URL: http://svn.apache.org/viewvc/qpid/jms/trunk/src/main/java/org/apache/qpid/jms/impl/LinkImpl.java?rev=1489398&r1=1489397&r2=1489398&view=diff
==============================================================================
--- qpid/jms/trunk/src/main/java/org/apache/qpid/jms/impl/LinkImpl.java (original)
+++ qpid/jms/trunk/src/main/java/org/apache/qpid/jms/impl/LinkImpl.java Tue Jun 4 12:10:15 2013
@@ -1,87 +1,87 @@
-/*
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
- */
-package org.apache.qpid.jms.impl;
-
-import org.apache.qpid.jms.engine.AmqpConnection;
-import org.apache.qpid.jms.engine.AmqpLink;
-import org.apache.qpid.jms.engine.ConnectionException;
-import org.apache.qpid.proton.TimeoutException;
-
-public class LinkImpl
-{
- private SessionImpl _sessionImpl;
- private ConnectionImpl _connectionImpl;
- private AmqpLink _amqpLink;
-
- public LinkImpl(SessionImpl sessionImpl, AmqpLink amqpLink)
- {
- _sessionImpl = sessionImpl;
- _connectionImpl = _sessionImpl.getConnectionImpl();
- _amqpLink = amqpLink;
- }
-
- public void establish() throws TimeoutException, InterruptedException
- {
- _connectionImpl.waitUntil(new Predicate()
- {
- public boolean test()
- {
- return _amqpLink.isEstablished();
- }
- }, AmqpConnection.TIMEOUT);
- }
-
- public void close() throws TimeoutException, InterruptedException, ConnectionException
- {
- _connectionImpl.lock();
- try
- {
- _amqpLink.close();
- _connectionImpl.stateChanged();
- while(!_amqpLink.isClosed())
- {
- _connectionImpl.waitUntil(new Predicate()
- {
- public boolean test()
- {
- return _amqpLink.isClosed();
- }
- }, AmqpConnection.TIMEOUT);
- }
-
- //TODO: link errors? E.g:
- // if(_amqpSender.getLinkError().getCondition() != null)
- // {
- // throw new ConnectionException("Sender close failed: " + _amqpSender.getLinkError());
- // }
- }
- finally
- {
- _connectionImpl.releaseLock();
- }
- }
-
- ConnectionImpl getConnectionImpl()
- {
- return _connectionImpl;
- }
-
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.qpid.jms.impl;
+
+import org.apache.qpid.jms.engine.AmqpConnection;
+import org.apache.qpid.jms.engine.AmqpLink;
+import org.apache.qpid.jms.engine.ConnectionException;
+import org.apache.qpid.proton.TimeoutException;
+
+public class LinkImpl
+{
+ private SessionImpl _sessionImpl;
+ private ConnectionImpl _connectionImpl;
+ private AmqpLink _amqpLink;
+
+ public LinkImpl(SessionImpl sessionImpl, AmqpLink amqpLink)
+ {
+ _sessionImpl = sessionImpl;
+ _connectionImpl = _sessionImpl.getConnectionImpl();
+ _amqpLink = amqpLink;
+ }
+
+ public void establish() throws TimeoutException, InterruptedException
+ {
+ _connectionImpl.waitUntil(new Predicate()
+ {
+ public boolean test()
+ {
+ return _amqpLink.isEstablished();
+ }
+ }, AmqpConnection.TIMEOUT);
+ }
+
+ public void close() throws TimeoutException, InterruptedException, ConnectionException
+ {
+ _connectionImpl.lock();
+ try
+ {
+ _amqpLink.close();
+ _connectionImpl.stateChanged();
+ while(!_amqpLink.isClosed())
+ {
+ _connectionImpl.waitUntil(new Predicate()
+ {
+ public boolean test()
+ {
+ return _amqpLink.isClosed();
+ }
+ }, AmqpConnection.TIMEOUT);
+ }
+
+ //TODO: link errors? E.g:
+ // if(_amqpSender.getLinkError().getCondition() != null)
+ // {
+ // throw new ConnectionException("Sender close failed: " + _amqpSender.getLinkError());
+ // }
+ }
+ finally
+ {
+ _connectionImpl.releaseLock();
+ }
+ }
+
+ ConnectionImpl getConnectionImpl()
+ {
+ return _connectionImpl;
+ }
+
}
\ No newline at end of file
Modified: qpid/jms/trunk/src/main/java/org/apache/qpid/jms/impl/Predicate.java
URL: http://svn.apache.org/viewvc/qpid/jms/trunk/src/main/java/org/apache/qpid/jms/impl/Predicate.java?rev=1489398&r1=1489397&r2=1489398&view=diff
==============================================================================
--- qpid/jms/trunk/src/main/java/org/apache/qpid/jms/impl/Predicate.java (original)
+++ qpid/jms/trunk/src/main/java/org/apache/qpid/jms/impl/Predicate.java Tue Jun 4 12:10:15 2013
@@ -1,26 +1,26 @@
-/*
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
- */
-package org.apache.qpid.jms.impl;
-
-interface Predicate
-{
- boolean test();
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.qpid.jms.impl;
+
+interface Predicate
+{
+ boolean test();
}
\ No newline at end of file
Modified: qpid/jms/trunk/src/main/java/org/apache/qpid/jms/impl/ReceivedMessageImpl.java
URL: http://svn.apache.org/viewvc/qpid/jms/trunk/src/main/java/org/apache/qpid/jms/impl/ReceivedMessageImpl.java?rev=1489398&r1=1489397&r2=1489398&view=diff
==============================================================================
--- qpid/jms/trunk/src/main/java/org/apache/qpid/jms/impl/ReceivedMessageImpl.java (original)
+++ qpid/jms/trunk/src/main/java/org/apache/qpid/jms/impl/ReceivedMessageImpl.java Tue Jun 4 12:10:15 2013
@@ -1,95 +1,95 @@
-/*
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
- */
-package org.apache.qpid.jms.impl;
-
-import org.apache.qpid.jms.engine.AmqpConnection;
-import org.apache.qpid.jms.engine.AmqpReceivedMessage;
-import org.apache.qpid.proton.TimeoutException;
-import org.apache.qpid.proton.message.Message;
-
-public class ReceivedMessageImpl
-{
- private AmqpReceivedMessage _amqpMessage;
- private ReceiverImpl _receiverImpl;
-
- public ReceivedMessageImpl(AmqpReceivedMessage amqpMessage, ReceiverImpl receiverImpl)
- {
- _amqpMessage = amqpMessage;
- _receiverImpl = receiverImpl;
- }
-
- public void accept(boolean settle)
- {
- _receiverImpl.getConnectionImpl().lock();
- try
- {
- _amqpMessage.accept();
- if(settle)
- {
- _amqpMessage.settle();
- }
- _receiverImpl.getConnectionImpl().stateChanged();
- }
- finally
- {
- _receiverImpl.getConnectionImpl().releaseLock();
- }
- }
-
- public void settle()
- {
- _receiverImpl.getConnectionImpl().lock();
- try
- {
- _amqpMessage.settle();
- _receiverImpl.getConnectionImpl().stateChanged();
- }
- finally
- {
- _receiverImpl.getConnectionImpl().releaseLock();
- }
- }
-
- public void waitUntilSettled() throws TimeoutException, InterruptedException
- {
- _receiverImpl.getConnectionImpl().lock();
- try
- {
- _receiverImpl.getConnectionImpl().waitUntil(new Predicate()
- {
- @Override
- public boolean test()
- {
- return _amqpMessage.isSettled();
- }
- }, AmqpConnection.TIMEOUT);
- }
- finally
- {
- _receiverImpl.getConnectionImpl().releaseLock();
- }
- }
-
- public Message getMessage()
- {
- return _amqpMessage.getMessage();
- }
-}
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.qpid.jms.impl;
+
+import org.apache.qpid.jms.engine.AmqpConnection;
+import org.apache.qpid.jms.engine.AmqpReceivedMessage;
+import org.apache.qpid.proton.TimeoutException;
+import org.apache.qpid.proton.message.Message;
+
+public class ReceivedMessageImpl
+{
+ private AmqpReceivedMessage _amqpMessage;
+ private ReceiverImpl _receiverImpl;
+
+ public ReceivedMessageImpl(AmqpReceivedMessage amqpMessage, ReceiverImpl receiverImpl)
+ {
+ _amqpMessage = amqpMessage;
+ _receiverImpl = receiverImpl;
+ }
+
+ public void accept(boolean settle)
+ {
+ _receiverImpl.getConnectionImpl().lock();
+ try
+ {
+ _amqpMessage.accept();
+ if(settle)
+ {
+ _amqpMessage.settle();
+ }
+ _receiverImpl.getConnectionImpl().stateChanged();
+ }
+ finally
+ {
+ _receiverImpl.getConnectionImpl().releaseLock();
+ }
+ }
+
+ public void settle()
+ {
+ _receiverImpl.getConnectionImpl().lock();
+ try
+ {
+ _amqpMessage.settle();
+ _receiverImpl.getConnectionImpl().stateChanged();
+ }
+ finally
+ {
+ _receiverImpl.getConnectionImpl().releaseLock();
+ }
+ }
+
+ public void waitUntilSettled() throws TimeoutException, InterruptedException
+ {
+ _receiverImpl.getConnectionImpl().lock();
+ try
+ {
+ _receiverImpl.getConnectionImpl().waitUntil(new Predicate()
+ {
+ @Override
+ public boolean test()
+ {
+ return _amqpMessage.isSettled();
+ }
+ }, AmqpConnection.TIMEOUT);
+ }
+ finally
+ {
+ _receiverImpl.getConnectionImpl().releaseLock();
+ }
+ }
+
+ public Message getMessage()
+ {
+ return _amqpMessage.getMessage();
+ }
+}
Modified: qpid/jms/trunk/src/main/java/org/apache/qpid/jms/impl/ReceiverImpl.java
URL: http://svn.apache.org/viewvc/qpid/jms/trunk/src/main/java/org/apache/qpid/jms/impl/ReceiverImpl.java?rev=1489398&r1=1489397&r2=1489398&view=diff
==============================================================================
--- qpid/jms/trunk/src/main/java/org/apache/qpid/jms/impl/ReceiverImpl.java (original)
+++ qpid/jms/trunk/src/main/java/org/apache/qpid/jms/impl/ReceiverImpl.java Tue Jun 4 12:10:15 2013
@@ -1,88 +1,88 @@
-/*
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
- */
-package org.apache.qpid.jms.impl;
-
-import org.apache.qpid.jms.engine.AmqpReceivedMessage;
-import org.apache.qpid.jms.engine.AmqpReceiver;
-import org.apache.qpid.proton.TimeoutException;
-
-public class ReceiverImpl extends LinkImpl
-{
- private final AmqpReceiver _amqpReceiver;
-
- public ReceiverImpl(SessionImpl sessionImpl, AmqpReceiver amqpReceiver)
- {
- super(sessionImpl, amqpReceiver);
- _amqpReceiver = amqpReceiver;
- }
-
- public ReceivedMessageImpl receive(long timeout) throws TimeoutException, InterruptedException
- {
- getConnectionImpl().lock();
- try
- {
- MessageReceivedPredicate messageReceievedCondition = new MessageReceivedPredicate();
- getConnectionImpl().waitUntil(messageReceievedCondition, timeout);
- getConnectionImpl().stateChanged();
-
- return new ReceivedMessageImpl(messageReceievedCondition.getReceivedMessage(), this);
- }
- finally
- {
- getConnectionImpl().releaseLock();
- }
- }
-
- public void credit(int credit)
- {
- getConnectionImpl().lock();
- try
- {
- _amqpReceiver.credit(credit);
- getConnectionImpl().stateChanged();
- }
- finally
- {
- getConnectionImpl().releaseLock();
- }
- }
-
- private final class MessageReceivedPredicate implements Predicate
- {
- AmqpReceivedMessage _message;
-
- @Override
- public boolean test()
- {
- if(_message == null)
- {
- _message = _amqpReceiver.receiveNoWait();
- }
- return _message != null;
- }
-
- public AmqpReceivedMessage getReceivedMessage()
- {
- return _message;
- }
- }
-
-}
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.qpid.jms.impl;
+
+import org.apache.qpid.jms.engine.AmqpReceivedMessage;
+import org.apache.qpid.jms.engine.AmqpReceiver;
+import org.apache.qpid.proton.TimeoutException;
+
+public class ReceiverImpl extends LinkImpl
+{
+ private final AmqpReceiver _amqpReceiver;
+
+ public ReceiverImpl(SessionImpl sessionImpl, AmqpReceiver amqpReceiver)
+ {
+ super(sessionImpl, amqpReceiver);
+ _amqpReceiver = amqpReceiver;
+ }
+
+ public ReceivedMessageImpl receive(long timeout) throws TimeoutException, InterruptedException
+ {
+ getConnectionImpl().lock();
+ try
+ {
+ MessageReceivedPredicate messageReceievedCondition = new MessageReceivedPredicate();
+ getConnectionImpl().waitUntil(messageReceievedCondition, timeout);
+ getConnectionImpl().stateChanged();
+
+ return new ReceivedMessageImpl(messageReceievedCondition.getReceivedMessage(), this);
+ }
+ finally
+ {
+ getConnectionImpl().releaseLock();
+ }
+ }
+
+ public void credit(int credit)
+ {
+ getConnectionImpl().lock();
+ try
+ {
+ _amqpReceiver.credit(credit);
+ getConnectionImpl().stateChanged();
+ }
+ finally
+ {
+ getConnectionImpl().releaseLock();
+ }
+ }
+
+ private final class MessageReceivedPredicate implements Predicate
+ {
+ AmqpReceivedMessage _message;
+
+ @Override
+ public boolean test()
+ {
+ if(_message == null)
+ {
+ _message = _amqpReceiver.receiveNoWait();
+ }
+ return _message != null;
+ }
+
+ public AmqpReceivedMessage getReceivedMessage()
+ {
+ return _message;
+ }
+ }
+
+}
Modified: qpid/jms/trunk/src/main/java/org/apache/qpid/jms/impl/SenderImpl.java
URL: http://svn.apache.org/viewvc/qpid/jms/trunk/src/main/java/org/apache/qpid/jms/impl/SenderImpl.java?rev=1489398&r1=1489397&r2=1489398&view=diff
==============================================================================
--- qpid/jms/trunk/src/main/java/org/apache/qpid/jms/impl/SenderImpl.java (original)
+++ qpid/jms/trunk/src/main/java/org/apache/qpid/jms/impl/SenderImpl.java Tue Jun 4 12:10:15 2013
@@ -1,57 +1,57 @@
-/*
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
- */
-package org.apache.qpid.jms.impl;
-
-import org.apache.qpid.jms.engine.AmqpSender;
-import org.apache.qpid.jms.engine.AmqpSentMessage;
-import org.apache.qpid.proton.TimeoutException;
-import org.apache.qpid.proton.message.Message;
-
-public class SenderImpl extends LinkImpl
-{
- private AmqpSender _amqpSender;
-
- public SenderImpl(SessionImpl sessionImpl, AmqpSender amqpSender)
- {
- super(sessionImpl, amqpSender);
- _amqpSender = amqpSender;
- }
-
- public void sendMessage(Message message) throws TimeoutException, InterruptedException
- {
- getConnectionImpl().lock();
- try
- {
- AmqpSentMessage sentMessage = _amqpSender.sendMessage(message);
-
- getConnectionImpl().stateChanged();
-
- SentMessageImpl sentMessageImpl = new SentMessageImpl(sentMessage, this);
- sentMessageImpl.waitUntilAccepted();
- sentMessage.settle();
- }
- finally
- {
- getConnectionImpl().releaseLock();
- }
-
- }
-}
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.qpid.jms.impl;
+
+import org.apache.qpid.jms.engine.AmqpSender;
+import org.apache.qpid.jms.engine.AmqpSentMessage;
+import org.apache.qpid.proton.TimeoutException;
+import org.apache.qpid.proton.message.Message;
+
+public class SenderImpl extends LinkImpl
+{
+ private AmqpSender _amqpSender;
+
+ public SenderImpl(SessionImpl sessionImpl, AmqpSender amqpSender)
+ {
+ super(sessionImpl, amqpSender);
+ _amqpSender = amqpSender;
+ }
+
+ public void sendMessage(Message message) throws TimeoutException, InterruptedException
+ {
+ getConnectionImpl().lock();
+ try
+ {
+ AmqpSentMessage sentMessage = _amqpSender.sendMessage(message);
+
+ getConnectionImpl().stateChanged();
+
+ SentMessageImpl sentMessageImpl = new SentMessageImpl(sentMessage, this);
+ sentMessageImpl.waitUntilAccepted();
+ sentMessage.settle();
+ }
+ finally
+ {
+ getConnectionImpl().releaseLock();
+ }
+
+ }
+}
Modified: qpid/jms/trunk/src/main/java/org/apache/qpid/jms/impl/SentMessageImpl.java
URL: http://svn.apache.org/viewvc/qpid/jms/trunk/src/main/java/org/apache/qpid/jms/impl/SentMessageImpl.java?rev=1489398&r1=1489397&r2=1489398&view=diff
==============================================================================
--- qpid/jms/trunk/src/main/java/org/apache/qpid/jms/impl/SentMessageImpl.java (original)
+++ qpid/jms/trunk/src/main/java/org/apache/qpid/jms/impl/SentMessageImpl.java Tue Jun 4 12:10:15 2013
@@ -1,50 +1,50 @@
-/*
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
- */
-package org.apache.qpid.jms.impl;
-
-import org.apache.qpid.jms.engine.AmqpConnection;
-import org.apache.qpid.jms.engine.AmqpSentMessage;
-import org.apache.qpid.proton.TimeoutException;
-
-public class SentMessageImpl
-{
- private AmqpSentMessage _sentMessage;
- private SenderImpl _sender;
-
- public SentMessageImpl(AmqpSentMessage sentMessage, SenderImpl sender)
- {
- _sentMessage = sentMessage;
- _sender = sender;
- }
-
- public void waitUntilAccepted() throws TimeoutException, InterruptedException
- {
- _sender.getConnectionImpl().waitUntil(new Predicate()
- {
- @Override
- public boolean test()
- {
- return _sentMessage.getRemoteDeliveryState() != null;
- }
- }, AmqpConnection.TIMEOUT);
- }
-
-}
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.qpid.jms.impl;
+
+import org.apache.qpid.jms.engine.AmqpConnection;
+import org.apache.qpid.jms.engine.AmqpSentMessage;
+import org.apache.qpid.proton.TimeoutException;
+
+public class SentMessageImpl
+{
+ private AmqpSentMessage _sentMessage;
+ private SenderImpl _sender;
+
+ public SentMessageImpl(AmqpSentMessage sentMessage, SenderImpl sender)
+ {
+ _sentMessage = sentMessage;
+ _sender = sender;
+ }
+
+ public void waitUntilAccepted() throws TimeoutException, InterruptedException
+ {
+ _sender.getConnectionImpl().waitUntil(new Predicate()
+ {
+ @Override
+ public boolean test()
+ {
+ return _sentMessage.getRemoteDeliveryState() != null;
+ }
+ }, AmqpConnection.TIMEOUT);
+ }
+
+}
Modified: qpid/jms/trunk/src/main/java/org/apache/qpid/jms/impl/SessionImpl.java
URL: http://svn.apache.org/viewvc/qpid/jms/trunk/src/main/java/org/apache/qpid/jms/impl/SessionImpl.java?rev=1489398&r1=1489397&r2=1489398&view=diff
==============================================================================
--- qpid/jms/trunk/src/main/java/org/apache/qpid/jms/impl/SessionImpl.java (original)
+++ qpid/jms/trunk/src/main/java/org/apache/qpid/jms/impl/SessionImpl.java Tue Jun 4 12:10:15 2013
@@ -1,119 +1,119 @@
-/*
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
- */
-package org.apache.qpid.jms.impl;
-
-import org.apache.qpid.jms.engine.AmqpConnection;
-import org.apache.qpid.jms.engine.AmqpReceiver;
-import org.apache.qpid.jms.engine.AmqpSender;
-import org.apache.qpid.jms.engine.AmqpSession;
-import org.apache.qpid.jms.engine.ConnectionException;
-import org.apache.qpid.proton.TimeoutException;
-
-public class SessionImpl
-{
- private AmqpSession _amqpSession;
- private ConnectionImpl _connectionImpl;
-
- public SessionImpl(AmqpSession amqpSession, ConnectionImpl connectionImpl)
- {
- _amqpSession = amqpSession;
- _connectionImpl = connectionImpl;
- }
-
- public void establish() throws TimeoutException, InterruptedException
- {
- _connectionImpl.waitUntil(new Predicate()
- {
- public boolean test()
- {
- return _amqpSession.isEstablished();
- }
- }, AmqpConnection.TIMEOUT);
- }
-
- public void close() throws TimeoutException, InterruptedException, ConnectionException
- {
- _connectionImpl.lock();
- try
- {
- _amqpSession.close();
- _connectionImpl.stateChanged();
- while(!_amqpSession.isClosed())
- {
- _connectionImpl.waitUntil(new Predicate()
- {
- public boolean test()
- {
- return _amqpSession.isClosed();
- }
- }, AmqpConnection.TIMEOUT);
- }
-
- if(_amqpSession.getSessionError().getCondition() != null)
- {
- throw new ConnectionException("Session close failed: " + _amqpSession.getSessionError());
- }
- }
- finally
- {
- _connectionImpl.releaseLock();
- }
- }
-
- ConnectionImpl getConnectionImpl()
- {
- return _connectionImpl;
- }
-
- public SenderImpl createSender(String name, String address) throws TimeoutException, InterruptedException
- {
- _connectionImpl.lock();
- try
- {
- AmqpSender amqpSender = _amqpSession.createAmqpSender(name, address);
- SenderImpl sender = new SenderImpl(this, amqpSender);
- _connectionImpl.stateChanged();
- sender.establish();
- return sender;
- }
- finally
- {
- _connectionImpl.releaseLock();
- }
- }
-
- public ReceiverImpl createReceiver(String name, String address) throws TimeoutException, InterruptedException
- {
- _connectionImpl.lock();
- try
- {
- AmqpReceiver amqpReceiver = _amqpSession.createAmqpReceiver(name, address);
- ReceiverImpl receiver = new ReceiverImpl(this, amqpReceiver);
- _connectionImpl.stateChanged();
- receiver.establish();
- return receiver;
- }
- finally
- {
- _connectionImpl.releaseLock();
- }
- }
-}
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.qpid.jms.impl;
+
+import org.apache.qpid.jms.engine.AmqpConnection;
+import org.apache.qpid.jms.engine.AmqpReceiver;
+import org.apache.qpid.jms.engine.AmqpSender;
+import org.apache.qpid.jms.engine.AmqpSession;
+import org.apache.qpid.jms.engine.ConnectionException;
+import org.apache.qpid.proton.TimeoutException;
+
+public class SessionImpl
+{
+ private AmqpSession _amqpSession;
+ private ConnectionImpl _connectionImpl;
+
+ public SessionImpl(AmqpSession amqpSession, ConnectionImpl connectionImpl)
+ {
+ _amqpSession = amqpSession;
+ _connectionImpl = connectionImpl;
+ }
+
+ public void establish() throws TimeoutException, InterruptedException
+ {
+ _connectionImpl.waitUntil(new Predicate()
+ {
+ public boolean test()
+ {
+ return _amqpSession.isEstablished();
+ }
+ }, AmqpConnection.TIMEOUT);
+ }
+
+ public void close() throws TimeoutException, InterruptedException, ConnectionException
+ {
+ _connectionImpl.lock();
+ try
+ {
+ _amqpSession.close();
+ _connectionImpl.stateChanged();
+ while(!_amqpSession.isClosed())
+ {
+ _connectionImpl.waitUntil(new Predicate()
+ {
+ public boolean test()
+ {
+ return _amqpSession.isClosed();
+ }
+ }, AmqpConnection.TIMEOUT);
+ }
+
+ if(_amqpSession.getSessionError().getCondition() != null)
+ {
+ throw new ConnectionException("Session close failed: " + _amqpSession.getSessionError());
+ }
+ }
+ finally
+ {
+ _connectionImpl.releaseLock();
+ }
+ }
+
+ ConnectionImpl getConnectionImpl()
+ {
+ return _connectionImpl;
+ }
+
+ public SenderImpl createSender(String name, String address) throws TimeoutException, InterruptedException
+ {
+ _connectionImpl.lock();
+ try
+ {
+ AmqpSender amqpSender = _amqpSession.createAmqpSender(name, address);
+ SenderImpl sender = new SenderImpl(this, amqpSender);
+ _connectionImpl.stateChanged();
+ sender.establish();
+ return sender;
+ }
+ finally
+ {
+ _connectionImpl.releaseLock();
+ }
+ }
+
+ public ReceiverImpl createReceiver(String name, String address) throws TimeoutException, InterruptedException
+ {
+ _connectionImpl.lock();
+ try
+ {
+ AmqpReceiver amqpReceiver = _amqpSession.createAmqpReceiver(name, address);
+ ReceiverImpl receiver = new ReceiverImpl(this, amqpReceiver);
+ _connectionImpl.stateChanged();
+ receiver.establish();
+ return receiver;
+ }
+ finally
+ {
+ _connectionImpl.releaseLock();
+ }
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org