You are viewing a plain text version of this content. The canonical link for it is here.
Posted to wadi-commits@incubator.apache.org by bd...@apache.org on 2005/12/14 23:36:16 UTC

svn commit: r356933 [5/35] - in /incubator/wadi/trunk: ./ etc/ modules/ modules/assembly/ modules/assembly/src/ modules/assembly/src/bin/ modules/assembly/src/conf/ modules/assembly/src/main/ modules/assembly/src/main/assembly/ modules/core/ modules/co...

Added: incubator/wadi/trunk/modules/core/src/main/java/org/codehaus/wadi/SessionConfig.java
URL: http://svn.apache.org/viewcvs/incubator/wadi/trunk/modules/core/src/main/java/org/codehaus/wadi/SessionConfig.java?rev=356933&view=auto
==============================================================================
--- incubator/wadi/trunk/modules/core/src/main/java/org/codehaus/wadi/SessionConfig.java (added)
+++ incubator/wadi/trunk/modules/core/src/main/java/org/codehaus/wadi/SessionConfig.java Wed Dec 14 15:32:56 2005
@@ -0,0 +1,43 @@
+/**
+ *
+ * Copyright 2003-2005 Core Developers Network Ltd.
+ *
+ *  Licensed 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.codehaus.wadi;
+
+import javax.servlet.ServletContext;
+import javax.servlet.http.HttpSessionAttributeListener;
+import javax.servlet.http.HttpSessionListener;
+
+
+public interface SessionConfig extends Config {
+    
+    ValuePool getValuePool();
+    AttributesFactory getAttributesFactory();
+    HttpSessionListener[] getSessionListeners();
+    HttpSessionAttributeListener[] getAttributeListeners();
+    ServletContext getServletContext();
+    
+    void destroy(Session session);
+    SessionWrapperFactory getSessionWrapperFactory();
+    SessionIdFactory getSessionIdFactory();
+    
+    int getMaxInactiveInterval();
+    
+    void setLastAccessedTime(Evictable evictable, long oldTime, long newTime);
+    void setMaxInactiveInterval(Evictable evictable, int oldInterval, int newInterval);
+    
+    Router getRouter();
+    
+}

Added: incubator/wadi/trunk/modules/core/src/main/java/org/codehaus/wadi/SessionFactory.java
URL: http://svn.apache.org/viewcvs/incubator/wadi/trunk/modules/core/src/main/java/org/codehaus/wadi/SessionFactory.java?rev=356933&view=auto
==============================================================================
--- incubator/wadi/trunk/modules/core/src/main/java/org/codehaus/wadi/SessionFactory.java (added)
+++ incubator/wadi/trunk/modules/core/src/main/java/org/codehaus/wadi/SessionFactory.java Wed Dec 14 15:32:56 2005
@@ -0,0 +1,21 @@
+/**
+ *
+ * Copyright 2003-2005 Core Developers Network Ltd.
+ *
+ *  Licensed 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.codehaus.wadi;
+
+public interface SessionFactory {
+    Session create(SessionConfig config);
+}

Added: incubator/wadi/trunk/modules/core/src/main/java/org/codehaus/wadi/SessionIdFactory.java
URL: http://svn.apache.org/viewcvs/incubator/wadi/trunk/modules/core/src/main/java/org/codehaus/wadi/SessionIdFactory.java?rev=356933&view=auto
==============================================================================
--- incubator/wadi/trunk/modules/core/src/main/java/org/codehaus/wadi/SessionIdFactory.java (added)
+++ incubator/wadi/trunk/modules/core/src/main/java/org/codehaus/wadi/SessionIdFactory.java Wed Dec 14 15:32:56 2005
@@ -0,0 +1,37 @@
+/**
+ *
+ * Copyright 2003-2005 Core Developers Network Ltd.
+ *
+ *  Licensed 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.codehaus.wadi;
+
+/**
+ * Abstract out the API for session id generation
+ *
+ * @author <a href="mailto:jules@coredevelopers.net">Jules Gosnell</a>
+ * @version $Revision: 1.1 $
+ */
+
+public interface SessionIdFactory {
+    
+    String create();
+    
+    int getSessionIdLength();
+    
+    // I don't want this here - I favour ctor IOC 
+    // - but TC's Manager i/f makes it awkward not to have it...
+    void setSessionIdLength(int l);    
+    
+}

Added: incubator/wadi/trunk/modules/core/src/main/java/org/codehaus/wadi/SessionManagerFactory.java
URL: http://svn.apache.org/viewcvs/incubator/wadi/trunk/modules/core/src/main/java/org/codehaus/wadi/SessionManagerFactory.java?rev=356933&view=auto
==============================================================================
--- incubator/wadi/trunk/modules/core/src/main/java/org/codehaus/wadi/SessionManagerFactory.java (added)
+++ incubator/wadi/trunk/modules/core/src/main/java/org/codehaus/wadi/SessionManagerFactory.java Wed Dec 14 15:32:56 2005
@@ -0,0 +1,43 @@
+/**
+ *
+ * Copyright 2003-2005 Core Developers Network Ltd.
+ *
+ *  Licensed 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.codehaus.wadi;
+
+import java.net.InetSocketAddress;
+import java.util.Map;
+
+public interface SessionManagerFactory {
+	
+	public abstract Object create(
+			SessionPool sessionPool,
+			AttributesFactory attributesFactory,
+			ValuePool valuePool,
+			SessionWrapperFactory sessionWrapperFactory,
+			SessionIdFactory sessionIdFactory,
+			Contextualiser contextualiser,
+			Map sessionMap,
+			Router router,
+			Streamer streamer,
+			boolean accessOnLoad,
+			String clusterUri,
+			String clusterName,
+			String nodeName,
+			InvocationProxy httpProxy,
+			InetSocketAddress httpAddress,
+			int numPartitions
+			) throws Exception;
+	
+}

Added: incubator/wadi/trunk/modules/core/src/main/java/org/codehaus/wadi/SessionPool.java
URL: http://svn.apache.org/viewcvs/incubator/wadi/trunk/modules/core/src/main/java/org/codehaus/wadi/SessionPool.java?rev=356933&view=auto
==============================================================================
--- incubator/wadi/trunk/modules/core/src/main/java/org/codehaus/wadi/SessionPool.java (added)
+++ incubator/wadi/trunk/modules/core/src/main/java/org/codehaus/wadi/SessionPool.java Wed Dec 14 15:32:56 2005
@@ -0,0 +1,27 @@
+/**
+ *
+ * Copyright 2003-2005 Core Developers Network Ltd.
+ *
+ *  Licensed 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.codehaus.wadi;
+
+public interface SessionPool {
+    
+    void init(SessionConfig config);
+    void destroy();
+    
+    Session take();
+    void put(Session session);
+
+}

Added: incubator/wadi/trunk/modules/core/src/main/java/org/codehaus/wadi/SessionRelocater.java
URL: http://svn.apache.org/viewcvs/incubator/wadi/trunk/modules/core/src/main/java/org/codehaus/wadi/SessionRelocater.java?rev=356933&view=auto
==============================================================================
--- incubator/wadi/trunk/modules/core/src/main/java/org/codehaus/wadi/SessionRelocater.java (added)
+++ incubator/wadi/trunk/modules/core/src/main/java/org/codehaus/wadi/SessionRelocater.java Wed Dec 14 15:32:56 2005
@@ -0,0 +1,28 @@
+/**
+ *
+ * Copyright 2003-2005 Core Developers Network Ltd.
+ *
+ *  Licensed 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.codehaus.wadi;
+
+/**
+ * A relocation strategy that involves relocating the State to the Request.
+ *
+ * @author <a href="mailto:jules@coredevelopers.net">Jules Gosnell</a>
+ * @version $Revision: 1.1 $
+ */
+
+public interface SessionRelocater extends Relocater {
+    // no new methods, just a logical type
+}

