[hornetq-commits] JBoss hornetq SVN: r8966 - in branches/Clebert_TMP/src/main/org/hornetq/jms: persistence/impl and 1 other directories.

do-not-reply at jboss.org do-not-reply at jboss.org
Thu Mar 25 14:57:35 EDT 2010


Author: ataylor
Date: 2010-03-25 14:57:34 -0400 (Thu, 25 Mar 2010)
New Revision: 8966

Added:
   branches/Clebert_TMP/src/main/org/hornetq/jms/persistence/impl/DestinationType.java
   branches/Clebert_TMP/src/main/org/hornetq/jms/persistence/impl/PersistedJNDIBinding.java
Modified:
   branches/Clebert_TMP/src/main/org/hornetq/jms/persistence/JMSStorageManager.java
   branches/Clebert_TMP/src/main/org/hornetq/jms/persistence/PersistedDestination.java
   branches/Clebert_TMP/src/main/org/hornetq/jms/server/impl/JMSServerManagerImpl.java
Log:
jndi persistence type

Modified: branches/Clebert_TMP/src/main/org/hornetq/jms/persistence/JMSStorageManager.java
===================================================================
--- branches/Clebert_TMP/src/main/org/hornetq/jms/persistence/JMSStorageManager.java	2010-03-25 15:04:26 UTC (rev 8965)
+++ branches/Clebert_TMP/src/main/org/hornetq/jms/persistence/JMSStorageManager.java	2010-03-25 18:57:34 UTC (rev 8966)
@@ -16,6 +16,7 @@
 import java.util.List;
 
 import org.hornetq.core.server.HornetQComponent;
+import org.hornetq.jms.persistence.impl.PersistedJNDIBinding;
 
 /**
  * A JMSPersistence
@@ -57,4 +58,5 @@
 
    // Inner classes -------------------------------------------------
 
+   void storeJndiBinding(PersistedJNDIBinding persistedJNDIBinding);
 }

Modified: branches/Clebert_TMP/src/main/org/hornetq/jms/persistence/PersistedDestination.java
===================================================================
--- branches/Clebert_TMP/src/main/org/hornetq/jms/persistence/PersistedDestination.java	2010-03-25 15:04:26 UTC (rev 8965)
+++ branches/Clebert_TMP/src/main/org/hornetq/jms/persistence/PersistedDestination.java	2010-03-25 18:57:34 UTC (rev 8966)
@@ -15,6 +15,7 @@
 
 import org.hornetq.api.core.HornetQBuffer;
 import org.hornetq.core.journal.EncodingSupport;
+import org.hornetq.jms.persistence.impl.DestinationType;
 import org.hornetq.utils.BufferHelper;
 import org.hornetq.utils.DataConstants;
 
@@ -29,26 +30,11 @@
 
    // Constants -----------------------------------------------------
 
-   public enum Type
-   {
-      QUEUE,
-      TOPIC;
-
-      public int getType()
-      {
-         return this == QUEUE ? 1 : 2;
-      }
-
-      static Type getType(int type)
-      {
-         return type == 1 ? QUEUE : TOPIC;
-      }
-   }
    // Attributes ----------------------------------------------------
 
    private long id;
 
-   private Type type;
+   private DestinationType type;
 
    private String name;
 
@@ -65,12 +51,12 @@
    {
    }
 
-   public PersistedDestination(final Type type, final String name, final String jndiBinding)
+   public PersistedDestination(final DestinationType type, final String name, final String jndiBinding)
    {
       this(type, name, jndiBinding, null, false);
    }
 
-   public PersistedDestination(final Type type, final String name, final String jndiBinding, final String selector, final boolean durable)
+   public PersistedDestination(final DestinationType type, final String name, final String jndiBinding, final String selector, final boolean durable)
    {
       this.type = type;
       this.name = name;
@@ -109,7 +95,7 @@
       return jndiBinding;
    }
 
-   public Type getType()
+   public DestinationType getType()
    {
       return type;
    }
@@ -144,7 +130,7 @@
 
    public void decode(final HornetQBuffer buffer)
    {
-      type = Type.getType(buffer.readInt());
+      type = DestinationType.getType(buffer.readInt());
       name = buffer.readString();
       jndiBinding = buffer.readString();
       selector = buffer.readNullableString();

Added: branches/Clebert_TMP/src/main/org/hornetq/jms/persistence/impl/DestinationType.java
===================================================================
--- branches/Clebert_TMP/src/main/org/hornetq/jms/persistence/impl/DestinationType.java	                        (rev 0)
+++ branches/Clebert_TMP/src/main/org/hornetq/jms/persistence/impl/DestinationType.java	2010-03-25 18:57:34 UTC (rev 8966)
@@ -0,0 +1,34 @@
+/*
+ * Copyright 2009 Red Hat, Inc.
+ *  Red Hat licenses this file to you under the Apache License, version
+ *  2.0 (the "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ *  implied.  See the License for the specific language governing
+ *  permissions and limitations under the License.
+ */
+
+package org.hornetq.jms.persistence.impl;
+
+/**
+ * @author <a href="mailto:andy.taylor at jboss.org">Andy Taylor</a>
+ *         Created Mar 25, 2010
+ */
+public enum DestinationType
+{
+   QUEUE,
+   TOPIC;
+
+   public int getType()
+   {
+      return this == QUEUE ? 1 : 2;
+   }
+
+   public static DestinationType getType(int type)
+   {
+      return type == 1 ? QUEUE : TOPIC;
+   }
+}

