[jboss-cvs] JBoss Messaging SVN: r7514 - in branches/Branch_MultiThreaded_Replication/src/main/org/jboss/messaging/core: server/impl and 2 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Jul 2 07:27:56 EDT 2009


Author: timfox
Date: 2009-07-02 07:27:55 -0400 (Thu, 02 Jul 2009)
New Revision: 7514

Added:
   branches/Branch_MultiThreaded_Replication/src/main/org/jboss/messaging/core/remoting/impl/wireformat/replication/RegisterQueueReplicationChannelMessage.java
   branches/Branch_MultiThreaded_Replication/src/main/org/jboss/messaging/core/server/impl/QueueReplicationPacketHandler.java
   branches/Branch_MultiThreaded_Replication/src/main/org/jboss/messaging/core/server/replication/ReplicableAction.java
   branches/Branch_MultiThreaded_Replication/src/main/org/jboss/messaging/core/server/replication/impl/ReplicationAwareAtomicLong.java
Log:
MT replication

Added: branches/Branch_MultiThreaded_Replication/src/main/org/jboss/messaging/core/remoting/impl/wireformat/replication/RegisterQueueReplicationChannelMessage.java
===================================================================
--- branches/Branch_MultiThreaded_Replication/src/main/org/jboss/messaging/core/remoting/impl/wireformat/replication/RegisterQueueReplicationChannelMessage.java	                        (rev 0)
+++ branches/Branch_MultiThreaded_Replication/src/main/org/jboss/messaging/core/remoting/impl/wireformat/replication/RegisterQueueReplicationChannelMessage.java	2009-07-02 11:27:55 UTC (rev 7514)
@@ -0,0 +1,82 @@
+/*
+ * JBoss, Home of Professional Open Source Copyright 2005-2008, Red Hat Middleware LLC, and individual contributors by
+ * the @authors tag. See the copyright.txt in the distribution for a full listing of individual contributors. This is
+ * free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.
+ * This software is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
+ * details. You should have received a copy of the GNU Lesser General Public License along with this software; if not,
+ * write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA, or see the FSF
+ * site: http://www.fsf.org.
+ */
+
+package org.jboss.messaging.core.remoting.impl.wireformat.replication;
+
+import org.jboss.messaging.core.remoting.impl.wireformat.PacketImpl;
+import org.jboss.messaging.core.remoting.spi.MessagingBuffer;
+import org.jboss.messaging.utils.DataConstants;
+
+/**
+ * 
+ * A RegisterQueueReplicationChannelMessage
+ *
+ * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
+ *
+ *
+ */
+public class RegisterQueueReplicationChannelMessage extends PacketImpl
+{
+   // Constants -----------------------------------------------------
+
+   // Attributes ----------------------------------------------------
+
+   private long bindingID;
+
+   // Static --------------------------------------------------------
+
+   // Constructors --------------------------------------------------
+
+   public RegisterQueueReplicationChannelMessage(final long bindingID)
+   {
+      super(REGISTER_QUEUE_REPLICATION_CHANNEL);
+
+      this.bindingID = bindingID;
+   }
+
+   // Public --------------------------------------------------------
+
+   public RegisterQueueReplicationChannelMessage()
+   {
+      super(REGISTER_QUEUE_REPLICATION_CHANNEL);
+   }
+
+   public int getRequiredBufferSize()
+   {
+      return BASIC_PACKET_SIZE + DataConstants.SIZE_LONG;
+   }
+
+   @Override
+   public void encodeBody(final MessagingBuffer buffer)
+   {
+      buffer.writeLong(bindingID);
+   }
+
+   @Override
+   public void decodeBody(final MessagingBuffer buffer)
+   {           
+      bindingID = buffer.readLong();
+   }
+
+   public long getBindingID()
+   {
+      return bindingID;
+   }
+
+   // Package protected ---------------------------------------------
+
+   // Protected -----------------------------------------------------
+
+   // Private -------------------------------------------------------
+
+   // Inner classes -------------------------------------------------
+}

