[jboss-cvs] JBoss Messaging SVN: r4797 - in branches/Branch_JBMESSAGING-1314: src/main/org/jboss/messaging/core/paging/impl and 1 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Tue Aug 12 17:52:13 EDT 2008
Author: clebert.suconic at jboss.com
Date: 2008-08-12 17:52:13 -0400 (Tue, 12 Aug 2008)
New Revision: 4797
Added:
branches/Branch_JBMESSAGING-1314/src/main/org/jboss/messaging/core/paging/impl/PagingManagerImpl.java
branches/Branch_JBMESSAGING-1314/src/main/org/jboss/messaging/core/paging/impl/PagingManagerNIOSPI.java
branches/Branch_JBMESSAGING-1314/src/main/org/jboss/messaging/core/paging/impl/PagingManagerSPI.java
branches/Branch_JBMESSAGING-1314/tests/src/org/jboss/messaging/tests/unit/core/paging/impl/PageManagerImplTest.java
Modified:
branches/Branch_JBMESSAGING-1314/src/main/org/jboss/messaging/core/paging/PagingManager.java
branches/Branch_JBMESSAGING-1314/src/main/org/jboss/messaging/core/paging/PagingStore.java
branches/Branch_JBMESSAGING-1314/src/main/org/jboss/messaging/core/paging/impl/PagingStoreImpl.java
branches/Branch_JBMESSAGING-1314/tests/src/org/jboss/messaging/tests/unit/core/paging/impl/PagingStoreImplTest.java
branches/Branch_JBMESSAGING-1314/tests/src/org/jboss/messaging/tests/unit/core/paging/impl/PagingStoreTestBase.java
Log:
Implementation / test of PagingManager
Modified: branches/Branch_JBMESSAGING-1314/src/main/org/jboss/messaging/core/paging/PagingManager.java
===================================================================
--- branches/Branch_JBMESSAGING-1314/src/main/org/jboss/messaging/core/paging/PagingManager.java 2008-08-12 16:53:05 UTC (rev 4796)
+++ branches/Branch_JBMESSAGING-1314/src/main/org/jboss/messaging/core/paging/PagingManager.java 2008-08-12 21:52:13 UTC (rev 4797)
@@ -33,5 +33,5 @@
*/
public interface PagingManager extends MessagingComponent
{
- public PagingStore getPageStore(String storeName);
+ public PagingStore getPageStore(String storeName) throws Exception;
}
Modified: branches/Branch_JBMESSAGING-1314/src/main/org/jboss/messaging/core/paging/PagingStore.java
===================================================================
--- branches/Branch_JBMESSAGING-1314/src/main/org/jboss/messaging/core/paging/PagingStore.java 2008-08-12 16:53:05 UTC (rev 4796)
+++ branches/Branch_JBMESSAGING-1314/src/main/org/jboss/messaging/core/paging/PagingStore.java 2008-08-12 21:52:13 UTC (rev 4797)
@@ -23,6 +23,7 @@
package org.jboss.messaging.core.paging;
+import org.jboss.messaging.core.server.MessagingComponent;
import org.jboss.messaging.core.server.ServerMessage;
/**
@@ -34,14 +35,14 @@
* @author <a href="mailto:clebert.suconic at jboss.com">Clebert Suconic</a>
*
*/
-public interface PagingStore
+public interface PagingStore extends MessagingComponent
{
int getNumberOfPages();
String getStoreName();
- void startPage() throws Exception;
+ void startPaging() throws Exception;
void sync() throws Exception;
@@ -55,6 +56,5 @@
* @throws Exception
*/
Page dequeuePage() throws Exception;
-
- void init() throws Exception;
+
}
Added: branches/Branch_JBMESSAGING-1314/src/main/org/jboss/messaging/core/paging/impl/PagingManagerImpl.java
===================================================================
--- branches/Branch_JBMESSAGING-1314/src/main/org/jboss/messaging/core/paging/impl/PagingManagerImpl.java (rev 0)
+++ branches/Branch_JBMESSAGING-1314/src/main/org/jboss/messaging/core/paging/impl/PagingManagerImpl.java 2008-08-12 21:52:13 UTC (rev 4797)
@@ -0,0 +1,125 @@
+/*
+ * 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.paging.impl;
+
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+
+import org.jboss.messaging.core.journal.SequentialFileFactory;
+import org.jboss.messaging.core.paging.PagingManager;
+import org.jboss.messaging.core.paging.PagingStore;
+
+/**
+ *
+ * @author <a href="mailto:clebert.suconic at jboss.com">Clebert Suconic</a>
+ *
+ */
+public class PagingManagerImpl implements PagingManager
+{
+ // Constants -----------------------------------------------------
+
+ // Attributes ----------------------------------------------------
+
+ private volatile boolean started = false;
+
+ private final ConcurrentMap<String, PagingStore> stores = new ConcurrentHashMap<String, PagingStore>();
+
+ private final PagingManagerSPI pagingSPI;
+
+ // Static --------------------------------------------------------
+
+ // Constructors --------------------------------------------------
+
+ public PagingManagerImpl(final PagingManagerSPI pagingSPI)
+ {
+ this.pagingSPI = pagingSPI;
+ }
+
+ // Public --------------------------------------------------------
+
+ public PagingStore getPageStore(String storeName) throws Exception
+ {
+ validateStarted();
+
+ PagingStore store = stores.get(storeName);
+ if (store == null)
+ {
+
+ store = newStore(storeName);
+
+ stores.putIfAbsent(storeName, store);
+
+ store = stores.get(storeName);
+
+ store.start();
+ }
+
+ return store;
+
+ }
+
+ public boolean isStarted()
+ {
+ return started;
+ }
+
+ public void start() throws Exception
+ {
+ this.started = true;
+
+ }
+
+ public void stop() throws Exception
+ {
+ this.started = false;
+
+ for (PagingStore store: stores.values())
+ {
+ store.stop();
+ }
+ }
+
+
+ // Package protected ---------------------------------------------
+
+ // Protected -----------------------------------------------------
+
+ // Private -------------------------------------------------------
+
+ private PagingStore newStore(String destinationName)
+ {
+ return pagingSPI.newStore(destinationName);
+ }
+
+ private void validateStarted()
+ {
+ if (!started)
+ {
+ throw new IllegalStateException("PagingManager is not started");
+ }
+ }
+
+ // Inner classes -------------------------------------------------
+
+}
Added: branches/Branch_JBMESSAGING-1314/src/main/org/jboss/messaging/core/paging/impl/PagingManagerNIOSPI.java
===================================================================
--- branches/Branch_JBMESSAGING-1314/src/main/org/jboss/messaging/core/paging/impl/PagingManagerNIOSPI.java (rev 0)
+++ branches/Branch_JBMESSAGING-1314/src/main/org/jboss/messaging/core/paging/impl/PagingManagerNIOSPI.java 2008-08-12 21:52:13 UTC (rev 4797)
@@ -0,0 +1,70 @@
+/*
+ * 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.paging.impl;
+
+import org.jboss.messaging.core.journal.impl.NIOSequentialFileFactory;
+import org.jboss.messaging.core.paging.PagingStore;
+
+/**
+ *
+ * Integration point between Paging and NIO
+ * @author <a href="mailto:clebert.suconic at jboss.com">Clebert Suconic</a>
+ *
+ */
+public class PagingManagerNIOSPI implements PagingManagerSPI
+{
+
+ // Constants -----------------------------------------------------
+
+ // Attributes ----------------------------------------------------
+
+ private final String directory;
+ private final int pageSize;
+
+ // Static --------------------------------------------------------
+
+ // Constructors --------------------------------------------------
+
+ public PagingManagerNIOSPI(final String directory, final int pageSize)
+ {
+ this.directory = directory;
+ this.pageSize = pageSize;
+ }
+
+ // Public --------------------------------------------------------
+
+ public PagingStore newStore(String destinationName)
+ {
+ return new PagingStoreImpl(new NIOSequentialFileFactory(directory + "/" + destinationName), destinationName, pageSize);
+ }
+
+ // Package protected ---------------------------------------------
+
+ // Protected -----------------------------------------------------
+
+ // Private -------------------------------------------------------
+
+ // Inner classes -------------------------------------------------
+
+}
Added: branches/Branch_JBMESSAGING-1314/src/main/org/jboss/messaging/core/paging/impl/PagingManagerSPI.java
===================================================================
--- branches/Branch_JBMESSAGING-1314/src/main/org/jboss/messaging/core/paging/impl/PagingManagerSPI.java (rev 0)
+++ branches/Branch_JBMESSAGING-1314/src/main/org/jboss/messaging/core/paging/impl/PagingManagerSPI.java 2008-08-12 21:52:13 UTC (rev 4797)
@@ -0,0 +1,40 @@
+/*
+ * 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.paging.impl;
+
+import org.jboss.messaging.core.journal.SequentialFileFactory;
+import org.jboss.messaging.core.paging.PagingStore;
+
+/**
+ * The integration point between the PagingManger and the File System (aka SequentialFiles)
+ *
+ * @author <a href="mailto:clebert.suconic at jboss.com">Clebert Suconic</a>
+ *
+ */
+public interface PagingManagerSPI
+{
+
+ PagingStore newStore(String destinationName);
+
+}
Modified: branches/Branch_JBMESSAGING-1314/src/main/org/jboss/messaging/core/paging/impl/PagingStoreImpl.java
===================================================================
--- branches/Branch_JBMESSAGING-1314/src/main/org/jboss/messaging/core/paging/impl/PagingStoreImpl.java 2008-08-12 16:53:05 UTC (rev 4796)
+++ branches/Branch_JBMESSAGING-1314/src/main/org/jboss/messaging/core/paging/impl/PagingStoreImpl.java 2008-08-12 21:52:13 UTC (rev 4797)
@@ -224,16 +224,50 @@
}
}
- public void init() throws Exception
+
+ // MessagingComponent implementation
+
+ public boolean isStarted()
{
+ return initialized;
+ }
+
+ public void stop() throws Exception
+ {
+ if (initialized)
+ {
+ lock.writeLock().lock();
+
+ try
+ {
+ initialized = false;
+ currentPage.close();
+ }
+ finally
+ {
+ lock.writeLock().unlock();
+ }
+ }
+ }
+
+ public void start() throws Exception
+ {
+
if (initialized)
{
- throw new IllegalStateException("PageStore " + this.storeName + " already initialized!");
+ // don't throw an exception.
+ // You could have two threads adding PagingStore to a ConcurrentHashMap,
+ // and having both threads calling init. One of the calls should just need to be ignored
+ return;
}
lock.writeLock().lock();
+ firstPageId = Integer.MAX_VALUE;
+ currentPageId = 0;
+ currentPage = null;
+
try
{
@@ -260,7 +294,7 @@
if (numberOfPages != 0)
{
- startPage();
+ startPaging();
}
}
finally
@@ -269,7 +303,7 @@
}
}
- public void startPage() throws Exception
+ public void startPaging() throws Exception
{
validateInit();
Added: branches/Branch_JBMESSAGING-1314/tests/src/org/jboss/messaging/tests/unit/core/paging/impl/PageManagerImplTest.java
===================================================================
--- branches/Branch_JBMESSAGING-1314/tests/src/org/jboss/messaging/tests/unit/core/paging/impl/PageManagerImplTest.java (rev 0)
+++ branches/Branch_JBMESSAGING-1314/tests/src/org/jboss/messaging/tests/unit/core/paging/impl/PageManagerImplTest.java 2008-08-12 21:52:13 UTC (rev 4797)
@@ -0,0 +1,125 @@
+/*
+ * 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.tests.unit.core.paging.impl;
+
+import org.easymock.EasyMock;
+import org.jboss.messaging.core.journal.SequentialFileFactory;
+import org.jboss.messaging.core.paging.PagingStore;
+import org.jboss.messaging.core.paging.impl.PagingManagerImpl;
+import org.jboss.messaging.core.paging.impl.PagingManagerSPI;
+import org.jboss.messaging.core.paging.impl.PagingStoreImpl;
+import org.jboss.messaging.tests.unit.core.journal.impl.fakes.FakeSequentialFileFactory;
+import org.jboss.messaging.tests.util.UnitTestCase;
+
+public class PageManagerImplTest extends UnitTestCase
+{
+
+ // Constants -----------------------------------------------------
+
+ // Attributes ----------------------------------------------------
+
+ // Static --------------------------------------------------------
+
+ // Constructors --------------------------------------------------
+
+ // Public --------------------------------------------------------
+
+
+ public void testGetStore() throws Exception
+ {
+ PagingManagerSPI spi = EasyMock.createMock(PagingManagerSPI.class);
+ PagingManagerImpl manager = new PagingManagerImpl(spi);
+
+ String destination = "some-destination";
+
+ try
+ {
+ manager.getPageStore(destination);
+ fail ("supposed to throw an exception");
+ }
+ catch (Exception ignored)
+ {
+ }
+
+ manager.start();
+
+ PagingStore store = EasyMock.createNiceMock(PagingStore.class);
+
+ EasyMock.expect(spi.newStore(destination)).andReturn(store);
+
+ store.start();
+
+
+ EasyMock.replay(spi, store);
+
+ assertEquals(store, manager.getPageStore(destination));
+
+ EasyMock.verify(spi, store);
+
+ EasyMock.reset(spi, store);
+
+ EasyMock.replay(spi, store);
+
+ // it should use the cached store, so nothing else should be called on any SPI
+ assertEquals(store, manager.getPageStore(destination));
+
+ EasyMock.verify(spi, store);
+
+ EasyMock.reset(spi, store);
+
+ store.stop();
+
+ EasyMock.replay(spi, store);
+
+ manager.stop();
+
+ EasyMock.verify(spi, store);
+
+ }
+
+
+ // Package protected ---------------------------------------------
+
+ // Protected -----------------------------------------------------
+
+ // Private -------------------------------------------------------
+
+ // Inner classes -------------------------------------------------
+
+ class FakeManagerSPI implements PagingManagerSPI
+ {
+
+ public SequentialFileFactory newFactory(String destinationName)
+ {
+ return new FakeSequentialFileFactory();
+ }
+
+ public PagingStore newStore(String destinationName)
+ {
+ return new PagingStoreImpl(new FakeSequentialFileFactory(),destinationName, 10 * 1024);
+ }
+
+ }
+
+}
Modified: branches/Branch_JBMESSAGING-1314/tests/src/org/jboss/messaging/tests/unit/core/paging/impl/PagingStoreImplTest.java
===================================================================
--- branches/Branch_JBMESSAGING-1314/tests/src/org/jboss/messaging/tests/unit/core/paging/impl/PagingStoreImplTest.java 2008-08-12 16:53:05 UTC (rev 4796)
+++ branches/Branch_JBMESSAGING-1314/tests/src/org/jboss/messaging/tests/unit/core/paging/impl/PagingStoreImplTest.java 2008-08-12 21:52:13 UTC (rev 4797)
@@ -60,11 +60,11 @@
PagingStore storeImpl = new PagingStoreImpl(factory, "test", 1024 * 2);
- storeImpl.init();
+ storeImpl.start();
assertEquals(0, storeImpl.getNumberOfPages());
- storeImpl.startPage();
+ storeImpl.startPaging();
assertEquals(1, storeImpl.getNumberOfPages());
@@ -85,7 +85,7 @@
storeImpl = new PagingStoreImpl(factory, "test", 1024 * 2);
- storeImpl.init();
+ storeImpl.start();
assertEquals(2, storeImpl.getNumberOfPages());
@@ -97,11 +97,11 @@
PagingStore storeImpl = new PagingStoreImpl(factory, "test", 1024 * 10);
- storeImpl.init();
+ storeImpl.start();
assertEquals(0, storeImpl.getNumberOfPages());
- storeImpl.startPage();
+ storeImpl.startPaging();
List<ByteBuffer> buffers = new ArrayList<ByteBuffer>();
@@ -149,11 +149,11 @@
TestSupportPageStore storeImpl = new PagingStoreImpl(factory, "test", 1024 * 10);
- storeImpl.init();
+ storeImpl.start();
assertEquals(0, storeImpl.getNumberOfPages());
- storeImpl.startPage();
+ storeImpl.startPaging();
assertEquals(1, storeImpl.getNumberOfPages());
@@ -209,7 +209,7 @@
assertFalse(storeImpl.writeOnCurrentPage(msg));
- storeImpl.startPage();
+ storeImpl.startPaging();
assertTrue(storeImpl.writeOnCurrentPage(msg));
Modified: branches/Branch_JBMESSAGING-1314/tests/src/org/jboss/messaging/tests/unit/core/paging/impl/PagingStoreTestBase.java
===================================================================
--- branches/Branch_JBMESSAGING-1314/tests/src/org/jboss/messaging/tests/unit/core/paging/impl/PagingStoreTestBase.java 2008-08-12 16:53:05 UTC (rev 4796)
+++ branches/Branch_JBMESSAGING-1314/tests/src/org/jboss/messaging/tests/unit/core/paging/impl/PagingStoreTestBase.java 2008-08-12 21:52:13 UTC (rev 4797)
@@ -82,11 +82,11 @@
final TestSupportPageStore storeImpl = new PagingStoreImpl(factory, "test", MAX_SIZE);
- storeImpl.init();
+ storeImpl.start();
assertEquals(0, storeImpl.getNumberOfPages());
- storeImpl.startPage();
+ storeImpl.startPaging();
assertEquals(1, storeImpl.getNumberOfPages());
@@ -227,16 +227,16 @@
}
TestSupportPageStore storeImpl2 = new PagingStoreImpl(factory, "test", MAX_SIZE);
- storeImpl2.init();
+ storeImpl2.start();
int numberOfPages = storeImpl2.getNumberOfPages();
assertTrue(numberOfPages != 0);
- storeImpl2.startPage();
+ storeImpl2.startPaging();
- storeImpl2.startPage();
+ storeImpl2.startPaging();
assertEquals(numberOfPages, storeImpl2.getNumberOfPages());
@@ -283,9 +283,6 @@
assertEquals(lastMessages[0].getMessageID(), lastMessageId);
assertEqualsByteArrays(lastMessages[0].getBody().array(), lastMsg.getBody().array());
- System.out.println("Last Message ID = " + lastMsg.getMessageID());
-
-
assertEquals(0, buffers2.size());
More information about the jboss-cvs-commits
mailing list