[P2play-commit] SF.net SVN: p2play: [30] trunk/P2Play/src/org/p2play
Status: Pre-Alpha
Brought to you by:
tisoft
|
From: <ti...@us...> - 2007-01-22 14:03:41
|
Revision: 30
http://p2play.svn.sourceforge.net/p2play/?rev=30&view=rev
Author: tisoft
Date: 2007-01-22 06:03:38 -0800 (Mon, 22 Jan 2007)
Log Message:
-----------
renamed package org.p2play.net.region to org.p2play.region
Modified Paths:
--------------
trunk/P2Play/src/org/p2play/scripting/pnuts/PnutsServer.java
trunk/P2Play/src/org/p2play/scripting/pnuts/PnutsServerFactory.java
trunk/P2Play/src/org/p2play/scripting/pnuts/api/region/RegionAPI.java
trunk/P2Play/src/org/p2play/scripting/pnuts/api/region/RegionChangeAPI.java
trunk/P2Play/src/org/p2play/scripting/pnuts/api/region/RegionChangeGameAction.java
trunk/P2Play/src/org/p2play/scripting/pnuts/api/region/RegionDelegate.java
trunk/P2Play/src/org/p2play/scripting/pnuts/object/GameActionClass.java
trunk/P2Play/src/org/p2play/scripting/pnuts/object/GameActionObject.java
trunk/P2Play/src/org/p2play/scripting/pnuts/object/GameDescriptor.java
trunk/P2Play/src/org/p2play/scripting/pnuts/object/GameStateClass.java
trunk/P2Play/src/org/p2play/scripting/pnuts/object/GameStateObject.java
trunk/P2Play/src/org/p2play/scripting/pnuts/object/RegionObject.java
Added Paths:
-----------
trunk/P2Play/src/org/p2play/region/
trunk/P2Play/src/org/p2play/region/Client.java
trunk/P2Play/src/org/p2play/region/GameAction.java
trunk/P2Play/src/org/p2play/region/GameState.java
trunk/P2Play/src/org/p2play/region/Region.java
trunk/P2Play/src/org/p2play/region/RegionInstance.java
trunk/P2Play/src/org/p2play/region/RegionManager.java
trunk/P2Play/src/org/p2play/region/Server.java
trunk/P2Play/src/org/p2play/region/ServerFactory.java
trunk/P2Play/src/org/p2play/region/impl/
trunk/P2Play/src/org/p2play/region/impl/NetworkHandler.java
trunk/P2Play/src/org/p2play/region/impl/RegionScribe.java
trunk/P2Play/src/org/p2play/region/message/
trunk/P2Play/src/org/p2play/region/message/GameActionMessage.java
trunk/P2Play/src/org/p2play/region/message/GameStateHashMessage.java
trunk/P2Play/src/org/p2play/region/message/GameStateMessage.java
trunk/P2Play/src/org/p2play/region/message/JoinMessage.java
trunk/P2Play/src/org/p2play/region/message/MessageDeserializer.java
trunk/P2Play/src/org/p2play/region/message/RegionMessage.java
Removed Paths:
-------------
trunk/P2Play/src/org/p2play/net/
trunk/P2Play/src/org/p2play/region/message/GameActionMessage.java
trunk/P2Play/src/org/p2play/region/message/GameStateHashMessage.java
trunk/P2Play/src/org/p2play/region/message/GameStateMessage.java
trunk/P2Play/src/org/p2play/region/message/JoinMessage.java
trunk/P2Play/src/org/p2play/region/message/MessageDeserializer.java
trunk/P2Play/src/org/p2play/region/message/RegionMessage.java
Copied: trunk/P2Play/src/org/p2play/region/Client.java (from rev 18, trunk/P2Play/src/org/p2play/net/region/Client.java)
===================================================================
--- trunk/P2Play/src/org/p2play/region/Client.java (rev 0)
+++ trunk/P2Play/src/org/p2play/region/Client.java 2007-01-22 14:03:38 UTC (rev 30)
@@ -0,0 +1,35 @@
+/*
+ * Copyright 2006 P2Play.org
+ * All rights reserved.
+ *
+ * This library 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 library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+package org.p2play.region;
+
+/**
+ * A "client" process, that wants to get updated when the game state changes
+ * @author markus
+ *
+ */
+public interface Client {
+ /**
+ * Set the new Game State
+ * The client may now display it
+ * @param gameState the new Game State to set
+ */
+ public void handleGameStateChanged(Region region, GameState gameState);
+
+ public void handleRegionChange(Region oldRegion, Region newRegion, Object gameObject);
+}
Copied: trunk/P2Play/src/org/p2play/region/GameAction.java (from rev 18, trunk/P2Play/src/org/p2play/net/region/GameAction.java)
===================================================================
--- trunk/P2Play/src/org/p2play/region/GameAction.java (rev 0)
+++ trunk/P2Play/src/org/p2play/region/GameAction.java 2007-01-22 14:03:38 UTC (rev 30)
@@ -0,0 +1,33 @@
+/*
+ * Copyright 2006 P2Play.org
+ * All rights reserved.
+ *
+ * This library 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 library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+package org.p2play.region;
+
+import java.io.Serializable;
+
+public interface GameAction extends Serializable{
+ /**
+ * The region we want to change
+ * @return The region we want to change
+ */
+ public Region getRegion();
+
+ public long getGameTime();
+
+ public boolean sendToAll();
+}
Copied: trunk/P2Play/src/org/p2play/region/GameState.java (from rev 18, trunk/P2Play/src/org/p2play/net/region/GameState.java)
===================================================================
--- trunk/P2Play/src/org/p2play/region/GameState.java (rev 0)
+++ trunk/P2Play/src/org/p2play/region/GameState.java 2007-01-22 14:03:38 UTC (rev 30)
@@ -0,0 +1,55 @@
+/*
+ * Copyright 2006 P2Play.org
+ * All rights reserved.
+ *
+ * This library 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 library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+package org.p2play.region;
+
+import java.io.Serializable;
+import java.util.List;
+import java.util.Random;
+
+public interface GameState extends Serializable {
+
+ public abstract Random getRandom();
+
+ /**
+ * The virtual game time this game state is valid for
+ * @return the virtual game time this game state is valid for
+ */
+ public abstract long getGameTime();
+
+ /**
+ * The Region identifier for the region, this game state belongs to
+ * @return the Region identifier for the region, this game state belongs to
+ */
+ public abstract Region getRegion();
+
+ public abstract List<Region> getNeighbourRegions();
+
+ public abstract boolean isIdle();
+
+ public abstract String toString();
+
+ /**
+ * Increase game time by one.
+ *
+ */
+ public abstract void tick();
+
+ public abstract int hash();
+
+}
\ No newline at end of file
Copied: trunk/P2Play/src/org/p2play/region/Region.java (from rev 18, trunk/P2Play/src/org/p2play/net/region/Region.java)
===================================================================
--- trunk/P2Play/src/org/p2play/region/Region.java (rev 0)
+++ trunk/P2Play/src/org/p2play/region/Region.java 2007-01-22 14:03:38 UTC (rev 30)
@@ -0,0 +1,35 @@
+/*
+ * Copyright 2006 P2Play.org
+ * All rights reserved.
+ *
+ * This library 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 library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+package org.p2play.region;
+
+import java.io.Serializable;
+
+public interface Region extends Serializable{
+ /**
+ *
+ * @return The name of the game, that we represent
+ */
+ public String getGame();
+
+ /**
+ *
+ * @return A textual form of our region
+ */
+ public String getRegionIdentifier();
+}
Copied: trunk/P2Play/src/org/p2play/region/RegionInstance.java (from rev 18, trunk/P2Play/src/org/p2play/net/region/RegionInstance.java)
===================================================================
--- trunk/P2Play/src/org/p2play/region/RegionInstance.java (rev 0)
+++ trunk/P2Play/src/org/p2play/region/RegionInstance.java 2007-01-22 14:03:38 UTC (rev 30)
@@ -0,0 +1,54 @@
+/*
+ * Copyright 2006 P2Play.org
+ * All rights reserved.
+ *
+ * This library 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 library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+package org.p2play.region;
+
+import java.io.Serializable;
+
+
+public class RegionInstance implements Serializable{
+ private Region region;
+
+ private int instance;
+
+ public RegionInstance(Region region, int instance) {
+ super();
+ this.region = region;
+ this.instance = instance;
+ }
+
+ public Region getRegion() {
+ return region;
+ }
+
+ public int getInstance() {
+ return instance;
+ }
+
+ @Override
+ public String toString() {
+ return region.getRegionIdentifier() + (instance != 0 ? instance : "");
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ RegionInstance other= ((RegionInstance)obj);
+
+ return other.region.equals(this.region)&&other.instance==this.instance;
+ }
+}
Copied: trunk/P2Play/src/org/p2play/region/RegionManager.java (from rev 18, trunk/P2Play/src/org/p2play/net/region/RegionManager.java)
===================================================================
--- trunk/P2Play/src/org/p2play/region/RegionManager.java (rev 0)
+++ trunk/P2Play/src/org/p2play/region/RegionManager.java 2007-01-22 14:03:38 UTC (rev 30)
@@ -0,0 +1,50 @@
+/*
+ * Copyright 2006 P2Play.org
+ * All rights reserved.
+ *
+ * This library 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 library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+package org.p2play.region;
+
+import org.p2play.region.message.RegionMessage;
+
+public interface RegionManager {
+
+ /**
+ * Called when a client wants to join a specific region
+ * @param region
+ * @param client
+ */
+ public abstract void joinRegion(Region region, Client client);
+
+ /**
+ * Called when a client wants to leave a region
+ * @param region
+ * @param client
+ */
+ public abstract void leaveRegion(Region region, Client client);
+
+ /**
+ * the given request is send over the network to the region controller
+ * @param client
+ * @param interaction
+ */
+ public abstract void scheduleInteraction(Client client,
+ GameAction interaction);
+
+ abstract void handleMessageReceived(RegionMessage message);
+
+
+}
\ No newline at end of file
Copied: trunk/P2Play/src/org/p2play/region/Server.java (from rev 18, trunk/P2Play/src/org/p2play/net/region/Server.java)
===================================================================
--- trunk/P2Play/src/org/p2play/region/Server.java (rev 0)
+++ trunk/P2Play/src/org/p2play/region/Server.java 2007-01-22 14:03:38 UTC (rev 30)
@@ -0,0 +1,59 @@
+/*
+ * Copyright 2006 P2Play.org
+ * All rights reserved.
+ *
+ * This library 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 library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+package org.p2play.region;
+
+import java.util.List;
+
+/**
+ * A "server" process that controlls a region.
+ * @author markus
+ *
+ */
+public interface Server {
+ /**
+ * The Identifier of the Region we controll
+ * @return the Identifier of the Region we controll
+ */
+ public Region getRegion();
+
+ /**
+ * The logical neighbours of this region (e.g. all directly connected regions)
+ * @return the logical neighbours of this region
+ */
+ public List<Region> getNeighbourRegionIdentifiers();
+
+ public GameState init(long gameTime, long randomSeed);
+
+ /**
+ * Returns true, if there are no players in this region
+ * @param gameState
+ * @return
+ */
+ public boolean isEmpty(GameState gameState);
+
+ /**
+ * Ticks the GameState with the Interactions.
+ * The interaction have to be applied to the GameState in the order of occurance in the list
+ * This method should block until all interactions have been applied
+ * interactions may be null, if no requests have to be processed
+ * @param interactions
+ * @return the difference between the old and the new game state
+ */
+ public GameState tick(GameState gameState, List<GameAction> interactions);
+}
Copied: trunk/P2Play/src/org/p2play/region/ServerFactory.java (from rev 18, trunk/P2Play/src/org/p2play/net/region/ServerFactory.java)
===================================================================
--- trunk/P2Play/src/org/p2play/region/ServerFactory.java (rev 0)
+++ trunk/P2Play/src/org/p2play/region/ServerFactory.java 2007-01-22 14:03:38 UTC (rev 30)
@@ -0,0 +1,23 @@
+/*
+ * Copyright 2006 P2Play.org
+ * All rights reserved.
+ *
+ * This library 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 library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+package org.p2play.region;
+
+public interface ServerFactory{
+ public Server getServer(Region region);
+}
\ No newline at end of file
Added: trunk/P2Play/src/org/p2play/region/impl/NetworkHandler.java
===================================================================
--- trunk/P2Play/src/org/p2play/region/impl/NetworkHandler.java (rev 0)
+++ trunk/P2Play/src/org/p2play/region/impl/NetworkHandler.java 2007-01-22 14:03:38 UTC (rev 30)
@@ -0,0 +1,246 @@
+/*
+ * Copyright 2006 P2Play.org
+ * All rights reserved.
+ *
+ * This library 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 library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+package org.p2play.region.impl;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.logging.Level;
+
+import org.p2play.io.Serializer;
+import org.p2play.region.GameAction;
+import org.p2play.region.GameState;
+import org.p2play.region.Region;
+import org.p2play.region.RegionInstance;
+import org.p2play.region.RegionManager;
+import org.p2play.region.message.GameActionMessage;
+import org.p2play.region.message.GameStateHashMessage;
+import org.p2play.region.message.GameStateMessage;
+import org.p2play.region.message.JoinMessage;
+import org.p2play.region.message.MessageDeserializer;
+import org.p2play.region.message.RegionMessage;
+import org.p2play.util.ListMap;
+
+
+import rice.environment.logging.Logger;
+import rice.p2p.commonapi.Application;
+import rice.p2p.commonapi.Endpoint;
+import rice.p2p.commonapi.Id;
+import rice.p2p.commonapi.IdFactory;
+import rice.p2p.commonapi.Message;
+import rice.p2p.commonapi.Node;
+import rice.p2p.commonapi.NodeHandle;
+import rice.p2p.commonapi.RouteMessage;
+import rice.p2p.scribe.Scribe;
+import rice.p2p.scribe.ScribeClient;
+import rice.p2p.scribe.ScribeContent;
+import rice.p2p.scribe.Topic;
+
+public class NetworkHandler implements Application, ScribeClient {
+ private ListMap<Region, RegionInstance> regionInstanceMap;
+
+ private HashMap<RegionInstance, Topic> topicMap;
+
+ private Logger logger;
+
+ private Scribe scribe;
+
+ private IdFactory idFactory;
+
+ private Id nodeId;
+
+ private RegionManager regionManager;
+
+ private Endpoint endpoint;
+
+ private MessageDeserializer messageDeserializer;
+
+ private Serializer serializer;
+
+ public NetworkHandler(Serializer serializer, RegionManager regionManager, final Node node) {
+ this.serializer=serializer;
+ this.regionManager = regionManager;
+ this.regionInstanceMap = new ListMap<Region, RegionInstance>();
+ this.topicMap = new HashMap<RegionInstance, Topic>();
+ this.logger = node.getEnvironment().getLogManager().getLogger(
+ this.getClass(), "");
+ this.nodeId = node.getId();
+ this.idFactory = node.getIdFactory();
+ this.endpoint = node.buildEndpoint(this,
+ "region.controller.application");
+
+ this.endpoint.register();
+
+ messageDeserializer = new MessageDeserializer(this.serializer, this.endpoint);
+ this.endpoint.setDeserializer(messageDeserializer);
+
+ this.scribe = new RegionScribe(node, "region.controller.scribe", this);
+ scribe.setContentDeserializer(messageDeserializer);
+ }
+
+ public MessageDeserializer getMessageDeserializer() {
+ return messageDeserializer;
+ }
+
+ public void joinRegion(Region region, long gameTime) {
+ joinRegion(region, gameTime, 1);
+ }
+
+ public void joinRegion(Region region, long gameTime, int instances) {
+ // subscribe to the other instances
+ for (int i = 0; i < instances; i++) {
+ joinRegion(new RegionInstance(region, i), gameTime);
+ }
+ }
+
+ public void joinRegion(RegionInstance regionInstance, long gameTime) {
+ if (!regionInstanceMap.contains(regionInstance.getRegion(),
+ regionInstance)) {
+ java.util.logging.Logger.global.log(Level.INFO, "Joining "
+ + regionInstance);
+
+ // create topic:
+ regionInstanceMap.add(regionInstance.getRegion(), regionInstance);
+ // subscribe to the group
+ scribe.subscribe(getTopic(regionInstance), this, new JoinMessage(this.serializer,
+ nodeId, regionInstance, gameTime));
+
+ // ping the region controller
+ /*endpoint.route(getTopic(regionInstance).getId(), new JoinMessage(
+ nodeId, regionInstance, gameTime), null);*/
+ }
+ }
+
+ public void leaveRegion(Region region) {
+ System.out.println("*** Leaving: " + region);
+ Iterator<RegionInstance> iterator = regionInstanceMap.iterator(region);
+ while (iterator.hasNext()) {
+ RegionInstance regionInstance = iterator.next();
+ scribe.unsubscribe(getTopic(regionInstance), this);
+ iterator.remove();
+ }
+
+ }
+
+ public void sendGameState(Id id, GameState gameState) {
+ if (gameState != null) {
+ endpoint.route(id, new GameStateMessage(this.serializer,nodeId, gameState,
+ new RegionInstance(gameState.getRegion(), 0)), null);
+ }
+ }
+
+ public void sendGameState(GameState gameState, RegionInstance instance) {
+ if (gameState != null) {
+ scribe.publish(getTopic(instance), new GameStateMessage(this.serializer,nodeId,
+ gameState, instance));
+ }
+ }
+
+ public void sendGameState(GameState gameState) {
+ sendGameState(gameState, new RegionInstance(gameState.getRegion(), 0));
+ }
+
+ // send the hash of the gameState
+ public void sendGameStateHash(GameState gameState, RegionInstance instance) {
+ if (gameState != null) {
+ scribe.publish(getTopic(instance), new GameStateHashMessage(this.serializer, nodeId,
+ gameState, instance));
+ }
+ }
+
+ /**
+ * @param region
+ * @return
+ */
+ public Topic getTopic(RegionInstance regionInstance) {
+ Topic topic = topicMap.get(regionInstance);
+ if (topic == null) {
+ topic = new Topic(idFactory, regionInstance.toString());
+ topicMap.put(regionInstance, topic);
+ }
+ return topic;
+ }
+
+ public void sendInteraction(GameAction changeRequest) {
+ sendExtendedInteraction(changeRequest, -1, 0);
+ }
+
+ public void sendExtendedInteraction(GameAction changeRequest, long ticks,
+ int hash) {
+ synchronized (regionInstanceMap) {
+ Iterator<RegionInstance> topicIterator = regionInstanceMap
+ .iterator(changeRequest.getRegion());
+
+ while (topicIterator.hasNext()) {
+ RegionInstance topic = topicIterator.next();
+
+ if (!changeRequest.sendToAll()) {
+ endpoint.route(getTopic(topic).getId(),
+ new GameActionMessage(this.serializer, nodeId,
+ changeRequest, topic), null);
+ } else {
+ scribe.publish(getTopic(topic),
+ new GameActionMessage(this.serializer,nodeId,
+ changeRequest, topic));
+ }
+ }
+ }
+ }
+
+ public boolean forward(RouteMessage message) {
+ // logger.log("Forwarding message: " + message);
+ return true;
+ }
+
+ public void deliver(Id id, Message message) {
+ // logger.log("Got message: " + message + " from id: " + id);
+ regionManager.handleMessageReceived((RegionMessage) message);
+ }
+
+ public void update(NodeHandle handle, boolean joined) {
+
+ }
+
+ public boolean anycast(Topic topic, ScribeContent content) {
+ return false;
+ }
+
+ public void deliver(Topic topic, ScribeContent content) {
+ // logger.log("Got message: " + content + " in topic: " + topic);
+ regionManager.handleMessageReceived((RegionMessage) content);
+ }
+
+ public void childAdded(Topic topic, NodeHandle child) {
+
+ }
+
+ public void childRemoved(Topic topic, NodeHandle child) {
+
+ }
+
+ public void subscribeFailed(Topic topic) {
+ logger.log("Resubscribing to: " + topic);
+ // recubscribe
+ scribe.subscribe(topic, this);
+ }
+
+ public boolean isRoot(RegionInstance regionInstance) {
+ return scribe.isRoot(getTopic(regionInstance));
+ }
+
+}
\ No newline at end of file
Added: trunk/P2Play/src/org/p2play/region/impl/RegionScribe.java
===================================================================
--- trunk/P2Play/src/org/p2play/region/impl/RegionScribe.java (rev 0)
+++ trunk/P2Play/src/org/p2play/region/impl/RegionScribe.java 2007-01-22 14:03:38 UTC (rev 30)
@@ -0,0 +1,41 @@
+package org.p2play.region.impl;
+
+import java.io.IOException;
+
+
+import rice.p2p.commonapi.Message;
+import rice.p2p.commonapi.Node;
+import rice.p2p.commonapi.RouteMessage;
+import rice.p2p.scribe.ScribeImpl;
+import rice.p2p.scribe.messaging.SubscribeMessage;
+
+public class RegionScribe extends ScribeImpl {
+ private NetworkHandler networkHandler;
+
+ public RegionScribe(Node node, String instance, NetworkHandler networkHandler) {
+ super(node, instance);
+ this.networkHandler=networkHandler;
+ }
+
+ @Override
+ public boolean forward(RouteMessage routeMessage) {
+ boolean forward=super.forward(routeMessage);
+
+ try {
+ Message message=routeMessage.getMessage(endpoint.getDeserializer());
+
+ if (message instanceof SubscribeMessage) {
+ SubscribeMessage subscribeMessage = (SubscribeMessage) message;
+ if(isRoot(subscribeMessage.getTopic())){
+ System.out.println("Root: "+endpoint.getId()+" added "+subscribeMessage.getSource().getId()+" ... "+subscribeMessage.getContent());
+ networkHandler.deliver(endpoint.getId(), (Message) subscribeMessage.getContent());
+ }
+ }
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+ return forward;
+ }
+}
Copied: trunk/P2Play/src/org/p2play/region/message (from rev 18, trunk/P2Play/src/org/p2play/net/region/message)
Deleted: trunk/P2Play/src/org/p2play/region/message/GameActionMessage.java
===================================================================
--- trunk/P2Play/src/org/p2play/net/region/message/GameActionMessage.java 2007-01-16 13:11:11 UTC (rev 18)
+++ trunk/P2Play/src/org/p2play/region/message/GameActionMessage.java 2007-01-22 14:03:38 UTC (rev 30)
@@ -1,58 +0,0 @@
-/*
- * Copyright 2006 P2Play.org
- * All rights reserved.
- *
- * This library 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 library 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 library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
- */
-package org.p2play.net.region.message;
-
-import java.io.IOException;
-
-import org.p2play.io.Serializer;
-import org.p2play.net.region.GameAction;
-import org.p2play.net.region.RegionInstance;
-
-import rice.p2p.commonapi.Endpoint;
-import rice.p2p.commonapi.Id;
-import rice.p2p.commonapi.rawserialization.InputBuffer;
-import rice.p2p.commonapi.rawserialization.OutputBuffer;
-
-public class GameActionMessage extends RegionMessage {
- private GameAction gameAction;
-
-
- public GameActionMessage(Serializer serializer, Id sender, GameAction interaction, RegionInstance regionInstance) {
- super(serializer, sender, regionInstance);
- this.gameAction = interaction;
- }
-
- GameActionMessage(Serializer serializer, InputBuffer buf, Endpoint endpoint) throws IOException {
- super(serializer, buf, endpoint);
- gameAction=(GameAction) serializer.deserialize(buf);
- }
-
- public GameAction getGameAction() {
- return gameAction;
- }
-
- public short getType() {
- return GAMEACTION_MESSAGE;
- }
-
- @Override
- public void doSerialize(OutputBuffer buf) throws IOException {
- getSerializer().serialize(gameAction, buf);
- }
-}
\ No newline at end of file
Copied: trunk/P2Play/src/org/p2play/region/message/GameActionMessage.java (from rev 26, trunk/P2Play/src/org/p2play/net/region/message/GameActionMessage.java)
===================================================================
--- trunk/P2Play/src/org/p2play/region/message/GameActionMessage.java (rev 0)
+++ trunk/P2Play/src/org/p2play/region/message/GameActionMessage.java 2007-01-22 14:03:38 UTC (rev 30)
@@ -0,0 +1,58 @@
+/*
+ * Copyright 2006 P2Play.org
+ * All rights reserved.
+ *
+ * This library 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 library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+package org.p2play.region.message;
+
+import java.io.IOException;
+
+import org.p2play.io.Serializer;
+import org.p2play.region.GameAction;
+import org.p2play.region.RegionInstance;
+
+import rice.p2p.commonapi.Endpoint;
+import rice.p2p.commonapi.Id;
+import rice.p2p.commonapi.rawserialization.InputBuffer;
+import rice.p2p.commonapi.rawserialization.OutputBuffer;
+
+public class GameActionMessage extends RegionMessage {
+ private GameAction gameAction;
+
+
+ public GameActionMessage(Serializer serializer, Id sender, GameAction interaction, RegionInstance regionInstance) {
+ super(serializer, sender, regionInstance);
+ this.gameAction = interaction;
+ }
+
+ GameActionMessage(Serializer serializer, InputBuffer buf, Endpoint endpoint) throws IOException {
+ super(serializer, buf, endpoint);
+ gameAction=(GameAction) serializer.deserialize(buf);
+ }
+
+ public GameAction getGameAction() {
+ return gameAction;
+ }
+
+ public short getType() {
+ return GAMEACTION_MESSAGE;
+ }
+
+ @Override
+ public void doSerialize(OutputBuffer buf) throws IOException {
+ getSerializer().serialize(gameAction, buf);
+ }
+}
\ No newline at end of file
Deleted: trunk/P2Play/src/org/p2play/region/message/GameStateHashMessage.java
===================================================================
--- trunk/P2Play/src/org/p2play/net/region/message/GameStateHashMessage.java 2007-01-16 13:11:11 UTC (rev 18)
+++ trunk/P2Play/src/org/p2play/region/message/GameStateHashMessage.java 2007-01-22 14:03:38 UTC (rev 30)
@@ -1,71 +0,0 @@
-/*
- * Copyright 2006 P2Play.org
- * All rights reserved.
- *
- * This library 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 library 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 library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
- */
-package org.p2play.net.region.message;
-
-import java.io.IOException;
-
-import org.p2play.io.Serializer;
-import org.p2play.net.region.GameState;
-import org.p2play.net.region.RegionInstance;
-
-import rice.p2p.commonapi.Endpoint;
-import rice.p2p.commonapi.Id;
-import rice.p2p.commonapi.rawserialization.InputBuffer;
-import rice.p2p.commonapi.rawserialization.OutputBuffer;
-
-public class GameStateHashMessage extends RegionMessage {
-
- private int hash;
- private long tick;
-
- public GameStateHashMessage(Serializer serializer, Id sender, GameState gameState, RegionInstance instance)
- {
- super(serializer, sender,instance);
- this.hash=gameState.hash();
- this.tick=gameState.getGameTime();
- }
-
- GameStateHashMessage(Serializer serializer, InputBuffer buf, Endpoint endpoint) throws IOException {
- super(serializer, buf, endpoint);
- this.hash=buf.readInt();
- this.tick=buf.readLong();
- }
-
- @Override
- public void doSerialize(OutputBuffer buf) throws IOException {
- buf.writeInt(this.hash);
- buf.writeLong(this.tick);
- }
-
- public int getHash()
- {
- return this.hash;
- }
-
- public long getTick()
- {
- return this.tick;
- }
-
- public short getType() {
- return GAME_STATE_HASH_MESSAGE ;
- }
-
-
-}
Copied: trunk/P2Play/src/org/p2play/region/message/GameStateHashMessage.java (from rev 26, trunk/P2Play/src/org/p2play/net/region/message/GameStateHashMessage.java)
===================================================================
--- trunk/P2Play/src/org/p2play/region/message/GameStateHashMessage.java (rev 0)
+++ trunk/P2Play/src/org/p2play/region/message/GameStateHashMessage.java 2007-01-22 14:03:38 UTC (rev 30)
@@ -0,0 +1,71 @@
+/*
+ * Copyright 2006 P2Play.org
+ * All rights reserved.
+ *
+ * This library 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 library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+package org.p2play.region.message;
+
+import java.io.IOException;
+
+import org.p2play.io.Serializer;
+import org.p2play.region.GameState;
+import org.p2play.region.RegionInstance;
+
+import rice.p2p.commonapi.Endpoint;
+import rice.p2p.commonapi.Id;
+import rice.p2p.commonapi.rawserialization.InputBuffer;
+import rice.p2p.commonapi.rawserialization.OutputBuffer;
+
+public class GameStateHashMessage extends RegionMessage {
+
+ private int hash;
+ private long tick;
+
+ public GameStateHashMessage(Serializer serializer, Id sender, GameState gameState, RegionInstance instance)
+ {
+ super(serializer, sender,instance);
+ this.hash=gameState.hash();
+ this.tick=gameState.getGameTime();
+ }
+
+ GameStateHashMessage(Serializer serializer, InputBuffer buf, Endpoint endpoint) throws IOException {
+ super(serializer, buf, endpoint);
+ this.hash=buf.readInt();
+ this.tick=buf.readLong();
+ }
+
+ @Override
+ public void doSerialize(OutputBuffer buf) throws IOException {
+ buf.writeInt(this.hash);
+ buf.writeLong(this.tick);
+ }
+
+ public int getHash()
+ {
+ return this.hash;
+ }
+
+ public long getTick()
+ {
+ return this.tick;
+ }
+
+ public short getType() {
+ return GAME_STATE_HASH_MESSAGE ;
+ }
+
+
+}
Deleted: trunk/P2Play/src/org/p2play/region/message/GameStateMessage.java
===================================================================
--- trunk/P2Play/src/org/p2play/net/region/message/GameStateMessage.java 2007-01-16 13:11:11 UTC (rev 18)
+++ trunk/P2Play/src/org/p2play/region/message/GameStateMessage.java 2007-01-22 14:03:38 UTC (rev 30)
@@ -1,58 +0,0 @@
-/*
- * Copyright 2006 P2Play.org
- * All rights reserved.
- *
- * This library 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 library 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 library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
- */
-package org.p2play.net.region.message;
-
-import java.io.IOException;
-
-import org.p2play.io.Serializer;
-import org.p2play.net.region.GameState;
-import org.p2play.net.region.RegionInstance;
-
-import rice.p2p.commonapi.Endpoint;
-import rice.p2p.commonapi.Id;
-import rice.p2p.commonapi.rawserialization.InputBuffer;
-import rice.p2p.commonapi.rawserialization.OutputBuffer;
-
-public class GameStateMessage extends RegionMessage {
- private GameState gameState;
-
- public GameStateMessage(Serializer serializer, Id sender, GameState gameState,
- RegionInstance instance) {
- super(serializer, sender, instance);
- this.gameState = gameState;
- }
-
- GameStateMessage(Serializer serializer, InputBuffer buf, Endpoint endpoint) throws IOException {
- super(serializer, buf, endpoint);
- this.gameState = (GameState) serializer.deserialize(buf);
- }
-
- public GameState getGameState() {
- return gameState;
- }
-
- public short getType() {
- return GAMESTATE_MESSAGE;
- }
-
- @Override
- public void doSerialize(OutputBuffer buf) throws IOException {
- getSerializer().serialize(gameState, buf);
- }
-}
\ No newline at end of file
Copied: trunk/P2Play/src/org/p2play/region/message/GameStateMessage.java (from rev 26, trunk/P2Play/src/org/p2play/net/region/message/GameStateMessage.java)
===================================================================
--- trunk/P2Play/src/org/p2play/region/message/GameStateMessage.java (rev 0)
+++ trunk/P2Play/src/org/p2play/region/message/GameStateMessage.java 2007-01-22 14:03:38 UTC (rev 30)
@@ -0,0 +1,58 @@
+/*
+ * Copyright 2006 P2Play.org
+ * All rights reserved.
+ *
+ * This library 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 library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+package org.p2play.region.message;
+
+import java.io.IOException;
+
+import org.p2play.io.Serializer;
+import org.p2play.region.GameState;
+import org.p2play.region.RegionInstance;
+
+import rice.p2p.commonapi.Endpoint;
+import rice.p2p.commonapi.Id;
+import rice.p2p.commonapi.rawserialization.InputBuffer;
+import rice.p2p.commonapi.rawserialization.OutputBuffer;
+
+public class GameStateMessage extends RegionMessage {
+ private GameState gameState;
+
+ public GameStateMessage(Serializer serializer, Id sender, GameState gameState,
+ RegionInstance instance) {
+ super(serializer, sender, instance);
+ this.gameState = gameState;
+ }
+
+ GameStateMessage(Serializer serializer, InputBuffer buf, Endpoint endpoint) throws IOException {
+ super(serializer, buf, endpoint);
+ this.gameState = (GameState) serializer.deserialize(buf);
+ }
+
+ public GameState getGameState() {
+ return gameState;
+ }
+
+ public short getType() {
+ return GAMESTATE_MESSAGE;
+ }
+
+ @Override
+ public void doSerialize(OutputBuffer buf) throws IOException {
+ getSerializer().serialize(gameState, buf);
+ }
+}
\ No newline at end of file
Deleted: trunk/P2Play/src/org/p2play/region/message/JoinMessage.java
===================================================================
--- trunk/P2Play/src/org/p2play/net/region/message/JoinMessage.java 2007-01-16 13:11:11 UTC (rev 18)
+++ trunk/P2Play/src/org/p2play/region/message/JoinMessage.java 2007-01-22 14:03:38 UTC (rev 30)
@@ -1,57 +0,0 @@
-/*
- * Copyright 2006 P2Play.org
- * All rights reserved.
- *
- * This library 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 library 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 library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
- */
-package org.p2play.net.region.message;
-
-import java.io.IOException;
-
-import org.p2play.io.Serializer;
-import org.p2play.net.region.RegionInstance;
-
-
-import rice.p2p.commonapi.Endpoint;
-import rice.p2p.commonapi.Id;
-import rice.p2p.commonapi.rawserialization.InputBuffer;
-import rice.p2p.commonapi.rawserialization.OutputBuffer;
-
-public class JoinMessage extends RegionMessage {
- private long gameTime;
-
- public JoinMessage(Serializer serializer, Id sender, RegionInstance regionInstance, long gameTime) {
- super(serializer, sender, regionInstance);
- this.gameTime = gameTime;
- }
-
- JoinMessage(Serializer serializer, InputBuffer buf, Endpoint endpoint) throws IOException {
- super(serializer, buf, endpoint);
- gameTime=buf.readLong();
- }
-
- public long getGameTime() {
- return gameTime;
- }
-
- public short getType() {
- return JOIN_MESSAGE;
- }
-
- @Override
- public void doSerialize(OutputBuffer buf) throws IOException {
- buf.writeLong(gameTime);
- }
-}
\ No newline at end of file
Copied: trunk/P2Play/src/org/p2play/region/message/JoinMessage.java (from rev 26, trunk/P2Play/src/org/p2play/net/region/message/JoinMessage.java)
===================================================================
--- trunk/P2Play/src/org/p2play/region/message/JoinMessage.java (rev 0)
+++ trunk/P2Play/src/org/p2play/region/message/JoinMessage.java 2007-01-22 14:03:38 UTC (rev 30)
@@ -0,0 +1,57 @@
+/*
+ * Copyright 2006 P2Play.org
+ * All rights reserved.
+ *
+ * This library 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 library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+package org.p2play.region.message;
+
+import java.io.IOException;
+
+import org.p2play.io.Serializer;
+import org.p2play.region.RegionInstance;
+
+
+import rice.p2p.commonapi.Endpoint;
+import rice.p2p.commonapi.Id;
+import rice.p2p.commonapi.rawserialization.InputBuffer;
+import rice.p2p.commonapi.rawserialization.OutputBuffer;
+
+public class JoinMessage extends RegionMessage {
+ private long gameTime;
+
+ public JoinMessage(Serializer serializer, Id sender, RegionInstance regionInstance, long gameTime) {
+ super(serializer, sender, regionInstance);
+ this.gameTime = gameTime;
+ }
+
+ JoinMessage(Serializer serializer, InputBuffer buf, Endpoint endpoint) throws IOException {
+ super(serializer, buf, endpoint);
+ gameTime=buf.readLong();
+ }
+
+ public long getGameTime() {
+ return gameTime;
+ }
+
+ public short getType() {
+ return JOIN_MESSAGE;
+ }
+
+ @Override
+ public void doSerialize(OutputBuffer buf) throws IOException {
+ buf.writeLong(gameTime);
+ }
+}
\ No newline at end of file
Deleted: trunk/P2Play/src/org/p2play/region/message/MessageDeserializer.java
===================================================================
--- trunk/P2Play/src/org/p2play/net/region/message/MessageDeserializer.java 2007-01-16 13:11:11 UTC (rev 18)
+++ trunk/P2Play/src/org/p2play/region/message/MessageDeserializer.java 2007-01-22 14:03:38 UTC (rev 30)
@@ -1,66 +0,0 @@
-/*
- * Copyright 2006 P2Play.org
- * All rights reserved.
- *
- * This library 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 library 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 library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
- */
-package org.p2play.net.region.message;
-
-import java.io.IOException;
-
-import org.p2play.io.Serializer;
-
-import rice.p2p.commonapi.Endpoint;
-import rice.p2p.commonapi.Message;
-import rice.p2p.commonapi.NodeHandle;
-import rice.p2p.commonapi.rawserialization.InputBuffer;
-import rice.p2p.scribe.ScribeContent;
-import rice.p2p.scribe.rawserialization.ScribeContentDeserializer;
-
-public class MessageDeserializer implements
- rice.p2p.commonapi.rawserialization.MessageDeserializer, ScribeContentDeserializer {
- private Endpoint endpoint;
- private Serializer serializer;
-
- public MessageDeserializer(Serializer serializer, Endpoint endpoint) {
- super();
- this.serializer=serializer;
- this.endpoint = endpoint;
- }
-
- public Message deserialize(InputBuffer buf, short type, int priority,
- NodeHandle sender) throws IOException {
- return (Message)deserialize(buf, endpoint, type);
- }
-
- public ScribeContent deserializeScribeContent(InputBuffer buf, Endpoint endpoint, short contentType) throws IOException {
- return (ScribeContent)deserialize(buf, endpoint, contentType);
- }
-
- private Object deserialize(InputBuffer buf, Endpoint endpoint,short type) throws IOException{
- switch (type) {
- case RegionMessage.JOIN_MESSAGE:
- return new JoinMessage(serializer, buf,endpoint);
- case RegionMessage.GAMESTATE_MESSAGE:
- return new GameStateMessage(serializer, buf,endpoint);
- case RegionMessage.GAMEACTION_MESSAGE:
- return new GameActionMessage(serializer, buf,endpoint);
- case RegionMessage.GAME_STATE_HASH_MESSAGE:
- return new GameStateHashMessage(serializer, buf,endpoint);
- }
- System.out.println("Found unknown message: "+type);
- return null;
- }
-}
Copied: trunk/P2Play/src/org/p2play/region/message/MessageDeserializer.java (from rev 26, trunk/P2Play/src/org/p2play/net/region/message/MessageDeserializer.java)
===================================================================
--- trunk/P2Play/src/org/p2play/region/message/MessageDeserializer.java (rev 0)
+++ trunk/P2Play/src/org/p2play/region/message/MessageDeserializer.java 2007-01-22 14:03:38 UTC (rev 30)
@@ -0,0 +1,66 @@
+/*
+ * Copyright 2006 P2Play.org
+ * All rights reserved.
+ *
+ * This library 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 library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+package org.p2play.region.message;
+
+import java.io.IOException;
+
+import org.p2play.io.Serializer;
+
+import rice.p2p.commonapi.Endpoint;
+import rice.p2p.commonapi.Message;
+import rice.p2p.commonapi.NodeHandle;
+import rice.p2p.commonapi.rawserialization.InputBuffer;
+import rice.p2p.scribe.ScribeContent;
+import rice.p2p.scribe.rawserialization.ScribeContentDeserializer;
+
+public class MessageDeserializer implements
+ rice.p2p.commonapi.rawserialization.MessageDeserializer, ScribeContentDeserializer {
+ private Endpoint endpoint;
+ private Serializer serializer;
+
+ public MessageDeserializer(Serializer serializer, Endpoint endpoint) {
+ super();
+ this.serializer=serializer;
+ this.endpoint = endpoint;
+ }
+
+ public Message deserialize(InputBuffer buf, short type, int priority,
+ NodeHandle sender) throws IOException {
+ return (Message)deserialize(buf, endpoint, type);
+ }
+
+ public ScribeContent deserializeScribeContent(InputBuffer buf, Endpoint endpoint, short contentType) throws IOException {
+ return (ScribeContent)deserialize(buf, endpoint, contentType);
+ }
+
+ private Object deserialize(InputBuffer buf, Endpoint endpoint,short type) throws IOException{
+ switch (type) {
+ case RegionMessage.JOIN_MESSAGE:
+ return new JoinMessage(serializer, buf,endpoint);
+ case RegionMessage.GAMESTATE_MESSAGE:
+ return new GameStateMessage(serializer, buf,endpoint);
+ case RegionMessage.GAMEACTION_MESSAGE:
+ return new GameActionMessage(serializer, buf,endpoint);
+ case RegionMessage.GAME_STATE_HASH_MESSAGE:
+ return new GameStateHashMessage(serializer, buf,endpoint);
+ }
+ System.out.println("Found unknown message: "+type);
+ return null;
+ }
+}
Deleted: trunk/P2Play/src/org/p2play/region/message/RegionMessage.java
===================================================================
--- trunk/P2Play/src/org/p2play/net/region/message/RegionMessage.java 2007-01-16 13:11:11 UTC (rev 18)
+++ trunk/P2Play/src/org/p2play/region/message/RegionMessage.java 2007-01-22 14:03:38 UTC (rev 30)
@@ -1,98 +0,0 @@
-/*
- * Copyright 2006 P2Play.org
- * All rights reserved.
- *
- * This library 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 library 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 library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
- */
-package org.p2play.net.region.message;
-
-import java.io.IOException;
-
-import org.p2play.io.Serializer;
-import org.p2play.net.region.Region;
-import org.p2play.net.region.RegionInstance;
-
-import rice.p2p.commonapi.Endpoint;
-import rice.p2p.commonapi.Id;
-import rice.p2p.commonapi.rawserialization.InputBuffer;
-import rice.p2p.commonapi.rawserialization.OutputBuffer;
-import rice.p2p.commonapi.rawserialization.RawMessage;
-import rice.p2p.scribe.rawserialization.RawScribeContent;
-
-public abstract class RegionMessage implements RawMessage, RawScribeContent {
- public static final short GAMESTATE_MESSAGE = 100;
-
- public static final short JOIN_MESSAGE = 200;
-
- public static final short GAMEACTION_MESSAGE = 300;
-
- public static final short GAME_STATE_HASH_MESSAGE = 400;
-
- private RegionInstance regionInstance;
-
- private Id sender;
-
- private Serializer serializer;
-
- public RegionMessage(Serializer serializer, Id sender, RegionInstance regionInstance) {
- super();
- this.serializer = serializer;
- this.sender = sender;
- this.regionInstance = regionInstance;
- }
-
- protected RegionMessage(Serializer serializer, InputBuffer buf, Endpoint endpoint)
- throws IOException {
- this.serializer=serializer;
- sender = endpoint.readId(buf, buf.readShort());
- regionInstance=new RegionInstance((Region)serializer.deserialize(buf),buf.readInt());
- }
-
- public final Id getSender() {
- return sender;
- }
-
- public int getPriority() {
- return 0;
- }
-
- public Region getRegion() {
- return regionInstance.getRegion();
- }
-
- public RegionInstance getRegionInstance() {
- return regionInstance;
- }
-
- public void setRegionInstance(RegionInstance regionInstance) {
- this.regionInstance = regionInstance;
- }
-
- public final void serialize(OutputBuffer buf) throws IOException {
- buf.writeShort(sender.getType());
- sender.serialize(buf);
-
- serializer.serialize(regionInstance.getRegion(), buf);
- buf.writeInt(regionInstance.getInstance());
-
- doSerialize(buf);
- }
-
- public abstract void doSerialize(OutputBuffer buf) throws IOException;
-
- protected final Serializer getSerializer() {
- return serializer;
- }
-}
\ No newline at end of file
Copied: trunk/P2Play/src/org/p2play/region/message/RegionMessage.java (from rev 26, trunk/P2Play/src/org/p2play/net/region/message/RegionMessage.java)
===================================================================
--- trunk/P2Play/src/org/p2play/region/message/RegionMessage.java (rev 0)
+++ trunk/P2Play/src/org/p2play/region/message/RegionMessage.java 2007-01-22 14:03:38 UTC (rev 30)
@@ -0,0 +1,98 @@
+/*
+ * Copyright 2006 P2Play.org
+ * All rights reserved.
+ *
+ * This library 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 library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+package org.p2play.region.message;
+
+import java.io.IOException;
+
+import org.p2play.io.Serializer;
+import org.p2play.region.Region;
+import org.p2play.region.RegionInstance;
+
+import rice.p2p.commonapi.Endpoint;
+import rice.p2p.commonapi.Id;
+import rice.p2p.commonapi.rawserialization.InputBuffer;
+import rice.p2p.commonapi.rawserialization.OutputBuffer;
+import rice.p2p.commonapi.rawserialization.RawMessage;
+import rice.p2p.scribe.rawserialization.RawScribeContent;
+
+public abstract class RegionMessage implements RawMessage, RawScribeContent {
+ public static final short GAMESTATE_MESSAGE = 100;
+
+ public static final short JOIN_MESSAGE = 200;
+
+ public static final short GAMEACTION_MESSAGE = 300;
+
+ public static final short GAME_STATE_HASH_MESSAGE = 400;
+
+ private RegionInstance regionInstance;
+
+ private Id sender;
+
+ private Serializer serializer;
+
+ public RegionMessage(Serializer serializer, Id sender, RegionInstance regionInstance) {
+ super();
+ this.serializer = serializer;
+ this.sender = sender;
+ this.regionInstance = regionInstance;
+ }
+
+ protected RegionMessage(Serializer serializer, InputBuffer buf, Endpoint endpoint)
+ throws IOException {
+ this.serializer=serializer;
+ sender = endpoint.readId(buf, buf.readShort());
+ regionInstance=new RegionInstance((Region)serializer.deserialize(buf),buf.readInt());
+ }
+
+ public final Id getSender() {
+ return sender;
+ }
+
+ public int getPriority() {
+ return 0;
+ }
+
+ public Region getRegion() {
+ return regionInstance.getRegion();
+ }
+
+ public RegionInstance getRegionInstance() {
+ return regionInstance;
+ }
+
+ public void setRegionInstance(RegionInstance regionInstance) {
+ this.regionInstance = regionInstance;
+ }
+
+ public final void serialize(OutputBuffer buf) throws IOException {
+ buf.writeShort(sender.getType());
+ sender.serialize(buf);
+
+ serializer.serialize(regionInstance.getRegion(), buf);
+ buf.writeInt(regionInstance.getInstance());
+
+ doSerialize(buf);
+ }
+
+ public abstract void doSerialize(OutputBuffer buf) throws IOException;
+
+ protected final Serializer getSerializer() {
+ return serializer;
+ }
+}
\ No newline at end of file
Modified: trunk/P2Play/src/org/p2play/scripting/pnuts/PnutsServer.java
===================================================================
--- trunk/P2Play/src/org/p2play/scripting/pnuts/PnutsServer.java 2007-01-22 12:52:54 UTC (rev 29)
+++ trunk/P2Play/src/org/p2play/scripting/pnuts/PnutsServer.java 2007-01-22 14:03:38 UTC (rev 30)
@@ -23,10 +23,10 @@
import java.util.List;
import java.util.Random;
-import org.p2play.net.region.GameAction;
-import org.p2play.net.region.GameState;
-import org.p2play.net.region.Region;
-import org.p2play.net.region.Server;
+import org.p2play.region.GameAction;
+import org.p2play.region.GameState;
+import org.p2play.region.Region;
+import org.p2play.region.Server;
import org.p2play.resource.ResourceClassLoader;
import org.p2play.scripting.pnuts.api.object.ObjectAPI;
import org.p2play.scripting.pnuts.api.region.RegionChangeAPI;
Modified: trunk/P2Play/src/org/p2play/scripting/pnuts/PnutsServerFactory.java
===================================================================
--- trunk/P2Play/src/org/p2play/scripting/pnuts/PnutsServerFactory.java 2007-01-22 12:52:54 UTC (rev 29)
+++ trunk/P2Play/src/org/p2play/scripting/pnuts/PnutsServerFactory.java 2007-01-22 14:03:38 UTC (rev 30)
@@ -18,9 +18,9 @@
*/
package org.p2play.scripting.pnuts;
-import org.p2play.net.region.Region;
-import org.p2play.net.region.Server;
-import org.p2play.net.region.ServerFactory;
+import org.p2play.region.Region;
+import org.p2play.region.Server;
+import org.p2play.region.ServerFactory;
import org.p2play.scripting.pnuts.api.region.RegionChangeAPI;
Modified: trunk/P2Play/src/org/p2play/scripting/pnuts/api/region/RegionAPI.java
===================================================================
--- trunk/P2Play/src/org/p2play/scripting/pnuts/api/region/RegionAPI.java 2007-01-22 12:52:54 UTC (rev 29)
+++ trunk/P2Play/src/org/p2play/scripting/pnuts/api/region/RegionAPI.java 2007-01-22 14:03:38 UTC (rev 30)
@@ -20,11 +20,11 @@
import java...
[truncated message content] |