Added: branches/Clebert_TMP/src/main/org/hornetq/jms/persistence/impl/PersistedJNDIBinding.java
===================================================================
--- branches/Clebert_TMP/src/main/org/hornetq/jms/persistence/impl/PersistedJNDIBinding.java	                        (rev 0)
+++ branches/Clebert_TMP/src/main/org/hornetq/jms/persistence/impl/PersistedJNDIBinding.java	2010-03-25 18:57:34 UTC (rev 8966)
@@ -0,0 +1,90 @@
+/*
+ * Copyright 2009 Red Hat, Inc.
+ *  Red Hat licenses this file to you under the Apache License, version
+ *  2.0 (the "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ *  implied.  See the License for the specific language governing
+ *  permissions and limitations under the License.
+ */
+package org.hornetq.jms.persistence.impl;
+
+import org.hornetq.api.core.HornetQBuffer;
+import org.hornetq.core.journal.EncodingSupport;
+import org.hornetq.utils.BufferHelper;
+import org.hornetq.utils.DataConstants;
+
+/**
+ * @author <a href="mailto:andy.taylor at jboss.org">Andy Taylor</a>
+ *         Created Mar 25, 2010
+ */
+public class PersistedJNDIBinding implements EncodingSupport
+{
+   private long id;
+
+   private DestinationType type;
+
+   private String name;
+
+   private String jndiBinding;
+
+   public PersistedJNDIBinding()
+   {
+   }
+
+   public PersistedJNDIBinding(final DestinationType type, final String name, final String jndiBinding)
+   {
+      this.type = type;
+      this.name = name;
+      this.jndiBinding = jndiBinding;
+   }
+
+      public long getId()
+   {
+      return id;
+   }
+
+   public void setId(final long id)
+   {
+      this.id = id;
+   }
+
+   public String getName()
+   {
+      return name;
+   }
+
+   public String getJndiBinding()
+   {
+      return jndiBinding;
+   }
+
+   public DestinationType getType()
+   {
+      return type;
+   }
+   
+   public int getEncodeSize()
+   {
+      return DataConstants.SIZE_INT +
+            BufferHelper.sizeOfSimpleString(name) +
+            BufferHelper.sizeOfSimpleString(jndiBinding);
+   }
+
+   public void encode(final HornetQBuffer buffer)
+   {
+      buffer.writeInt(type.getType());
+      buffer.writeString(name);
+      buffer.writeString(jndiBinding);
+   }
+
+   public void decode(final HornetQBuffer buffer)
+   {
+      type = DestinationType.getType(buffer.readInt());
+      name = buffer.readString();
+      jndiBinding = buffer.readString();
+   }
+}

Modified: branches/Clebert_TMP/src/main/org/hornetq/jms/server/impl/JMSServerManagerImpl.java
===================================================================
--- branches/Clebert_TMP/src/main/org/hornetq/jms/server/impl/JMSServerManagerImpl.java	2010-03-25 15:04:26 UTC (rev 8965)
+++ branches/Clebert_TMP/src/main/org/hornetq/jms/server/impl/JMSServerManagerImpl.java	2010-03-25 18:57:34 UTC (rev 8966)
@@ -45,6 +45,8 @@
 import org.hornetq.jms.persistence.JMSStorageManager;
 import org.hornetq.jms.persistence.PersistedConnectionFactory;
 import org.hornetq.jms.persistence.PersistedDestination;
+import org.hornetq.jms.persistence.impl.DestinationType;
+import org.hornetq.jms.persistence.impl.PersistedJNDIBinding;
 import org.hornetq.jms.persistence.impl.journal.JournalJMSStorageManagerImpl;
 import org.hornetq.jms.persistence.impl.nullpm.NullJMSStorageManagerImpl;
 import org.hornetq.jms.server.JMSServerManager;
@@ -56,9 +58,6 @@
 import org.hornetq.jms.server.management.impl.JMSManagementServiceImpl;
 import org.hornetq.utils.TimeAndCounterIDGenerator;
 
-import static org.hornetq.jms.persistence.PersistedDestination.Type.QUEUE;
-import static org.hornetq.jms.persistence.PersistedDestination.Type.TOPIC;
-
 /**
  * A Deployer used to create and add to JNDI queues, topics and connection
  * factories. Typically this would only be used in an app server env.
@@ -86,8 +85,10 @@
     */
    private Context context;
 
-   private final Map<String, List<String>> destinations = new HashMap<String, List<String>>();
+   private Map<String, HornetQDestination> destinations = new HashMap<String, HornetQDestination>();
 