Added: incubator/wadi/trunk/modules/core/src/main/java/org/codehaus/wadi/SessionWrapperFactory.java
URL: http://svn.apache.org/viewcvs/incubator/wadi/trunk/modules/core/src/main/java/org/codehaus/wadi/SessionWrapperFactory.java?rev=356933&view=auto
==============================================================================
--- incubator/wadi/trunk/modules/core/src/main/java/org/codehaus/wadi/SessionWrapperFactory.java (added)
+++ incubator/wadi/trunk/modules/core/src/main/java/org/codehaus/wadi/SessionWrapperFactory.java Wed Dec 14 15:32:56 2005
@@ -0,0 +1,25 @@
+/**
+ *
+ * Copyright 2003-2005 Core Developers Network Ltd.
+ *
+ *  Licensed 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.codehaus.wadi;
+
+import javax.servlet.http.HttpSession;
+
+public interface SessionWrapperFactory {
+
+    HttpSession create(Session session);
+    
+}

Added: incubator/wadi/trunk/modules/core/src/main/java/org/codehaus/wadi/Store.java
URL: http://svn.apache.org/viewcvs/incubator/wadi/trunk/modules/core/src/main/java/org/codehaus/wadi/Store.java?rev=356933&view=auto
==============================================================================
--- incubator/wadi/trunk/modules/core/src/main/java/org/codehaus/wadi/Store.java (added)
+++ incubator/wadi/trunk/modules/core/src/main/java/org/codehaus/wadi/Store.java Wed Dec 14 15:32:56 2005
@@ -0,0 +1,31 @@
+/**
+ *
+ * Copyright 2003-2005 Core Developers Network Ltd.
+ *
+ *  Licensed 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.codehaus.wadi;
+
+public interface Store extends StoreMotableConfig {
+    
+    interface Putter {
+        void put(String name, Motable motable);
+    }
+    
+    void clean();
+    String getStartInfo();
+    String getDescription();
+
+    StoreMotable create();
+    void load(Putter putter, boolean accessOnLoad);
+}
\ No newline at end of file

Added: incubator/wadi/trunk/modules/core/src/main/java/org/codehaus/wadi/StoreMotable.java
URL: http://svn.apache.org/viewcvs/incubator/wadi/trunk/modules/core/src/main/java/org/codehaus/wadi/StoreMotable.java?rev=356933&view=auto
==============================================================================
--- incubator/wadi/trunk/modules/core/src/main/java/org/codehaus/wadi/StoreMotable.java (added)
+++ incubator/wadi/trunk/modules/core/src/main/java/org/codehaus/wadi/StoreMotable.java Wed Dec 14 15:32:56 2005
@@ -0,0 +1,25 @@
+/**
+ *
+ * Copyright 2003-2005 Core Developers Network Ltd.
+ *
+ *  Licensed 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.codehaus.wadi;
+
+public interface StoreMotable extends Motable {
+
+    void init(StoreMotableConfig config); // used when we are going to store something...
+  
+    void init(StoreMotableConfig config, String name) throws Exception; // used when we are going to load something...
+ 
+}

Added: incubator/wadi/trunk/modules/core/src/main/java/org/codehaus/wadi/StoreMotableConfig.java
URL: http://svn.apache.org/viewcvs/incubator/wadi/trunk/modules/core/src/main/java/org/codehaus/wadi/StoreMotableConfig.java?rev=356933&view=auto
==============================================================================
--- incubator/wadi/trunk/modules/core/src/main/java/org/codehaus/wadi/StoreMotableConfig.java (added)
+++ incubator/wadi/trunk/modules/core/src/main/java/org/codehaus/wadi/StoreMotableConfig.java Wed Dec 14 15:32:56 2005
@@ -0,0 +1,23 @@
+/**
+ *
+ * Copyright 2003-2005 Core Developers Network Ltd.
+ *
+ *  Licensed 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.codehaus.wadi;
+
+public interface StoreMotableConfig extends Config {
+
+    boolean getUseNIO();
+
+}

Added: incubator/wadi/trunk/modules/core/src/main/java/org/codehaus/wadi/Streamer.java
URL: http://svn.apache.org/viewcvs/incubator/wadi/trunk/modules/core/src/main/java/org/codehaus/wadi/Streamer.java?rev=356933&view=auto
==============================================================================
--- incubator/wadi/trunk/modules/core/src/main/java/org/codehaus/wadi/Streamer.java (added)
+++ incubator/wadi/trunk/modules/core/src/main/java/org/codehaus/wadi/Streamer.java Wed Dec 14 15:32:56 2005
@@ -0,0 +1,45 @@
+/**
+ *
+ * Copyright 2003-2005 Core Developers Network Ltd.
+ *
+ *  Licensed 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.codehaus.wadi;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+import java.io.OutputStream;
+
+/**
+ * Abstract factory. Allows pluggable implementations of various
+ * input/output streaming mechanisms to support e.g. compression,
+ * encryption etc... I'd like to pool these, but the streams apis
+ * don't allow the resetting of the streams that they wrap.
+ *
+ * @author <a href="mailto:jules@coredevelopers.net">Jules Gosnell</a>
+ * @version $Revision: 1.2 $
+ */
+public interface Streamer {
+	
+	void init(StreamerConfig confige);
+	
+	ObjectInput getInputStream(InputStream is) throws IOException;
+	ObjectOutput getOutputStream(OutputStream os) throws IOException;
+	String getSuffix();
+	String getSuffixWithDot();
+	
+}
+

Added: incubator/wadi/trunk/modules/core/src/main/java/org/codehaus/wadi/StreamerConfig.java
URL: http://svn.apache.org/viewcvs/incubator/wadi/trunk/modules/core/src/main/java/org/codehaus/wadi/StreamerConfig.java?rev=356933&view=auto
==============================================================================
--- incubator/wadi/trunk/modules/core/src/main/java/org/codehaus/wadi/StreamerConfig.java (added)
+++ incubator/wadi/trunk/modules/core/src/main/java/org/codehaus/wadi/StreamerConfig.java Wed Dec 14 15:32:56 2005
@@ -0,0 +1,24 @@
+/**
+ *
+ * Copyright 2003-2005 Core Developers Network Ltd.
+ *
+ *  Licensed 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.codehaus.wadi;
+
+public interface StreamerConfig {
+
+	ClassLoader getClassLoader();
+	
+}

Added: incubator/wadi/trunk/modules/core/src/main/java/org/codehaus/wadi/Value.java
URL: http://svn.apache.org/viewcvs/incubator/wadi/trunk/modules/core/src/main/java/org/codehaus/wadi/Value.java?rev=356933&view=auto
==============================================================================
--- incubator/wadi/trunk/modules/core/src/main/java/org/codehaus/wadi/Value.java (added)
+++ incubator/wadi/trunk/modules/core/src/main/java/org/codehaus/wadi/Value.java Wed Dec 14 15:32:56 2005
@@ -0,0 +1,31 @@
+/**
+ *
+ * Copyright 2003-2005 Core Developers Network Ltd.
+ *
+ *  Licensed 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.codehaus.wadi;
+
+/**
+ * TODO - JavaDoc this type
+ *
+ * @author <a href="mailto:jules@coredevelopers.net">Jules Gosnell</a>
+ * @version $Revision: 1.1 $
+ */
+
+public interface Value {
+
+    Object getValue();
+    Object setValue(Object newValue);
+
+}
\ No newline at end of file

Added: incubator/wadi/trunk/modules/core/src/main/java/org/codehaus/wadi/ValueConfig.java
URL: http://svn.apache.org/viewcvs/incubator/wadi/trunk/modules/core/src/main/java/org/codehaus/wadi/ValueConfig.java?rev=356933&view=auto
==============================================================================
--- incubator/wadi/trunk/modules/core/src/main/java/org/codehaus/wadi/ValueConfig.java (added)
+++ incubator/wadi/trunk/modules/core/src/main/java/org/codehaus/wadi/ValueConfig.java Wed Dec 14 15:32:56 2005
@@ -0,0 +1,28 @@
+/**
+ *
+ * Copyright 2003-2005 Core Developers Network Ltd.
+ *
+ *  Licensed 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.codehaus.wadi;
+
+/**
+ * TODO - JavaDoc this type
+ *
+ * @author <a href="mailto:jules@coredevelopers.net">Jules Gosnell</a>
+ * @version $Revision: 1.1 $
+ */
+
+public interface ValueConfig extends Config {
+    // empty
+}
\ No newline at end of file

Added: incubator/wadi/trunk/modules/core/src/main/java/org/codehaus/wadi/ValueFactory.java
URL: http://svn.apache.org/viewcvs/incubator/wadi/trunk/modules/core/src/main/java/org/codehaus/wadi/ValueFactory.java?rev=356933&view=auto
==============================================================================
--- incubator/wadi/trunk/modules/core/src/main/java/org/codehaus/wadi/ValueFactory.java (added)
+++ incubator/wadi/trunk/modules/core/src/main/java/org/codehaus/wadi/ValueFactory.java Wed Dec 14 15:32:56 2005
@@ -0,0 +1,30 @@
+/**
+ *
+ * Copyright 2003-2005 Core Developers Network Ltd.
+ *
+ *  Licensed 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.codehaus.wadi;
+
+/**
+ * TODO - JavaDoc this type
+ *
+ * @author <a href="mailto:jules@coredevelopers.net">Jules Gosnell</a>
+ * @version $Revision: 1.1 $
+ */
+
+public interface ValueFactory {
+
+    public Value create(ValueConfig config);
+    
+}

Added: incubator/wadi/trunk/modules/core/src/main/java/org/codehaus/wadi/ValueHelper.java
URL: http://svn.apache.org/viewcvs/incubator/wadi/trunk/modules/core/src/main/java/org/codehaus/wadi/ValueHelper.java?rev=356933&view=auto
==============================================================================
--- incubator/wadi/trunk/modules/core/src/main/java/org/codehaus/wadi/ValueHelper.java (added)
+++ incubator/wadi/trunk/modules/core/src/main/java/org/codehaus/wadi/ValueHelper.java Wed Dec 14 15:32:56 2005
@@ -0,0 +1,44 @@
+/**
+ *
+ * Copyright 2003-2005 Core Developers Network Ltd.
+ *
+ *  Licensed 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.codehaus.wadi;
+
+import java.io.Serializable;
+
+/**
+ * Help with the [de]serialisation of non-Serializable types. Registered
+ * via AttributeWrapper.registerHelper(Class type, AttributeHelper helper).
+ * See the doc on java.io.Serializable for an explanation of the readResolve()
+ * method.
+ *
+ * @author <a href="mailto:jules@coredevelopers.net">Jules Gosnell</a>
+ * @version $Revision: 1.1 $
+ */
+
+public interface ValueHelper extends Serializable {
+    
+    /**
+     * Used during the writing out of a non-Serializable. If its type matches
+     * a registered Helper, that Helper's replace() method will be used to return
+     * a Serializable Object that implements readResolve() to return an instance
+     * with the same value as the original non-Serializable on deserialisation.
+     * 
+     * @param output - a non-Serializable, which is about to be serialised
+     * @return - a Serializable, which will be serialised in place of the original Object
+     */
+    public Serializable replace(Object output);
+
+}