Added: branches/Branch_MultiThreaded_Replication/src/main/org/jboss/messaging/core/server/impl/QueueReplicationPacketHandler.java
===================================================================
--- branches/Branch_MultiThreaded_Replication/src/main/org/jboss/messaging/core/server/impl/QueueReplicationPacketHandler.java	                        (rev 0)
+++ branches/Branch_MultiThreaded_Replication/src/main/org/jboss/messaging/core/server/impl/QueueReplicationPacketHandler.java	2009-07-02 11:27:55 UTC (rev 7514)
@@ -0,0 +1,132 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005-2009, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.messaging.core.server.impl;
+
+import static org.jboss.messaging.core.remoting.impl.wireformat.PacketImpl.REPLICATE_LOCK_SEQUENCES;
+
+import java.util.List;
+
+import org.jboss.messaging.core.logging.Logger;
+import org.jboss.messaging.core.postoffice.Binding;
+import org.jboss.messaging.core.postoffice.PostOffice;
+import org.jboss.messaging.core.remoting.Channel;
+import org.jboss.messaging.core.remoting.ChannelHandler;
+import org.jboss.messaging.core.remoting.Packet;
+import org.jboss.messaging.core.remoting.impl.wireformat.PacketImpl;
+import org.jboss.messaging.core.remoting.impl.wireformat.replication.ReplicateLockSequenceMessage;
+import org.jboss.messaging.core.remoting.impl.wireformat.replication.ReplicationResponseMessage;
+import org.jboss.messaging.core.server.HandleStatus;
+import org.jboss.messaging.core.server.Queue;
+import org.jboss.messaging.core.server.replication.impl.JBMThread;
+
+/**
+ * A QueueReplicationPacketHandler
+ *
+ * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
+ *
+ *
+ */
+public class QueueReplicationPacketHandler implements ChannelHandler
+{
+   private static final Logger log = Logger.getLogger(QueueReplicationPacketHandler.class);
+   
+   private final long queueID;
+   
+   private volatile Queue queue;
+
+   private volatile List<Long> sequences;
+   
+   private volatile boolean requiresReplicationResponse;
+   
+   private final PostOffice postOffice;
+   
+   private final Channel channel;
+
+   public QueueReplicationPacketHandler(final long queueID, final PostOffice postOffice, final Channel channel)
+   {
+      this.queueID = queueID;
+      
+      this.postOffice = postOffice;
+      
+      this.channel = channel;
+   }
+
+   public void handlePacket(final Packet packet)
+   {
+      switch (packet.getType())
+      {
+         case REPLICATE_LOCK_SEQUENCES:
+         {
+            ReplicateLockSequenceMessage msg = (ReplicateLockSequenceMessage)packet;
+            
+            sequences = msg.getSequences();
+            
+            requiresReplicationResponse = msg.isRequiresResponse();
+            
+            break;
+         }
+         case PacketImpl.REPLICATE_QUEUE_DELIVERY:
+         {           
+            JBMThread thread = JBMThread.currentThread();
+
+            thread.setReplay(sequences);
+
+            if (queue == null)
+            {
+               JBMThread.currentThread().setNoReplayOrRecord();
+               
+               Binding binding = postOffice.getBindingByID(queueID);
+
+               if (binding == null)
+               {
+                  throw new IllegalStateException("Cannot find binding " + queueID);
+               }
+
+               queue = (Queue)binding.getBindable();
+               
+               JBMThread.currentThread().resumeReplay();
+            }
+            
+            HandleStatus handled = queue.deliverOne();
+            
+//            if (handled == HandleStatus.HANDLED)
+//            {
+//               log.info("*** delivered message on backup");
+//            }
+            
+            if (this.requiresReplicationResponse)
+            {
+               channel.send(new ReplicationResponseMessage());
+            }
+            
+            thread.setNoReplayOrRecord();
+
+            break;
+         }
+         default:
+         {
+            throw new IllegalArgumentException("Invalid packet " + packet);
+         }
+      }
+   }
+}

Added: branches/Branch_MultiThreaded_Replication/src/main/org/jboss/messaging/core/server/replication/ReplicableAction.java
===================================================================
--- branches/Branch_MultiThreaded_Replication/src/main/org/jboss/messaging/core/server/replication/ReplicableAction.java	                        (rev 0)
+++ branches/Branch_MultiThreaded_Replication/src/main/org/jboss/messaging/core/server/replication/ReplicableAction.java	2009-07-02 11:27:55 UTC (rev 7514)
@@ -0,0 +1,38 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005-2009, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+
+package org.jboss.messaging.core.server.replication;
+
+import org.jboss.messaging.core.remoting.Packet;
+
+/**
+ * A ReplicableAction
+ *
+ * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
+ *
+ *
+ */
+public interface ReplicableAction extends Runnable
+{
+   Packet getPacket();
+}

Added: branches/Branch_MultiThreaded_Replication/src/main/org/jboss/messaging/core/server/replication/impl/ReplicationAwareAtomicLong.java
===================================================================
--- branches/Branch_MultiThreaded_Replication/src/main/org/jboss/messaging/core/server/replication/impl/ReplicationAwareAtomicLong.java	                        (rev 0)
+++ branches/Branch_MultiThreaded_Replication/src/main/org/jboss/messaging/core/server/replication/impl/ReplicationAwareAtomicLong.java	2009-07-02 11:27:55 UTC (rev 7514)
@@ -0,0 +1,93 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005-2009, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.messaging.core.server.replication.impl;
+
+import java.util.concurrent.atomic.AtomicLong;
+
+import org.jboss.messaging.core.logging.Logger;
+import org.jboss.messaging.utils.Pair;
+
+/**
+ * A ReplicationAwareAtomicLong
+ *
+ * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
+ *
+ *
+ */
+public class ReplicationAwareAtomicLong
+{
+   private static final Logger log = Logger.getLogger(ReplicationAwareAtomicLong.class);
+
+   private final AtomicLong al;
+
+   public ReplicationAwareAtomicLong(final long initialValue)
+   {
+      this.al = new AtomicLong(initialValue);
+   }
+
+   public void set(final long l)
+   {
+      al.set(l);
+   }
+
+   public long getAndIncrement()
+   {
+      JBMThread thread = JBMThread.currentThread();
+
+      if (thread.isReplay())
+      {
+         long sequence = thread.getNextSequence();
+
+         while (!al.compareAndSet(sequence, sequence + 1))
+         {
+            Thread.yield();
+         }
+
+         return sequence;
+      }
+      else
+      {
+         long sequence = al.getAndIncrement();
+
+         thread.addSequence(sequence);
+         
+         return sequence;
+      }
+   }
+   
+   public long get()
+   {
+      return al.get();
+   }
+
+   // public long getAndIncrement(long expected)
+   // {
+   // while (!al.compareAndSet(expected, expected + 1))
+   // {
+   // Thread.yield();
+   // }
+   //
+   // return expected;
+   // }
+
+}




More information about the jboss-cvs-commits mailing list