+   private final Map<String, List<String>> destinationBindings = new HashMap<String, List<String>>();
+
    private final Map<String, HornetQConnectionFactory> connectionFactories = new HashMap<String, HornetQConnectionFactory>();
 
    private final Map<String, List<String>> connectionFactoryBindings = new HashMap<String, List<String>>();
@@ -219,7 +220,7 @@
          deploymentManager.stop();
       }
 
-      for (String destination : destinations.keySet())
+      for (String destination : destinationBindings.keySet())
       {
          undeployDestination(destination);
       }
@@ -229,7 +230,7 @@
          destroyConnectionFactory(connectionFactory);
       }
 
-      destinations.clear();
+      destinationBindings.clear();
       connectionFactories.clear();
       connectionFactoryBindings.clear();
 
@@ -302,7 +303,7 @@
 
       boolean added = internalCreateQueue(queueName, jndiBinding, selectorString, durable);
 
-      storage.storeDestination(new PersistedDestination(QUEUE, queueName, jndiBinding, selectorString, durable));
+      storage.storeDestination(new PersistedDestination(DestinationType.QUEUE, queueName, jndiBinding, selectorString, durable));
 
       return added;
    }
@@ -313,15 +314,55 @@
 
       boolean added = internalCreateTopic(topicName, jndiBinding);
 
-      storage.storeDestination(new PersistedDestination(TOPIC, topicName, jndiBinding));
+      storage.storeDestination(new PersistedDestination(DestinationType.TOPIC, topicName, jndiBinding));
 
       return added;
    }
 
+   public boolean addTopicToJndi(final String topicName, final String jndiBinding) throws NamingException
+   {
+      HornetQDestination destination = destinations.get(topicName);
+      if(destination == null)
+      {
+         throw new IllegalArgumentException("Topic does not exist");
+      }
+      if(destination.getTopicName() == null)
+      {
+         throw new IllegalArgumentException(topicName + " is not a topic");
+      }
+      boolean added = bindToJndi(jndiBinding, destination);
+      if (added)
+      {
+         addToDestinationBindings(topicName, jndiBinding);
+         storage.storeJndiBinding(new PersistedJNDIBinding(DestinationType.TOPIC, topicName, jndiBinding));
+      }
+      return added;
+   }
+
+   public boolean addQueueToJndi(final String queueName, final String jndiBinding) throws NamingException
+   {
+      HornetQDestination destination = destinations.get(queueName);
+      if(destination == null)
+      {
+         throw new IllegalArgumentException("Queue does not exist");
+      }
+      if(destination.getQueueName() == null)
+      {
+         throw new IllegalArgumentException(queueName + " is not a queue");
+      }
+      boolean added = bindToJndi(jndiBinding, destination);
+      if (added)
+      {
+         addToDestinationBindings(queueName, jndiBinding);
+         storage.storeJndiBinding(new PersistedJNDIBinding(DestinationType.QUEUE, queueName, jndiBinding));
+      }
+      return added;
+   }
+
    public synchronized boolean undeployDestination(final String name) throws Exception
    {
       checkInitialised();
-      List<String> jndiBindings = destinations.get(name);
+      List<String> jndiBindings = destinationBindings.get(name);
       if (jndiBindings == null || jndiBindings.size() == 0)
       {
          return false;
@@ -344,7 +385,7 @@
       checkInitialised();
       undeployDestination(name);
 
-      destinations.remove(name);
+      destinationBindings.remove(name);
       jmsManagementService.unregisterQueue(name);
       server.getHornetQServerControl().destroyQueue(HornetQDestination.createQueueAddressFromName(name).toString());
       storage.deleteDestination(name);
@@ -356,7 +397,7 @@
       checkInitialised();
       undeployDestination(name);
 
-      destinations.remove(name);
+      destinationBindings.remove(name);
       jmsManagementService.unregisterTopic(name);
       AddressControl addressControl = (AddressControl)server.getManagementService().getResource(ResourceNames.CORE_ADDRESS + HornetQDestination.createTopicAddressFromName(name));
       if (addressControl != null)
@@ -953,11 +994,11 @@
 
    private void addToDestinationBindings(final String destination, final String jndiBinding)
    {
-      if (destinations.get(destination) == null)
+      if (destinationBindings.get(destination) == null)
       {
-         destinations.put(destination, new ArrayList<String>());
+         destinationBindings.put(destination, new ArrayList<String>());
       }
-      destinations.get(destination).add(jndiBinding);
+      destinationBindings.get(destination).add(jndiBinding);
    }
 
    private void deploy() throws Exception
@@ -1030,11 +1071,11 @@
 
       for (PersistedDestination destination : destinations)
       {
-         if(destination.getType() == QUEUE)
+         if(destination.getType() == DestinationType.QUEUE)
          {
             internalCreateQueue(destination.getName(), destination.getJndiBinding(), destination.getSelector(), destination.isDurable());
          }
-         else if(destination.getType() == TOPIC)
+         else if(destination.getType() == DestinationType.TOPIC)
          {
             internalCreateTopic(destination.getName(), destination.getJndiBinding());   
          }



More information about the hornetq-commits mailing list