Added: incubator/wadi/trunk/modules/core/src/main/java/org/codehaus/wadi/ValuePool.java
URL: http://svn.apache.org/viewcvs/incubator/wadi/trunk/modules/core/src/main/java/org/codehaus/wadi/ValuePool.java?rev=356933&view=auto
==============================================================================
--- incubator/wadi/trunk/modules/core/src/main/java/org/codehaus/wadi/ValuePool.java (added)
+++ incubator/wadi/trunk/modules/core/src/main/java/org/codehaus/wadi/ValuePool.java Wed Dec 14 15:32:56 2005
@@ -0,0 +1,31 @@
+/**
+ *
+ * Copyright 2003-2005 Core Developers Network Ltd.
+ *
+ *  Licensed 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.codehaus.wadi;
+
+/**
+ * TODO - JavaDoc this type
+ *
+ * @author <a href="mailto:jules@coredevelopers.net">Jules Gosnell</a>
+ * @version $Revision: 1.1 $
+ */
+
+public interface ValuePool {
+
+    public Value take(ValueConfig config);
+    public void put(Value attribute);
+    
+}

Added: incubator/wadi/trunk/modules/core/src/main/java/org/codehaus/wadi/WADIHttpSession.java
URL: http://svn.apache.org/viewcvs/incubator/wadi/trunk/modules/core/src/main/java/org/codehaus/wadi/WADIHttpSession.java?rev=356933&view=auto
==============================================================================
--- incubator/wadi/trunk/modules/core/src/main/java/org/codehaus/wadi/WADIHttpSession.java (added)
+++ incubator/wadi/trunk/modules/core/src/main/java/org/codehaus/wadi/WADIHttpSession.java Wed Dec 14 15:32:56 2005
@@ -0,0 +1,27 @@
+/**
+ *
+ * Copyright 2003-2005 Core Developers Network Ltd.
+ *
+ *  Licensed 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.codehaus.wadi;
+
+import javax.servlet.http.HttpSession;
+import javax.servlet.http.HttpSessionEvent;
+
+public interface WADIHttpSession extends Session {
+	
+    public HttpSession getWrapper();
+    public HttpSessionEvent getHttpSessionEvent();
+    
+}
\ No newline at end of file

Added: incubator/wadi/trunk/modules/core/src/main/java/org/codehaus/wadi/dindex/CoordinatorConfig.java
URL: http://svn.apache.org/viewcvs/incubator/wadi/trunk/modules/core/src/main/java/org/codehaus/wadi/dindex/CoordinatorConfig.java?rev=356933&view=auto
==============================================================================
--- incubator/wadi/trunk/modules/core/src/main/java/org/codehaus/wadi/dindex/CoordinatorConfig.java (added)
+++ incubator/wadi/trunk/modules/core/src/main/java/org/codehaus/wadi/dindex/CoordinatorConfig.java Wed Dec 14 15:32:56 2005
@@ -0,0 +1,43 @@
+/**
+ *
+ * Copyright 2003-2005 Core Developers Network Ltd.
+ *
+ *  Licensed 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.codehaus.wadi.dindex;
+
+import java.util.Collection;
+import java.util.Map;
+
+import org.activecluster.Cluster;
+import org.activecluster.Node;
+import org.codehaus.wadi.gridstate.Dispatcher;
+
+public interface CoordinatorConfig {
+
+    int getNumPartitions();
+
+    Node getLocalNode();
+    Collection getRemoteNodes();
+    Cluster getCluster();
+    Dispatcher getDispatcher();
+
+    Map getRendezVousMap();
+
+    Collection getLeavers();
+    Collection getLeft();
+
+    long getInactiveTime();
+    void regenerateMissingPartitions(Node[] living, Node[] leaving);
+
+}

Added: incubator/wadi/trunk/modules/core/src/main/java/org/codehaus/wadi/dindex/DIndexMessage.java
URL: http://svn.apache.org/viewcvs/incubator/wadi/trunk/modules/core/src/main/java/org/codehaus/wadi/dindex/DIndexMessage.java?rev=356933&view=auto
==============================================================================
--- incubator/wadi/trunk/modules/core/src/main/java/org/codehaus/wadi/dindex/DIndexMessage.java (added)
+++ incubator/wadi/trunk/modules/core/src/main/java/org/codehaus/wadi/dindex/DIndexMessage.java Wed Dec 14 15:32:56 2005
@@ -0,0 +1,27 @@
+/**
+ *
+ * Copyright 2003-2005 Core Developers Network Ltd.
+ *
+ *  Licensed 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.codehaus.wadi.dindex;
+
+import java.io.Serializable;
+
+import org.codehaus.wadi.OldMessage;
+
+public interface DIndexMessage extends OldMessage, Serializable {
+    
+    // just a marker i/f - at the moment
+    
+}

Added: incubator/wadi/trunk/modules/core/src/main/java/org/codehaus/wadi/dindex/DIndexRequest.java
URL: http://svn.apache.org/viewcvs/incubator/wadi/trunk/modules/core/src/main/java/org/codehaus/wadi/dindex/DIndexRequest.java?rev=356933&view=auto
==============================================================================
--- incubator/wadi/trunk/modules/core/src/main/java/org/codehaus/wadi/dindex/DIndexRequest.java (added)
+++ incubator/wadi/trunk/modules/core/src/main/java/org/codehaus/wadi/dindex/DIndexRequest.java Wed Dec 14 15:32:56 2005
@@ -0,0 +1,24 @@
+/**
+ *
+ * Copyright 2003-2005 Core Developers Network Ltd.
+ *
+ *  Licensed 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.codehaus.wadi.dindex;
+
+public interface DIndexRequest extends DIndexMessage {
+
+    int getPartitionKey(int numPartitions);
+    String getKey();
+
+}

Added: incubator/wadi/trunk/modules/core/src/main/java/org/codehaus/wadi/dindex/DIndexResponse.java
URL: http://svn.apache.org/viewcvs/incubator/wadi/trunk/modules/core/src/main/java/org/codehaus/wadi/dindex/DIndexResponse.java?rev=356933&view=auto
==============================================================================
--- incubator/wadi/trunk/modules/core/src/main/java/org/codehaus/wadi/dindex/DIndexResponse.java (added)
+++ incubator/wadi/trunk/modules/core/src/main/java/org/codehaus/wadi/dindex/DIndexResponse.java Wed Dec 14 15:32:56 2005
@@ -0,0 +1,23 @@
+/**
+ *
+ * Copyright 2003-2005 Core Developers Network Ltd.
+ *
+ *  Licensed 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.codehaus.wadi.dindex;
+
+public interface DIndexResponse extends DIndexMessage {
+    
+    // just a marker i/f - at the moment
+    
+}

Added: incubator/wadi/trunk/modules/core/src/main/java/org/codehaus/wadi/dindex/Partition.java
URL: http://svn.apache.org/viewcvs/incubator/wadi/trunk/modules/core/src/main/java/org/codehaus/wadi/dindex/Partition.java?rev=356933&view=auto
==============================================================================
--- incubator/wadi/trunk/modules/core/src/main/java/org/codehaus/wadi/dindex/Partition.java (added)
+++ incubator/wadi/trunk/modules/core/src/main/java/org/codehaus/wadi/dindex/Partition.java Wed Dec 14 15:32:56 2005
@@ -0,0 +1,38 @@
+/**
+ *
+ * Copyright 2003-2005 Core Developers Network Ltd.
+ *
+ *  Licensed 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.codehaus.wadi.dindex;
+
+import javax.jms.ObjectMessage;
+
+import org.codehaus.wadi.PMPartition;
+import org.codehaus.wadi.dindex.messages.DIndexForwardRequest;
+import org.codehaus.wadi.dindex.messages.DIndexRelocationRequest;
+import org.codehaus.wadi.dindex.newmessages.DeleteIMToPM;
+import org.codehaus.wadi.dindex.newmessages.InsertIMToPM;
+import org.codehaus.wadi.dindex.newmessages.MoveIMToPM;
+
+public interface Partition extends PMPartition, SMPartition {
+
+	void onMessage(ObjectMessage message, InsertIMToPM request);
+	void onMessage(ObjectMessage message, DeleteIMToPM request);
+	void onMessage(ObjectMessage message, DIndexRelocationRequest request);
+	void onMessage(ObjectMessage message, DIndexForwardRequest request);
+	void onMessage(ObjectMessage message, MoveIMToPM request);
+
+	ObjectMessage exchange(DIndexRequest request, long timeout) throws Exception;
+
+}
\ No newline at end of file

Added: incubator/wadi/trunk/modules/core/src/main/java/org/codehaus/wadi/dindex/PartitionConfig.java
URL: http://svn.apache.org/viewcvs/incubator/wadi/trunk/modules/core/src/main/java/org/codehaus/wadi/dindex/PartitionConfig.java?rev=356933&view=auto
==============================================================================
--- incubator/wadi/trunk/modules/core/src/main/java/org/codehaus/wadi/dindex/PartitionConfig.java (added)
+++ incubator/wadi/trunk/modules/core/src/main/java/org/codehaus/wadi/dindex/PartitionConfig.java Wed Dec 14 15:32:56 2005
@@ -0,0 +1,35 @@
+/**
+ *
+ * Copyright 2003-2005 Core Developers Network Ltd.
+ *
+ *  Licensed 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.codehaus.wadi.dindex;
+
+import javax.jms.Destination;
+
+import org.activecluster.Cluster;
+import org.codehaus.wadi.gridstate.Dispatcher;
+import org.codehaus.wadi.gridstate.LockManager;
+
+public interface PartitionConfig {
+
+    Dispatcher getDispatcher();
+    Cluster getCluster();
+    String getNodeName(Destination destination);
+    long getInactiveTime();
+    
+    String getLocalNodeName();
+    LockManager getPMSyncs();
+    
+}

Added: incubator/wadi/trunk/modules/core/src/main/java/org/codehaus/wadi/dindex/PartitionManager.java
URL: http://svn.apache.org/viewcvs/incubator/wadi/trunk/modules/core/src/main/java/org/codehaus/wadi/dindex/PartitionManager.java?rev=356933&view=auto
==============================================================================
--- incubator/wadi/trunk/modules/core/src/main/java/org/codehaus/wadi/dindex/PartitionManager.java (added)
+++ incubator/wadi/trunk/modules/core/src/main/java/org/codehaus/wadi/dindex/PartitionManager.java Wed Dec 14 15:32:56 2005
@@ -0,0 +1,49 @@
+/**
+ *
+ * Copyright 2003-2005 Core Developers Network Ltd.
+ *
+ *  Licensed 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.codehaus.wadi.dindex;
+
+import org.activecluster.Node;
+import org.codehaus.wadi.dindex.impl.PartitionFacade;
+import org.codehaus.wadi.dindex.impl.PartitionKeys;
+
+/**
+ * A PartitionManager is responsible for unambiguously renegotiating Partition ownership every time
+ * that there is a change in Cluster membership and exposing these Partitions to the rest of the program,
+ * whether local or Remote.
+ *
+ * A lot of work needed here...
+ *
+ * @author jules
+ *
+ */
+public interface PartitionManager {
+
+	PartitionFacade getPartition(int partition);
+	PartitionFacade getPartition(Object key);
+	PartitionKeys getPartitionKeys();
+	int getNumPartitions();
+
+	void init(PartitionManagerConfig config);
+	void start() throws Exception;
+	void evacuate() throws Exception;
+	void stop() throws Exception;
+
+	void update(Node node);
+	void regenerateMissingPartitions(Node[] living, Node[] leaving);
+	void localise();
+
+}

Added: incubator/wadi/trunk/modules/core/src/main/java/org/codehaus/wadi/dindex/PartitionManagerConfig.java
URL: http://svn.apache.org/viewcvs/incubator/wadi/trunk/modules/core/src/main/java/org/codehaus/wadi/dindex/PartitionManagerConfig.java?rev=356933&view=auto
==============================================================================
--- incubator/wadi/trunk/modules/core/src/main/java/org/codehaus/wadi/dindex/PartitionManagerConfig.java (added)
+++ incubator/wadi/trunk/modules/core/src/main/java/org/codehaus/wadi/dindex/PartitionManagerConfig.java Wed Dec 14 15:32:56 2005
@@ -0,0 +1,43 @@
+/**
+ *
+ * Copyright 2003-2005 Core Developers Network Ltd.
+ *
+ *  Licensed 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.codehaus.wadi.dindex;
+
+import java.util.Collection;
+
+import javax.jms.Destination;
+
+import org.activecluster.Node;
+import org.codehaus.wadi.Immoter;
+import org.codehaus.wadi.InvocationContext;
+import org.codehaus.wadi.InvocationException;
+import org.codehaus.wadi.Motable;
+
+import EDU.oswego.cs.dl.util.concurrent.Sync;
+
+public interface PartitionManagerConfig {
+
+    void findRelevantSessionNames(int numPartitions, Collection[] resultSet);
+    Node getCoordinatorNode();
+    long getInactiveTime();
+    
+    boolean contextualise(InvocationContext invocationContext, String id, Immoter immoter, Sync motionLock, boolean exclusiveOnly) throws InvocationException;
+    String getNodeName(Destination destination);
+    
+    Immoter getImmoter(String name, Motable immotable);
+    Sync getInvocationLock(String name);
+
+}

Added: incubator/wadi/trunk/modules/core/src/main/java/org/codehaus/wadi/dindex/SMPartition.java
URL: http://svn.apache.org/viewcvs/incubator/wadi/trunk/modules/core/src/main/java/org/codehaus/wadi/dindex/SMPartition.java?rev=356933&view=auto
==============================================================================
--- incubator/wadi/trunk/modules/core/src/main/java/org/codehaus/wadi/dindex/SMPartition.java (added)
+++ incubator/wadi/trunk/modules/core/src/main/java/org/codehaus/wadi/dindex/SMPartition.java Wed Dec 14 15:32:56 2005
@@ -0,0 +1,21 @@
+/**
+ *
+ * Copyright 2003-2005 Core Developers Network Ltd.
+ *
+ *  Licensed 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.codehaus.wadi.dindex;
+
+public interface SMPartition {
+
+}

Added: incubator/wadi/trunk/modules/core/src/main/java/org/codehaus/wadi/dindex/StateManager.java
URL: http://svn.apache.org/viewcvs/incubator/wadi/trunk/modules/core/src/main/java/org/codehaus/wadi/dindex/StateManager.java?rev=356933&view=auto
==============================================================================
--- incubator/wadi/trunk/modules/core/src/main/java/org/codehaus/wadi/dindex/StateManager.java (added)
+++ incubator/wadi/trunk/modules/core/src/main/java/org/codehaus/wadi/dindex/StateManager.java Wed Dec 14 15:32:56 2005
@@ -0,0 +1,38 @@
+/**
+ *
+ * Copyright 2003-2005 Core Developers Network Ltd.
+ *
+ *  Licensed 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.codehaus.wadi.dindex;
+
+import javax.jms.ObjectMessage;
+
+import org.codehaus.wadi.Location;
+import org.codehaus.wadi.Motable;
+
+public interface StateManager {
+	
+	void init(StateManagerConfig config);
+	void start() throws Exception;
+	void stop() throws Exception;
+	
+	interface ImmigrationListener { void onImmigration(ObjectMessage message, Motable immigrant); }
+	
+	boolean offerEmigrant(String key, Motable emotable, long timeout);
+	void acceptImmigrant(ObjectMessage message, Location location, String name, Motable immotable);
+	
+	void setImmigrationListener(ImmigrationListener listener);
+	void unsetImmigrationListener(ImmigrationListener listener);
+	
+}

Added: incubator/wadi/trunk/modules/core/src/main/java/org/codehaus/wadi/dindex/StateManagerConfig.java
URL: http://svn.apache.org/viewcvs/incubator/wadi/trunk/modules/core/src/main/java/org/codehaus/wadi/dindex/StateManagerConfig.java?rev=356933&view=auto
==============================================================================
--- incubator/wadi/trunk/modules/core/src/main/java/org/codehaus/wadi/dindex/StateManagerConfig.java (added)
+++ incubator/wadi/trunk/modules/core/src/main/java/org/codehaus/wadi/dindex/StateManagerConfig.java Wed Dec 14 15:32:56 2005
@@ -0,0 +1,45 @@
+/**
+ *
+ * Copyright 2003-2005 Core Developers Network Ltd.
+ *
+ *  Licensed 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.codehaus.wadi.dindex;
+
+import javax.jms.Destination;
+
+import org.codehaus.wadi.Immoter;
+import org.codehaus.wadi.InvocationContext;
+import org.codehaus.wadi.InvocationException;
+import org.codehaus.wadi.dindex.impl.PartitionFacade;
+import org.codehaus.wadi.gridstate.Dispatcher;
+
+import EDU.oswego.cs.dl.util.concurrent.Sync;
+
+public interface StateManagerConfig {
+
+	PartitionFacade getPartition(int key);
+	PartitionFacade getPartition(Object key);
+	int getNumPartitions();
+	
+	String getLocalNodeName();
+	String getNodeName(Destination destination);
+		
+	Dispatcher getDispatcher();
+    
+    boolean contextualise(InvocationContext invocationContext, String id, Immoter immoter, Sync motionLock, boolean exclusiveOnly) throws InvocationException;
+	long getInactiveTime();
+
+	Sync getInvocationLock(String name);
+	
+}

Added: incubator/wadi/trunk/modules/core/src/main/java/org/codehaus/wadi/dindex/impl/AbstractDIndexRequest.java
URL: http://svn.apache.org/viewcvs/incubator/wadi/trunk/modules/core/src/main/java/org/codehaus/wadi/dindex/impl/AbstractDIndexRequest.java?rev=356933&view=auto
==============================================================================
--- incubator/wadi/trunk/modules/core/src/main/java/org/codehaus/wadi/dindex/impl/AbstractDIndexRequest.java (added)
+++ incubator/wadi/trunk/modules/core/src/main/java/org/codehaus/wadi/dindex/impl/AbstractDIndexRequest.java Wed Dec 14 15:32:56 2005
@@ -0,0 +1,44 @@
+/**
+ *
+ * Copyright 2003-2005 Core Developers Network Ltd.
+ *
+ *  Licensed 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.codehaus.wadi.dindex.impl;
+
+import java.io.Serializable;
+
+import org.codehaus.wadi.dindex.DIndexRequest;
+
+public abstract class AbstractDIndexRequest implements DIndexRequest, Serializable {
+
+    protected String _key;
+
+    public AbstractDIndexRequest(String key) {
+        super();
+        _key=key;
+    }
+
+    protected AbstractDIndexRequest() {
+        // for deserialisation...
+    }
+
+    public String getKey() {
+        return _key;
+    }
+
+    public int getPartitionKey(int numPartitions) {
+        return Math.abs(_key.hashCode()%numPartitions);
+    }
+
+}

Added: incubator/wadi/trunk/modules/core/src/main/java/org/codehaus/wadi/dindex/impl/AbstractPartition.java
URL: http://svn.apache.org/viewcvs/incubator/wadi/trunk/modules/core/src/main/java/org/codehaus/wadi/dindex/impl/AbstractPartition.java?rev=356933&view=auto
==============================================================================
--- incubator/wadi/trunk/modules/core/src/main/java/org/codehaus/wadi/dindex/impl/AbstractPartition.java (added)
+++ incubator/wadi/trunk/modules/core/src/main/java/org/codehaus/wadi/dindex/impl/AbstractPartition.java Wed Dec 14 15:32:56 2005
@@ -0,0 +1,39 @@
+/**
+ *
+ * Copyright 2003-2005 Core Developers Network Ltd.
+ *
+ *  Licensed 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.codehaus.wadi.dindex.impl;
+
+import java.io.Serializable;
+
+import org.codehaus.wadi.dindex.Partition;
+
+public abstract class AbstractPartition implements Partition, Serializable {
+
+    protected int _key;
+
+    public AbstractPartition(int key) {
+        _key=key;
+    }
+
+    protected AbstractPartition() {
+        // for deserialisation...
+    }
+
+    public int getKey() {
+        return _key;
+    }
+
+}

Added: incubator/wadi/trunk/modules/core/src/main/java/org/codehaus/wadi/dindex/impl/Coordinator.java
URL: http://svn.apache.org/viewcvs/incubator/wadi/trunk/modules/core/src/main/java/org/codehaus/wadi/dindex/impl/Coordinator.java?rev=356933&view=auto
==============================================================================
--- incubator/wadi/trunk/modules/core/src/main/java/org/codehaus/wadi/dindex/impl/Coordinator.java (added)
+++ incubator/wadi/trunk/modules/core/src/main/java/org/codehaus/wadi/dindex/impl/Coordinator.java Wed Dec 14 15:32:56 2005
@@ -0,0 +1,288 @@
+/**
+ *
+ * Copyright 2003-2005 Core Developers Network Ltd.
+ *
+ *  Licensed 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.codehaus.wadi.dindex.impl;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.Map;
+
+import javax.jms.Destination;
+
+import org.activecluster.Cluster;
+import org.activecluster.Node;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.codehaus.wadi.dindex.CoordinatorConfig;
+import org.codehaus.wadi.dindex.messages.PartitionEvacuationResponse;
+import org.codehaus.wadi.dindex.messages.PartitionTransferCommand;
+import org.codehaus.wadi.gridstate.Dispatcher;
+import org.codehaus.wadi.impl.Quipu;
+
+import EDU.oswego.cs.dl.util.concurrent.Slot;
+import EDU.oswego.cs.dl.util.concurrent.TimeoutException;
+
+//it's important that the Plan is constructed from snapshotted resources (i.e. the ground doesn't
+//shift under its feet), and that it is made and executed as quickly as possible - as a node could
+//leave the Cluster in the meantime...
+
+public class Coordinator implements Runnable {
+	
+	protected final Log _log=LogFactory.getLog(getClass());
+	
+	protected final Slot _flag=new Slot();
+	
+	protected final CoordinatorConfig _config;
+	protected final Cluster _cluster;
+	protected final Dispatcher _dispatcher;
+	protected final Node _localNode;
+	protected final int _numItems;
+	protected final long _inactiveTime;
+	
+	public Coordinator(CoordinatorConfig config) {
+		_config=config;
+		_cluster=_config.getCluster();
+		_dispatcher=_config.getDispatcher();
+		_localNode=_cluster.getLocalNode();
+		_numItems=_config.getNumPartitions();
+		_inactiveTime=_config.getInactiveTime();
+	}
+	
+	protected Thread _thread;
+	protected Node[] _remoteNodes;
+	
+	
+	public synchronized void start() throws Exception {
+		_log.info("starting...");
+		_thread=new Thread(this, "WADI Coordinator");
+		_thread.start();
+		_log.info("...started");
+	}
+	
+	public synchronized void stop() throws Exception {
+		// somehow wake up thread
+		_log.info("stopping...");
+		_flag.put(Boolean.FALSE);
+		_thread.join();
+		_thread=null;
+		_log.info("...stopped");
+	}
+	
+	public synchronized void queueRebalancing() {
+		_log.trace("queueing rebalancing...");
+		try {
+			_flag.offer(Boolean.TRUE, 0);
+		} catch (InterruptedException e) {
+			_log.warn("unexpected interruption");
+		}
+		_log.trace("...rebalancing queued");
+	}
+	
+	public void run() {
+		try {
+			while (_flag.take()==Boolean.TRUE) {
+				rebalanceClusterState();
+			}
+		} catch (InterruptedException e) {
+			Thread.interrupted();
+			_log.warn("interrupted"); // hmmm.... - TODO
+		}
+	}
+	
+	public void rebalanceClusterState() {
+		int failures=0;
+		try {
+			
+			Map nodeMap=_cluster.getNodes();
+			
+			Collection stayingNodes=nodeMap.values();
+			synchronized (stayingNodes) {stayingNodes=new ArrayList(stayingNodes);} // snapshot
+			stayingNodes.add(_cluster.getLocalNode());
+			
+			Collection l=_config.getLeavers();
+			synchronized (l) {l=new ArrayList(l);} // snapshot
+			
+			Collection leavingNodes=new ArrayList();
+			for (Iterator i=l.iterator(); i.hasNext(); ) {
+				Destination d=(Destination)i.next();
+				Node leaver=getNode(d);
+				if (leaver!=null) {
+					leavingNodes.add(leaver);
+					stayingNodes.remove(leaver);
+				}
+			}
+			
+			_log.trace("--------");
+			_log.trace("STAYING:");
+			
+			printNodes(stayingNodes);
+			_log.trace("LEAVING:");
+			printNodes(leavingNodes);
+			_log.trace("--------");
+			
+			Node [] leaving=(Node[])leavingNodes.toArray(new Node[leavingNodes.size()]);
+			
+			if (stayingNodes.size()==0) {
+				_log.warn("we are the last node - no need to rebalance cluster");
+			} else {
+				
+				Node [] living=(Node[])stayingNodes.toArray(new Node[stayingNodes.size()]);
+				
+				_config.regenerateMissingPartitions(living, leaving);
+				
+				RedistributionPlan plan=new RedistributionPlan(living, leaving, _numItems);
+				
+				_log.trace("--------");
+				_log.trace("BEFORE:");
+				printNodes(living, leaving);
+				_log.trace("--------");
+				
+				Map rvMap=_config.getRendezVousMap();
+				Quipu rv=new Quipu(0);
+				String correlationId=_dispatcher.nextCorrelationId();
+				rvMap.put(correlationId, rv);
+				execute(plan, correlationId, rv); // quipu will be incremented as participants are invited
+				
+				try {
+					_log.trace("WAITING ON RENDEZVOUS");
+					if (rv.waitFor(_inactiveTime)) {
+						_log.trace("RENDEZVOUS SUCCESSFUL");
+						//Collection results=rv.getResults();
+					} else {
+						_log.warn("RENDEZVOUS FAILED");
+						failures++;
+					}
+				} catch (TimeoutException e) {
+					_log.warn("timed out waiting for response", e);
+					failures++;
+				} catch (InterruptedException e) {
+					_log.warn("unexpected interruption", e);
+					failures++;
+				} finally {
+					rvMap.remove(correlationId);
+					// somehow check all returned success.. - TODO
+				}
+				
+				_log.trace("--------");
+				_log.trace("AFTER:");
+				printNodes(living, leaving);
+				_log.trace("--------");
+			}
+			
+			// send EvacuationResponses to each leaving node... - hmmm....
+			Collection left=_config.getLeft();
+			for (int i=0; i<leaving.length; i++) {
+				Node node=leaving[i];
+				if (_log.isTraceEnabled()) _log.trace("sending evacuation response to: "+_dispatcher.getNodeName(node.getDestination()));
+				if (!left.contains(node.getDestination())) {
+					PartitionEvacuationResponse response=new PartitionEvacuationResponse();
+					if (!_dispatcher.reply(_cluster.getLocalNode().getDestination(), node.getDestination(), node.getName(), response)) {
+						if (_log.isErrorEnabled()) _log.error("problem sending EvacuationResponse to "+DIndex.getNodeName(node));
+						failures++;
+					}
+					left.add(node.getDestination());
+				}
+			}
+			
+		} catch (Throwable t) {
+			_log.warn("problem rebalancing indeces", t);
+			failures++;
+		}
+		
+		if (failures>0) {
+			if (_log.isWarnEnabled()) _log.warn("rebalance failed - backing off for "+_inactiveTime+" millis...");
+			queueRebalancing();
+		}
+	}
+	
+	protected void execute(RedistributionPlan plan, String correlationId, Quipu quipu) {
+		quipu.increment(); // add a safety margin of '1', so if we are caught up by acks, waiting thread does not finish until we have
+		Iterator p=plan.getProducers().iterator();
+		Iterator c=plan.getConsumers().iterator();
+		
+		PartitionOwner consumer=null;
+		while (p.hasNext()) {
+			PartitionOwner producer=(PartitionOwner)p.next();
+			Collection transfers=new ArrayList();
+			while (producer._deviation>0) {
+				if (consumer==null)
+					consumer=c.hasNext()?(PartitionOwner)c.next():null;
+					if (null == consumer) {
+						break;
+					}
+					if (producer._deviation>=consumer._deviation) {
+						transfers.add(new PartitionTransfer(consumer._node.getDestination(), DIndex.getNodeName(consumer._node), consumer._deviation));
+						producer._deviation-=consumer._deviation;
+						consumer._deviation=0;
+						consumer=null;
+					} else {
+						transfers.add(new PartitionTransfer(consumer._node.getDestination(), DIndex.getNodeName(consumer._node), producer._deviation));
+						consumer._deviation-=producer._deviation;
+						producer._deviation=0;
+					}
+			}
+			
+			PartitionTransferCommand command=new PartitionTransferCommand((PartitionTransfer[])transfers.toArray(new PartitionTransfer[transfers.size()]));
+			quipu.increment();
+			if (_log.isTraceEnabled()) _log.trace("sending plan to: "+_dispatcher.getNodeName(producer._node.getDestination()));
+			if (!_dispatcher.send(_cluster.getLocalNode().getDestination(), producer._node.getDestination(), correlationId, command)) {
+				_log.error("problem sending transfer command");
+			}
+		}
+		quipu.decrement(); // remove safety margin
+	}
+	
+	protected int printNodes(Collection nodes) {
+		int total=0;
+		for (Iterator i=nodes.iterator(); i.hasNext(); )
+			total+=printNode((Node)i.next());
+		return total;
+	}
+	
+	protected void printNodes(Node[] living, Node[] leaving) {
+		int total=0;
+		for (int i=0; i<living.length; i++)
+			total+=printNode(living[i]);
+		for (int i=0; i<leaving.length; i++)
+			total+=printNode(leaving[i]);
+		if (_log.isTraceEnabled()) _log.trace("TOTAL: " + total);
+	}
+	
+	protected int printNode(Node node) {
+		if (node!=_cluster.getLocalNode())
+			node=(Node)_cluster.getNodes().get(node.getDestination());
+		if (node==null) {
+			if (_log.isTraceEnabled()) _log.trace(DIndex.getNodeName(node) + " : <unknown>");
+			return 0;
+		} else {
+			PartitionKeys keys=DIndex.getPartitionKeys(node);
+			int amount=keys.size();
+			if (_log.isTraceEnabled()) _log.trace(DIndex.getNodeName(node) + " : " + amount + " - " + keys);
+			return amount;
+		}
+	}
+	
+	protected Node getNode(Destination destination) {
+		Node localNode=_cluster.getLocalNode();
+		Destination localDestination=localNode.getDestination();
+		if (destination.equals(localDestination))
+			return localNode;
+		else
+			return (Node)_cluster.getNodes().get(destination);
+	}
+	
+}

Added: incubator/wadi/trunk/modules/core/src/main/java/org/codehaus/wadi/dindex/impl/DIndex.java
URL: http://svn.apache.org/viewcvs/incubator/wadi/trunk/modules/core/src/main/java/org/codehaus/wadi/dindex/impl/DIndex.java?rev=356933&view=auto
==============================================================================
--- incubator/wadi/trunk/modules/core/src/main/java/org/codehaus/wadi/dindex/impl/DIndex.java (added)
+++ incubator/wadi/trunk/modules/core/src/main/java/org/codehaus/wadi/dindex/impl/DIndex.java Wed Dec 14 15:32:56 2005
@@ -0,0 +1,557 @@
+/**
+ *
+ * Copyright 2003-2005 Core Developers Network Ltd.
+ *
+ *  Licensed 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.codehaus.wadi.dindex.impl;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.jms.Destination;
+import javax.jms.JMSException;
+import javax.jms.ObjectMessage;
+
+import org.activecluster.Cluster;
+import org.activecluster.ClusterEvent;
+import org.activecluster.ClusterListener;
+import org.activecluster.Node;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.codehaus.wadi.Emoter;
+import org.codehaus.wadi.Immoter;
+import org.codehaus.wadi.InvocationContext;
+import org.codehaus.wadi.InvocationException;
+import org.codehaus.wadi.Motable;
+import org.codehaus.wadi.dindex.CoordinatorConfig;
+import org.codehaus.wadi.dindex.PartitionManager;
+import org.codehaus.wadi.dindex.PartitionManagerConfig;
+import org.codehaus.wadi.dindex.StateManager;
+import org.codehaus.wadi.dindex.StateManagerConfig;
+import org.codehaus.wadi.dindex.messages.DIndexForwardRequest;
+import org.codehaus.wadi.dindex.messages.DIndexRelocationRequest;
+import org.codehaus.wadi.dindex.messages.RelocationRequest;
+import org.codehaus.wadi.dindex.newmessages.DeleteIMToPM;
+import org.codehaus.wadi.dindex.newmessages.InsertIMToPM;
+import org.codehaus.wadi.dindex.newmessages.InsertPMToIM;
+import org.codehaus.wadi.dindex.newmessages.MoveIMToPM;
+import org.codehaus.wadi.dindex.newmessages.MoveIMToSM;
+import org.codehaus.wadi.dindex.newmessages.MovePMToIM;
+import org.codehaus.wadi.dindex.newmessages.MoveSMToIM;
+import org.codehaus.wadi.gridstate.Dispatcher;
+import org.codehaus.wadi.gridstate.PartitionMapper;
+import org.codehaus.wadi.gridstate.activecluster.ActiveClusterDispatcher;
+import org.codehaus.wadi.impl.AbstractChainedEmoter;
+import org.codehaus.wadi.impl.Quipu;
+import org.codehaus.wadi.impl.SimpleMotable;
+import org.codehaus.wadi.impl.Utils;
+
+import EDU.oswego.cs.dl.util.concurrent.Latch;
+import EDU.oswego.cs.dl.util.concurrent.Sync;
+
+public class DIndex implements ClusterListener, CoordinatorConfig, SimplePartitionManager.Callback, StateManagerConfig {
+
+	protected final static String _nodeNameKey="nodeName";
+	protected final static String _partitionKeysKey="partitionKeys";
+	protected final static String _timeStampKey="timeStamp";
+	protected final static String _birthTimeKey="birthTime";
+	protected final static String _correlationIDMapKey="correlationIDMap";
+
+	protected final Map _distributedState;
+	protected final Latch _coordinatorLatch=new Latch();
+	protected final Object _coordinatorLock=new Object();
+	protected final Dispatcher _dispatcher;
+	protected final Cluster _cluster;
+	protected final String _nodeName;
+	protected final Log _log;
+	protected final long _inactiveTime;
+	protected final PartitionManager _partitionManager;
+	protected final StateManager _stateManager;
+	protected final Log _lockLog=LogFactory.getLog("org.codehaus.wadi.LOCKS");
+
+	public DIndex(String nodeName, int numPartitions, long inactiveTime, Dispatcher dispatcher, Map distributedState, PartitionMapper mapper) {
+		_nodeName=nodeName;
+		_log=LogFactory.getLog(getClass().getName()+"#"+_nodeName);
+		_inactiveTime=inactiveTime;
+		_dispatcher=dispatcher;
+		_cluster=((ActiveClusterDispatcher)_dispatcher).getCluster();
+		_distributedState=distributedState;
+		_partitionManager=new SimplePartitionManager(_dispatcher, numPartitions, _distributedState, this, mapper);
+		_stateManager= new SimpleStateManager(_dispatcher, _inactiveTime);
+	}
+
+	protected Node _coordinatorNode;
+	protected Coordinator _coordinator;
+	protected PartitionManagerConfig _config;
+
+	public void init(PartitionManagerConfig config) {
+		_log.info("init-ing...");
+		_config=config;
+		_cluster.setElectionStrategy(new SeniorityElectionStrategy());
+		_dispatcher.setClusterListener(this);
+		_distributedState.put(_nodeNameKey, _nodeName);
+		_distributedState.put(_correlationIDMapKey, new HashMap());
+		_distributedState.put(_birthTimeKey, new Long(System.currentTimeMillis()));
+		PartitionKeys keys=_partitionManager.getPartitionKeys();
+		_distributedState.put(_partitionKeysKey, keys);
+		_distributedState.put(_timeStampKey, new Long(System.currentTimeMillis()));
+		_partitionManager.init(config);
+		_stateManager.init(this);
+		_log.info("...init-ed");
+	}
+
+	public void start() throws Exception {
+		_log.info("starting...");
+
+		_partitionManager.start();
+
+		_log.info("sleeping...");
+		boolean isNotCoordinator=_coordinatorLatch.attempt(_inactiveTime); // wait to find out if we are the Coordinator
+		_log.info("...waking");
+
+		// If our wait timed out, then we must be the coordinator...
+		if (!isNotCoordinator) {
+			_partitionManager.localise();
+			PartitionKeys k=_partitionManager.getPartitionKeys();
+			_distributedState.put(_partitionKeysKey, k);
+			_distributedState.put(_timeStampKey, new Long(System.currentTimeMillis()));
+			if (_log.isInfoEnabled()) _log.info("local state: " + k);
+			_dispatcher.setDistributedState(_distributedState);
+			if (_log.isTraceEnabled()) _log.trace("distributed state updated: " + _dispatcher.getDistributedState());
+			onCoordinatorChanged(new ClusterEvent(_cluster, _cluster.getLocalNode(), ClusterEvent.ELECTED_COORDINATOR));
+			_coordinator.queueRebalancing();
+		}
+
+		// whether we are the coordinator or not...
+
+		_log.info("...started");
+	}
+
+	public void stop() throws Exception {
+		_log.info("stopping...");
+
+		Thread.interrupted();
+
+		_stateManager.stop();
+
+		if (_coordinator!=null) {
+			_coordinator.stop();
+			_coordinator=null;
+		}
+
+		_partitionManager.stop();
+
+		_log.info("...stopped");
+	}
+
+	public Cluster getCluster() {
+		return _cluster;
+	}
+
+	public Dispatcher getDispatcher() {
+		return _dispatcher;
+	}
+
+	public PartitionManager getPartitionManager() {
+		return _partitionManager;
+	}
+
+	// ClusterListener
+
+	public int getPartition() {
+		// TODO - think about synchronisation...
+		PartitionKeys keys=(PartitionKeys)_distributedState.get(_partitionKeysKey);
+		return keys.getKeys()[Math.abs((int)(Math.random()*keys.size()))];
+	}
+
+	public void onNodeUpdate(ClusterEvent event) {
+		Node node=event.getNode();
+		if (_log.isTraceEnabled()) _log.trace("onNodeUpdate: " + getNodeName(node) + ": " + node.getState());
+
+		_partitionManager.update(node);
+
+		Map state=node.getState();
+		correlateStateUpdate(state);
+	}
+
+	protected void correlateStateUpdate(Map state) {
+		Map correlationIDMap=(Map)state.get(_correlationIDMapKey);
+		Destination local=_dispatcher.getLocalDestination();
+		String correlationID=(String)correlationIDMap.get(local);
+		if (correlationID!=null) {
+			Quipu rv=(Quipu)_dispatcher.getRendezVousMap().get(correlationID);
+			if (rv==null) {
+				if (_log.isWarnEnabled()) _log.warn("no one waiting for: " + correlationID);
+			} else {
+				if (_log.isTraceEnabled()) _log.trace("successful correlation: " + correlationID);
+				rv.putResult(state);
+			}
+		}
+	}
+
+	public void onNodeAdd(ClusterEvent event) {
+		Node node=event.getNode();
+
+		if (_log.isDebugEnabled()) _log.debug("node joined: "+getNodeName(node));
+
+		if (_cluster.getLocalNode()==_coordinatorNode) {
+			_coordinator.queueRebalancing();
+		}
+
+		_partitionManager.update(node);
+	}
+
+	public void onNodeRemoved(ClusterEvent event) {
+		Node node=event.getNode();
+		if (_log.isDebugEnabled()) _log.debug("node left: "+getNodeName(node));
+		_leavers.add(node.getDestination());
+		if (_coordinator!=null)
+			_coordinator.queueRebalancing();
+	}
+
+
+	public boolean amCoordinator() {
+		return _coordinatorNode.getDestination().equals(_dispatcher.getLocalDestination());
+	}
+
+	public void onNodeFailed(ClusterEvent event) {
+		Node node=event.getNode();
+		if (_log.isDebugEnabled()) _log.info("node failed: "+getNodeName(node));
+		if (_leavers.remove(node.getDestination())) {
+			// we have already been explicitly informed of this node's wish to leave...
+			_left.remove(node);
+			if (_log.isTraceEnabled()) _log.trace("onNodeFailed:" + getNodeName(node) + "- already evacuated - ignoring");
+		} else {
+			if (_log.isErrorEnabled()) _log.error("onNodeFailed: " + getNodeName(node));
+			if (amCoordinator()) {
+				if (_log.isErrorEnabled()) _log.error("CATASTROPHIC FAILURE on: " + getNodeName(node));
+				if (_coordinator!=null)
+					_coordinator.queueRebalancing();
+				else
+					_log.warn("coordinator thread not running");
+			}
+		}
+	}
+
+	public void onCoordinatorChanged(ClusterEvent event) {
+		synchronized (_coordinatorLock) {
+			if (_log.isDebugEnabled()) _log.debug("coordinator elected: " + getNodeName(event.getNode()));
+			Node newCoordinator=event.getNode();
+			if (newCoordinator!=_coordinatorNode) {
+				if (_coordinatorNode==_cluster.getLocalNode())
+					onDismissal(event);
+				_coordinatorNode=newCoordinator;
+				if (_coordinatorNode==_cluster.getLocalNode())
+					onElection(event);
+			}
+
+			_coordinatorLatch.release(); // we are still waiting in start() to find out if we are the Coordinator...
+		}
+	}
+
+	public Collection[] createResultSet(int numPartitions, int[] keys) {
+		Collection[] c=new Collection[numPartitions];
+		for (int i=0; i<keys.length; i++)
+			c[keys[i]]=new ArrayList();
+		return c;
+	}
+
+	public void onElection(ClusterEvent event) {
+		_log.info("accepting coordinatorship");
+		try {
+			(_coordinator=new Coordinator(this)).start();
+			_coordinator.queueRebalancing();
+		} catch (Exception e) {
+			_log.error("problem starting Coordinator");
+		}
+	}
+
+	public void onDismissal(ClusterEvent event) {
+		_log.info("resigning coordinatorship"); // never happens - coordinatorship is for life..
+		try {
+			_coordinator.stop();
+			_coordinator=null;
+		} catch (Exception e) {
+			_log.error("problem starting Balancer");
+		}
+	}
+
+
+	public static String getNodeName(Node node) {
+		return node==null?"<unknown>":(String)node.getState().get(_nodeNameKey);
+	}
+
+	public boolean isCoordinator() {
+		synchronized (_coordinatorLock) {
+			return _cluster.getLocalNode()==_coordinatorNode;
+		}
+	}
+
+	public Node getCoordinator() {
+		synchronized (_coordinatorLock) {
+			return _coordinatorNode;
+		}
+	}
+
+	public int getNumPartitions() {
+		return _partitionManager.getNumPartitions();
+	}
+
+	public Node getLocalNode() {
+		return _cluster.getLocalNode();
+	}
+
+	public Collection getRemoteNodes() {
+		return _cluster.getNodes().values();
+	}
+
+	public Map getRendezVousMap() {
+		return _dispatcher.getRendezVousMap();
+	}
+
+	protected final Collection _leavers=Collections.synchronizedCollection(new ArrayList());
+	protected final Collection _left=Collections.synchronizedCollection(new ArrayList());
+
+	public Collection getLeavers() {
+		return _leavers;
+	}
+
+	public Collection getLeft() {
+		return _left;
+	}
+
+	protected int printNode(Node node) {
+		if (node!=_cluster.getLocalNode())
+			node=(Node)_cluster.getNodes().get(node.getDestination());
+		if (node==null) {
+			if (_log.isInfoEnabled()) _log.info(DIndex.getNodeName(node) + " : <unknown> - {?...}");
+			return 0;
+		} else {
+			PartitionKeys keys=DIndex.getPartitionKeys(node);
+			int amount=keys.size();
+			if (_log.isInfoEnabled()) _log.info(DIndex.getNodeName(node) + " : " + amount + " - " + keys);
+			return amount;
+		}
+	}
+	// temporary test methods...
+
+	public boolean insert(String name, long timeout) {
+		try {
+			InsertIMToPM request=new InsertIMToPM(name);
+			PartitionFacade pf=getPartition(name);
+			ObjectMessage reply=pf.exchange(request, timeout);
+			return ((InsertPMToIM)reply.getObject()).getSuccess();
+		} catch (Exception e) {
+			_log.warn("problem inserting session key into DHT", e);
+			return false;
+		}
+	}
+
+	public void remove(String name) {
+		try {
+			DeleteIMToPM request=new DeleteIMToPM(name);
+			getPartition(name).exchange(request, _inactiveTime);
+		} catch (Exception e) {
+			_log.info("oops...", e);
+		}
+	}
+
+	public void relocate(String name) {
+		try {
+			DIndexRelocationRequest request=new DIndexRelocationRequest(name);
+			getPartition(name).exchange(request, _inactiveTime);
+		} catch (Exception e) {
+			_log.info("oops...", e);
+		}
+	}
+
+	public ObjectMessage relocate(String sessionName, String nodeName, int concurrentRequestThreads, boolean shuttingDown, long timeout) throws Exception {
+		ObjectMessage message=_dispatcher.createObjectMessage();
+		message.setJMSReplyTo(_dispatcher.getLocalDestination());
+		RelocationRequest request=new RelocationRequest(sessionName, nodeName, concurrentRequestThreads, shuttingDown);
+		message.setObject(request);
+		//getPartition(sessionName).onMessage(message, request);
+		return forwardAndExchange(sessionName, request, timeout);
+	}
+
+	class SMToIMEmoter extends AbstractChainedEmoter {
+		protected final Log _log=LogFactory.getLog(getClass());
+
+		protected final String _nodeName;
+		protected final ObjectMessage _message;
+
+		protected Sync _invocationLock;
+		protected Sync _stateLock;
+
+		public SMToIMEmoter(String nodeName, ObjectMessage message) {
+			_nodeName=nodeName;
+			_message=message;
+		}
+
+		public boolean prepare(String name, Motable emotable, Motable immotable) {
+			try {
+//				Sync _stateLock=((Context)emotable).getExclusiveLock();
+//				if (_lockLog.isTraceEnabled()) _lockLog.trace("State - (excl.): "+name+ " ["+Thread.currentThread().getName()+"]");
+//				Utils.acquireUninterrupted(_stateLock);
+//				if (_lockLog.isTraceEnabled()) _lockLog.trace("State - (excl.): "+name+ " ["+Thread.currentThread().getName()+"]");
+				immotable.copy(emotable);
+			} catch (Exception e) {
+				_log.warn("oops", e);
+				return false;
+			}
+
+			return true;
+		}
+
+		public void commit(String name, Motable emotable) {
+			try {
+				// respond...
+				MoveIMToSM response=new MoveIMToSM(true);
+				_dispatcher.reply(_message, response);
+
+				emotable.destroy(); // remove copy in store
+//				if (_lockLog.isTraceEnabled()) _lockLog.trace("State (excl.) - releasing: "+name+ " ["+Thread.currentThread().getName()+"]");
+//				_stateLock.release();
+//				if (_lockLog.isTraceEnabled()) _lockLog.trace("State (excl.) - released: "+name+ " ["+Thread.currentThread().getName()+"]");
+
+			} catch (Exception e) {
+				throw new UnsupportedOperationException("NYI"); // NYI
+			}
+		}
+
+		public void rollback(String name, Motable motable) {
+			throw new RuntimeException("NYI");
+		}
+
+		public String getInfo() {
+			return "immigration:"+_nodeName;
+		}
+	}
+
+	public Motable relocate2(String sessionName, String nodeName, int concurrentRequestThreads, boolean shuttingDown, long timeout) throws Exception {
+		MoveIMToPM request=new MoveIMToPM(sessionName, nodeName, concurrentRequestThreads, shuttingDown);
+		ObjectMessage message=getPartition(sessionName).exchange(request, timeout);
+
+		if (message==null) {
+			_log.error("something went wrong - what should we do?"); // TODO
+			return null;
+		}
+
+		try {
+			Serializable dm=(Serializable)message.getObject();
+			// the possibilities...
+			if (dm instanceof MoveSMToIM) {
+				MoveSMToIM req=(MoveSMToIM)dm;
+				// insert motable into contextualiser stack...
+				byte[] bytes=(byte[])req.getValue();
+				if (bytes==null) {
+					_log.warn("failed relocation - 0 bytes arrived: "+sessionName);
+					return null;
+				} else {
+					Motable emotable=new SimpleMotable();
+					emotable.setBodyAsByteArray(bytes);
+					// TOTAL HACK - FIXME
+					emotable.setLastAccessedTime(System.currentTimeMillis());
+					if (!emotable.checkTimeframe(System.currentTimeMillis()))
+						if (_log.isWarnEnabled()) _log.warn("immigrating session has come from the future!: "+emotable.getName());
+
+					Emoter emoter=new SMToIMEmoter(_config.getNodeName(message.getJMSReplyTo()), message);
+					Immoter immoter=_config.getImmoter(sessionName, emotable);
+					Motable immotable=Utils.mote(emoter, immoter, emotable, sessionName);
+					return immotable;
+//					if (null==immotable)
+//					return false;
+//					else {
+//					boolean answer=immoter.contextualise(null, null, null, sessionName, immotable, null);
+//					return answer;
+//					}
+				}
+			} else if (dm instanceof MovePMToIM) {
+				if (_log.isTraceEnabled()) _log.trace("unknown session: "+sessionName);
+				return null;
+			} else {
+				_log.warn("unexpected response returned - what should I do? : "+dm);
+				return null;
+			}
+		} catch (JMSException e) {
+			_log.warn("could not extract message body", e);
+		}
+		return null;
+	}
+
+	public ObjectMessage forwardAndExchange(String name, RelocationRequest request, long timeout) throws Exception {
+		_log.trace("wrapping request");
+		DIndexForwardRequest request2=new DIndexForwardRequest(request);
+		return getPartition(name).exchange(request2, timeout);
+	}
+
+	public PartitionFacade getPartition(Object key) {
+		return _partitionManager.getPartition(key);
+	}
+
+	public String getNodeName(Destination destination) {
+		Node local=_cluster.getLocalNode();
+		Node node=destination.equals(local.getDestination())?local:(Node)_cluster.getNodes().get(destination);
+		return getNodeName(node);
+	}
+
+	public long getInactiveTime() {
+		return _inactiveTime;
+	}
+
+	public void regenerateMissingPartitions(Node[] living, Node[] leaving) {
+		_partitionManager.regenerateMissingPartitions(living, leaving);
+	}
+
+	public static PartitionKeys getPartitionKeys(Node node) {
+		return ((PartitionKeys)node.getState().get(_partitionKeysKey));
+	}
+
+
+	// only for use whilst developing GridState...
+
+//	public PartitionFacade[] getPartitions() {
+//	return _partitions;
+//	}
+
+	// StateManagerConfig API
+
+	public PartitionFacade getPartition(int key) {
+		return _partitionManager.getPartition(key);
+	}
+
+	public StateManager getStateManager() {
+		return _stateManager;
+	}
+
+	// StateManagerConfig API
+
+	public String getLocalNodeName() {
+		return _nodeName;
+	}
+
+	public 	boolean contextualise(InvocationContext invocationContext, String id, Immoter immoter, Sync motionLock, boolean exclusiveOnly) throws InvocationException {
+		return _config.contextualise(invocationContext, id, immoter, motionLock, exclusiveOnly);
+	}
+
+	public Sync getInvocationLock(String name) {
+		return _config.getInvocationLock(name);
+	}
+
+}
+

Added: incubator/wadi/trunk/modules/core/src/main/java/org/codehaus/wadi/dindex/impl/DummyPartition.java
URL: http://svn.apache.org/viewcvs/incubator/wadi/trunk/modules/core/src/main/java/org/codehaus/wadi/dindex/impl/DummyPartition.java?rev=356933&view=auto
==============================================================================
--- incubator/wadi/trunk/modules/core/src/main/java/org/codehaus/wadi/dindex/impl/DummyPartition.java (added)
+++ incubator/wadi/trunk/modules/core/src/main/java/org/codehaus/wadi/dindex/impl/DummyPartition.java Wed Dec 14 15:32:56 2005
@@ -0,0 +1,88 @@
+/**
+ *
+ * Copyright 2003-2005 Core Developers Network Ltd.
+ *
+ *  Licensed 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.codehaus.wadi.dindex.impl;
+
+import javax.jms.ObjectMessage;
+
+import org.codehaus.wadi.dindex.DIndexRequest;
+import org.codehaus.wadi.dindex.messages.DIndexForwardRequest;
+import org.codehaus.wadi.dindex.messages.DIndexRelocationRequest;
+import org.codehaus.wadi.dindex.newmessages.DeleteIMToPM;
+import org.codehaus.wadi.dindex.newmessages.InsertIMToPM;
+import org.codehaus.wadi.dindex.newmessages.MoveIMToPM;
+import org.codehaus.wadi.dindex.newmessages.MovePMToSM;
+
+public class DummyPartition extends AbstractPartition {
+
+    public DummyPartition(int key) {
+        super(key);
+    }
+
+    protected DummyPartition() {
+        super();
+        // for deserialisation...
+        throw new UnsupportedOperationException();
+    }
+
+    public boolean isLocal() {
+        return false;
+    }
+
+	public String toString() {
+        return "<unknown>";
+    }
+
+    public void dispatch(ObjectMessage om, DIndexRequest request) {
+        throw new UnsupportedOperationException();
+    }
+
+	public void onMessage(ObjectMessage message, InsertIMToPM request) {
+		// TODO Auto-generated method stub
+		
+	}
+
+	public void onMessage(ObjectMessage message, DeleteIMToPM request) {
+		// TODO Auto-generated method stub
+		
+	}
+
+	public void onMessage(ObjectMessage message, DIndexRelocationRequest request) {
+		// TODO Auto-generated method stub
+		
+	}
+
+	public void onMessage(ObjectMessage message, DIndexForwardRequest request) {
+		// TODO Auto-generated method stub
+		
+	}
+
+	public void onMessage(ObjectMessage message, MoveIMToPM request) {
+		// TODO Auto-generated method stub
+		
+	}
+
+	public void onMessage(ObjectMessage message, MovePMToSM request) {
+		// TODO Auto-generated method stub
+		
+	}
+
+	public ObjectMessage exchange(DIndexRequest request, long timeout) throws Exception {
+		// TODO Auto-generated method stub
+		return null;
+	}
+
+}