p2play-commit Mailing List for P2Play (Page 3)
Status: Pre-Alpha
Brought to you by:
tisoft
You can subscribe to this list here.
| 2006 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
(17) |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 2007 |
Jan
(17) |
Feb
|
Mar
(18) |
Apr
|
May
|
Jun
(1) |
Jul
(8) |
Aug
(20) |
Sep
|
Oct
|
Nov
|
Dec
|
|
From: <ti...@us...> - 2007-01-22 14:15:12
|
Revision: 31
http://p2play.svn.sourceforge.net/p2play/?rev=31&view=rev
Author: tisoft
Date: 2007-01-22 06:15:09 -0800 (Mon, 22 Jan 2007)
Log Message:
-----------
Initial import.
Interfaces for persistent data
Added Paths:
-----------
trunk/P2Play/src/org/p2play/data/
trunk/P2Play/src/org/p2play/data/Data.java
trunk/P2Play/src/org/p2play/data/DataContainer.java
trunk/P2Play/src/org/p2play/data/DataListener.java
trunk/P2Play/src/org/p2play/data/DataManager.java
Added: trunk/P2Play/src/org/p2play/data/Data.java
===================================================================
--- trunk/P2Play/src/org/p2play/data/Data.java (rev 0)
+++ trunk/P2Play/src/org/p2play/data/Data.java 2007-01-22 14:15:09 UTC (rev 31)
@@ -0,0 +1,22 @@
+package org.p2play.data;
+
+import java.io.Serializable;
+
+import de.upb.mmog.net.security.Signable;
+
+/**
+ * All Objects stored in the DataManager have to be subclasses of Data
+ */
+public interface Data extends Serializable, Signable{
+ /**
+ * Returns the unique identifier for this Data
+ * @return the unique identifier
+ */
+ public String getIdentifier();
+ /**
+ * Returns the version of this Data
+ * @return the version
+ */
+ public int getVersion();
+
+}
Added: trunk/P2Play/src/org/p2play/data/DataContainer.java
===================================================================
--- trunk/P2Play/src/org/p2play/data/DataContainer.java (rev 0)
+++ trunk/P2Play/src/org/p2play/data/DataContainer.java 2007-01-22 14:15:09 UTC (rev 31)
@@ -0,0 +1,18 @@
+package org.p2play.data;
+
+
+public interface DataContainer {
+
+ public abstract Data getData();
+
+ public abstract String getName();
+
+ public abstract Exception getException();
+
+ public abstract boolean isReady();
+
+ public abstract void removeDataListener(DataListener listener);
+
+ public abstract void addDataListener(DataListener listener);
+
+}
\ No newline at end of file
Added: trunk/P2Play/src/org/p2play/data/DataListener.java
===================================================================
--- trunk/P2Play/src/org/p2play/data/DataListener.java (rev 0)
+++ trunk/P2Play/src/org/p2play/data/DataListener.java 2007-01-22 14:15:09 UTC (rev 31)
@@ -0,0 +1,10 @@
+package org.p2play.data;
+
+
+public interface DataListener {
+
+ void dataException(DataContainer container);
+
+ void dataUpdated(DataContainer container);
+
+}
Added: trunk/P2Play/src/org/p2play/data/DataManager.java
===================================================================
--- trunk/P2Play/src/org/p2play/data/DataManager.java (rev 0)
+++ trunk/P2Play/src/org/p2play/data/DataManager.java 2007-01-22 14:15:09 UTC (rev 31)
@@ -0,0 +1,28 @@
+package org.p2play.data;
+
+
+
+/**
+ * Applications can use a DataManager to load and store Data
+ */
+public interface DataManager {
+ /**
+ * loads the Data with the given Identifier.
+ * @param identifier the Identifier of the Data to load
+ * @return Data the loaded Data
+ */
+ public DataContainer loadData(String identifier);
+
+ /**
+ * loads the Data with the given Identifier. This method notifies the listener when the data becomes available.
+ * @param identifier the Identifier of the Data to load
+ * @return Data the loaded Data
+ */
+ public DataContainer loadData(String identifier, DataListener listener);
+
+ /**
+ * Stores Data
+ * @param data the data to be stored
+ */
+ public void storeData(Data data);
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
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] |
|
From: <ti...@us...> - 2007-01-22 12:52:53
|
Revision: 29
http://p2play.svn.sourceforge.net/p2play/?rev=29&view=rev
Author: tisoft
Date: 2007-01-22 04:52:54 -0800 (Mon, 22 Jan 2007)
Log Message:
-----------
Initial import of project structure.
Property Changed:
----------------
trunk/P2PlayBoot/
Property changes on: trunk/P2PlayBoot
___________________________________________________________________
Name: svn:ignore
+ bin
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ti...@us...> - 2007-01-22 12:50:57
|
Revision: 28
http://p2play.svn.sourceforge.net/p2play/?rev=28&view=rev
Author: tisoft
Date: 2007-01-22 04:50:57 -0800 (Mon, 22 Jan 2007)
Log Message:
-----------
Initial import.
A PAST based virtual file system
Added Paths:
-----------
trunk/P2PlayBoot/src/org/p2play/boot/vfs/
trunk/P2PlayBoot/src/org/p2play/boot/vfs/FilePastContent.java
trunk/P2PlayBoot/src/org/p2play/boot/vfs/FolderPastContent.java
trunk/P2PlayBoot/src/org/p2play/boot/vfs/ImagineryPastContent.java
trunk/P2PlayBoot/src/org/p2play/boot/vfs/PastDeserializer.java
trunk/P2PlayBoot/src/org/p2play/boot/vfs/PastryFileObject.java
trunk/P2PlayBoot/src/org/p2play/boot/vfs/PastryFileProvider.java
trunk/P2PlayBoot/src/org/p2play/boot/vfs/PastryFileSystem.java
Added: trunk/P2PlayBoot/src/org/p2play/boot/vfs/FilePastContent.java
===================================================================
--- trunk/P2PlayBoot/src/org/p2play/boot/vfs/FilePastContent.java (rev 0)
+++ trunk/P2PlayBoot/src/org/p2play/boot/vfs/FilePastContent.java 2007-01-22 12:50:57 UTC (rev 28)
@@ -0,0 +1,100 @@
+package org.p2play.boot.vfs;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+import rice.p2p.commonapi.Endpoint;
+import rice.p2p.commonapi.Id;
+import rice.p2p.commonapi.NodeHandle;
+import rice.p2p.commonapi.rawserialization.InputBuffer;
+import rice.p2p.commonapi.rawserialization.OutputBuffer;
+import rice.p2p.past.Past;
+import rice.p2p.past.PastContent;
+import rice.p2p.past.PastContentHandle;
+import rice.p2p.past.PastException;
+import rice.p2p.past.rawserialization.RawPastContent;
+
+public class FilePastContent implements RawPastContent {
+
+ private Id id;
+
+ private byte[] data;
+
+ private transient ByteArrayOutputStream outputStream;
+
+ public FilePastContent(Id id) {
+ super();
+ this.id = id;
+ this.data=new byte[0];
+ }
+
+ public FilePastContent(InputBuffer buf, Endpoint endpoint) throws IOException {
+ this.id=endpoint.readId(buf, buf.readShort());
+ this.data=new byte[buf.readInt()];
+ buf.read(this.data);
+ }
+
+ public PastContent checkInsert(Id id, PastContent existingContent)
+ throws PastException {
+ System.out.println("Storing file "+id.toString());
+ return this;
+ }
+
+ public PastContentHandle getHandle(final Past local) {
+ final NodeHandle handle=local.getLocalNodeHandle();
+ return new PastContentHandle() {
+ public Id getId() {
+ return FilePastContent.this.getId();
+ }
+ public NodeHandle getNodeHandle() {
+ return handle;
+ }
+ };
+ }
+
+ public short getType() {
+ return PastDeserializer.TYPE_FILE;
+ }
+
+ public Id getId() {
+ return id;
+ }
+
+ public boolean isMutable() {
+ return true;
+ }
+ public long getContentSize(){
+ return data.length;
+ }
+
+ public InputStream getInputStream(){
+ return new ByteArrayInputStream(data);
+ }
+
+ public OutputStream getOutputStream(boolean append) throws IOException {
+ if(outputStream!=null)
+ throw new IOException("Tring to open a second outputstream to the same file.");
+
+ outputStream=new ByteArrayOutputStream();
+ if(append)
+ outputStream.write(data);
+
+ return outputStream;
+ }
+
+ public void closeStream() {
+ if(outputStream!=null)
+ data=outputStream.toByteArray();
+ outputStream=null;
+ }
+
+ public void serialize(OutputBuffer buf) throws IOException {
+ buf.writeShort(id.getType());
+ id.serialize(buf);
+ buf.writeInt(data.length);
+ buf.write(data, 0, data.length);
+ }
+}
Added: trunk/P2PlayBoot/src/org/p2play/boot/vfs/FolderPastContent.java
===================================================================
--- trunk/P2PlayBoot/src/org/p2play/boot/vfs/FolderPastContent.java (rev 0)
+++ trunk/P2PlayBoot/src/org/p2play/boot/vfs/FolderPastContent.java 2007-01-22 12:50:57 UTC (rev 28)
@@ -0,0 +1,89 @@
+package org.p2play.boot.vfs;
+
+import java.io.IOException;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Iterator;
+
+import rice.p2p.commonapi.Endpoint;
+import rice.p2p.commonapi.Id;
+import rice.p2p.commonapi.NodeHandle;
+import rice.p2p.commonapi.rawserialization.InputBuffer;
+import rice.p2p.commonapi.rawserialization.OutputBuffer;
+import rice.p2p.past.Past;
+import rice.p2p.past.PastContent;
+import rice.p2p.past.PastContentHandle;
+import rice.p2p.past.PastException;
+import rice.p2p.past.rawserialization.RawPastContent;
+
+public class FolderPastContent implements RawPastContent {
+
+ private Id id;
+ private Collection<String> children;
+
+ public FolderPastContent(Id id) {
+ super();
+ this.id = id;
+ children=new HashSet<String>();
+ }
+
+ public FolderPastContent(InputBuffer buf, Endpoint endpoint) throws IOException {
+ this(endpoint.readId(buf, buf.readShort()));
+ int size=buf.readInt();
+ for (int i = 0; i < size; i++) {
+ children.add(buf.readUTF());
+ }
+ }
+
+ public PastContent checkInsert(Id id, PastContent existingContent)
+ throws PastException {
+ System.out.println("Storing folder "+id.toString());
+ return this;
+ }
+
+ public PastContentHandle getHandle(Past local) {
+ final NodeHandle handle=local.getLocalNodeHandle();
+ return new PastContentHandle() {
+ public Id getId() {
+ return FolderPastContent.this.getId();
+ }
+ public NodeHandle getNodeHandle() {
+ return handle;
+ }
+ };
+ }
+
+ public Id getId() {
+ return id;
+ }
+
+ public boolean isMutable() {
+ return true;
+ }
+
+ public short getType() {
+ return PastDeserializer.TYPE_FOLDER;
+ }
+
+ public void serialize(OutputBuffer buf) throws IOException {
+ buf.writeShort(id.getType());
+ id.serialize(buf);
+ buf.writeInt(children.size());
+ Iterator<String> iterator=children.iterator();
+ while (iterator.hasNext()) {
+ buf.writeUTF(iterator.next());
+ }
+ }
+
+ public String[] getChildren() {
+ return children.toArray(new String[children.size()]);
+ }
+
+ public void add(String pathDecoded) {
+ children.add(pathDecoded);
+ }
+
+ public void remove(String pathDecoded) {
+ children.remove(pathDecoded);
+ }
+}
Added: trunk/P2PlayBoot/src/org/p2play/boot/vfs/ImagineryPastContent.java
===================================================================
--- trunk/P2PlayBoot/src/org/p2play/boot/vfs/ImagineryPastContent.java (rev 0)
+++ trunk/P2PlayBoot/src/org/p2play/boot/vfs/ImagineryPastContent.java 2007-01-22 12:50:57 UTC (rev 28)
@@ -0,0 +1,49 @@
+package org.p2play.boot.vfs;
+
+import rice.p2p.commonapi.Id;
+import rice.p2p.commonapi.NodeHandle;
+import rice.p2p.past.Past;
+import rice.p2p.past.PastContent;
+import rice.p2p.past.PastContentHandle;
+import rice.p2p.past.PastException;
+
+/**
+ * This class represents a deeted file or folder
+ *
+ * @author markus
+ *
+ */
+public class ImagineryPastContent implements PastContent {
+ private Id id;
+
+ public ImagineryPastContent(Id id) {
+ super();
+ this.id = id;
+ }
+
+ public PastContent checkInsert(Id id, PastContent existingContent)
+ throws PastException {
+ System.out.println("Deleting "+id.toString());
+ return this;
+ }
+
+ public PastContentHandle getHandle(final Past local) {
+ final NodeHandle handle=local.getLocalNodeHandle();
+ return new PastContentHandle() {
+ public Id getId() {
+ return ImagineryPastContent.this.getId();
+ }
+ public NodeHandle getNodeHandle() {
+ return handle;
+ }
+ };
+ }
+
+ public Id getId() {
+ return id;
+ }
+
+ public boolean isMutable() {
+ return true;
+ }
+}
Added: trunk/P2PlayBoot/src/org/p2play/boot/vfs/PastDeserializer.java
===================================================================
--- trunk/P2PlayBoot/src/org/p2play/boot/vfs/PastDeserializer.java (rev 0)
+++ trunk/P2PlayBoot/src/org/p2play/boot/vfs/PastDeserializer.java 2007-01-22 12:50:57 UTC (rev 28)
@@ -0,0 +1,38 @@
+package org.p2play.boot.vfs;
+
+import java.io.IOException;
+
+import rice.p2p.commonapi.Endpoint;
+import rice.p2p.commonapi.rawserialization.InputBuffer;
+import rice.p2p.past.PastContent;
+import rice.p2p.past.rawserialization.JavaPastContentDeserializer;
+import rice.p2p.past.rawserialization.PastContentDeserializer;
+
+public class PastDeserializer implements PastContentDeserializer {
+
+ public static final short TYPE_IMAGINERY = 1;
+
+ public static final short TYPE_FOLDER = 2;
+
+ public static final short TYPE_FILE = 3;
+
+ private JavaPastContentDeserializer deserializer;
+
+ public PastDeserializer() {
+ deserializer=new JavaPastContentDeserializer();
+ }
+
+ public PastContent deserializePastContent(InputBuffer buf,
+ Endpoint endpoint, short contentType) throws IOException {
+ switch (contentType) {
+ case TYPE_FILE:
+ return new FilePastContent(buf,endpoint);
+ case TYPE_FOLDER:
+ return new FolderPastContent(buf,endpoint);
+ default:
+ return deserializer.deserializePastContent(buf, endpoint,
+ contentType);
+ }
+ }
+
+}
Added: trunk/P2PlayBoot/src/org/p2play/boot/vfs/PastryFileObject.java
===================================================================
--- trunk/P2PlayBoot/src/org/p2play/boot/vfs/PastryFileObject.java (rev 0)
+++ trunk/P2PlayBoot/src/org/p2play/boot/vfs/PastryFileObject.java 2007-01-22 12:50:57 UTC (rev 28)
@@ -0,0 +1,176 @@
+package org.p2play.boot.vfs;
+
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.Arrays;
+
+import org.apache.commons.vfs.FileName;
+import org.apache.commons.vfs.FileSystemException;
+import org.apache.commons.vfs.FileType;
+import org.apache.commons.vfs.provider.AbstractFileObject;
+import org.apache.commons.vfs.provider.AbstractFileSystem;
+
+import rice.Continuation;
+import rice.p2p.commonapi.Id;
+import rice.p2p.commonapi.Node;
+import rice.p2p.past.Past;
+import rice.p2p.past.PastContent;
+
+public class PastryFileObject extends AbstractFileObject {
+ private Past past;
+
+ private Id id;
+
+ private Exception exception;
+
+ private PastContent content;
+
+ private Object mutex = new Object();
+
+ /**
+ * are we currently in the process of refreshing our state?
+ */
+ private boolean refreshing;
+
+ public PastryFileObject(Node node, Past past, FileName name,
+ AbstractFileSystem fs) throws FileSystemException {
+ super(name, fs);
+ this.past = past;
+ this.id = node.getIdFactory().buildId(name.getPathDecoded());
+ this.refreshing = true;
+ }
+
+ @Override
+ protected void doAttach() throws Exception {
+ this.past.lookup(this.id, new Continuation() {
+ public void receiveException(Exception result) {
+ result.printStackTrace();
+
+ exception = result;
+
+ synchronized (mutex) {
+ refreshing = false;
+ mutex.notifyAll();
+ }
+ }
+
+ public void receiveResult(Object result) {
+ content = (PastContent) result;
+ synchronized (mutex) {
+ refreshing = false;
+ mutex.notifyAll();
+ }
+ }
+ });
+
+ waitForRefreshFinished();
+ }
+
+ @Override
+ protected void doCreateFolder() throws Exception {
+ FolderPastContent folderPastContent = new FolderPastContent(id);
+
+ updateData(folderPastContent);
+
+ refresh();
+ }
+
+ private void updateData(final PastContent pastContent) throws Exception {
+ //close stream of files, so that they can be transmitted
+ if(pastContent instanceof FilePastContent)
+ ((FilePastContent)pastContent).closeStream();
+
+ past.insert(pastContent, new Continuation() {
+
+ public void receiveException(Exception result) {
+ result.printStackTrace();
+
+ exception = result;
+
+ synchronized (mutex) {
+ refreshing = false;
+ mutex.notifyAll();
+ }
+ }
+
+ public void receiveResult(Object result) {
+ System.out.println("Update of "+pastContent.getId()+": "+Arrays.toString((Object[])result));
+ synchronized (mutex) {
+ refreshing = false;
+ mutex.notifyAll();
+ }
+ }
+ });
+
+ waitForRefreshFinished();
+ }
+
+ @Override
+ protected long doGetContentSize() throws Exception {
+ return ((FilePastContent) content).getContentSize();
+ }
+
+ private void waitForRefreshFinished() throws Exception {
+ if (refreshing) {
+ synchronized (mutex) {
+ mutex.wait();
+ }
+ }
+
+ if (exception != null)
+ throw exception;
+ }
+
+ @Override
+ protected InputStream doGetInputStream() throws Exception {
+ return ((FilePastContent) content).getInputStream();
+ }
+
+ @Override
+ protected OutputStream doGetOutputStream(boolean bAppend) throws Exception {
+ if(content==null||content instanceof ImagineryPastContent)
+ content=new FilePastContent(id);
+ return ((FilePastContent)content).getOutputStream(bAppend);
+ }
+
+ @Override
+ protected FileType doGetType() throws Exception {
+ if (content == null)
+ return FileType.IMAGINARY;
+ else if (content instanceof ImagineryPastContent)
+ return FileType.IMAGINARY;
+ else if (content instanceof FilePastContent)
+ return FileType.FILE;
+ else if (content instanceof FolderPastContent)
+ return FileType.FOLDER;
+
+ return FileType.IMAGINARY;
+ }
+
+ @Override
+ protected void doDelete() throws Exception {
+ content=new ImagineryPastContent(id);
+ updateData(content);
+ }
+
+ @Override
+ protected String[] doListChildren() throws Exception {
+ return ((FolderPastContent)content).getChildren();
+ }
+
+ @Override
+ protected void onChildrenChanged(FileName child, FileType newType) throws Exception {
+ if(!isAttached())
+ this.doAttach();
+ if(newType==FileType.IMAGINARY)
+ ((FolderPastContent)content).remove(child.getPathDecoded());
+ else
+ ((FolderPastContent)content).add(child.getPathDecoded());
+ updateData(content);
+ }
+
+ @Override
+ protected void onChange() throws Exception {
+ updateData(content);
+ }
+}
Added: trunk/P2PlayBoot/src/org/p2play/boot/vfs/PastryFileProvider.java
===================================================================
--- trunk/P2PlayBoot/src/org/p2play/boot/vfs/PastryFileProvider.java (rev 0)
+++ trunk/P2PlayBoot/src/org/p2play/boot/vfs/PastryFileProvider.java 2007-01-22 12:50:57 UTC (rev 28)
@@ -0,0 +1,48 @@
+package org.p2play.boot.vfs;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+
+import org.apache.commons.vfs.Capability;
+import org.apache.commons.vfs.FileName;
+import org.apache.commons.vfs.FileSystem;
+import org.apache.commons.vfs.FileSystemException;
+import org.apache.commons.vfs.FileSystemOptions;
+import org.apache.commons.vfs.provider.AbstractOriginatingFileProvider;
+import org.p2play.net.pastry.NodeHandler;
+
+public class PastryFileProvider extends AbstractOriginatingFileProvider {
+
+ private NodeHandler nodeHandler;
+
+ final static Collection capabilities = Collections
+ .unmodifiableCollection(Arrays
+ .asList(new Capability[] {
+ Capability.CREATE,
+ Capability.DELETE,
+ Capability.GET_TYPE,
+ Capability.LIST_CHILDREN,
+ Capability.READ_CONTENT,
+ Capability.WRITE_CONTENT,
+ Capability.GET_LAST_MODIFIED,
+ Capability.URI,
+ Capability.COMPRESS,
+ Capability.SIGNING,
+ }));
+
+ public PastryFileProvider(NodeHandler nodeHandler) {
+ this.nodeHandler=nodeHandler;
+ }
+
+ @Override
+ protected FileSystem doCreateFileSystem(FileName rootName,
+ FileSystemOptions fileSystemOptions) throws FileSystemException {
+ return new PastryFileSystem(this, nodeHandler, rootName, fileSystemOptions);
+ }
+
+ public Collection getCapabilities() {
+ return capabilities;
+ }
+
+}
Added: trunk/P2PlayBoot/src/org/p2play/boot/vfs/PastryFileSystem.java
===================================================================
--- trunk/P2PlayBoot/src/org/p2play/boot/vfs/PastryFileSystem.java (rev 0)
+++ trunk/P2PlayBoot/src/org/p2play/boot/vfs/PastryFileSystem.java 2007-01-22 12:50:57 UTC (rev 28)
@@ -0,0 +1,43 @@
+package org.p2play.boot.vfs;
+
+import java.util.Collection;
+
+import org.apache.commons.vfs.FileName;
+import org.apache.commons.vfs.FileObject;
+import org.apache.commons.vfs.FileSystemOptions;
+import org.apache.commons.vfs.provider.AbstractFileSystem;
+import org.p2play.net.pastry.NodeHandler;
+
+import rice.p2p.commonapi.Node;
+import rice.p2p.past.Past;
+
+public class PastryFileSystem extends AbstractFileSystem {
+
+ private PastryFileProvider pastryFileProvider;
+
+ private Node node;
+
+ private Past past;
+
+ public PastryFileSystem(PastryFileProvider pastryFileProvider, NodeHandler nodeHandler,
+ FileName rootName, FileSystemOptions fileSystemOptions) {
+ super(rootName, null, fileSystemOptions);
+ this.pastryFileProvider = pastryFileProvider;
+ this.node = nodeHandler.getNode();
+ this.past = nodeHandler.getPast("p2play.vfs");
+ this.past.setContentDeserializer(new PastDeserializer());
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ protected void addCapabilities(Collection caps) {
+ caps.addAll(pastryFileProvider.getCapabilities());
+ }
+
+ @Override
+ protected FileObject createFile(FileName name) throws Exception {
+ // TODO Auto-generated method stub
+ return new PastryFileObject(node, past, name, this);
+ }
+
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ti...@us...> - 2007-01-22 12:50:52
|
Revision: 27
http://p2play.svn.sourceforge.net/p2play/?rev=27&view=rev
Author: tisoft
Date: 2007-01-22 04:50:49 -0800 (Mon, 22 Jan 2007)
Log Message:
-----------
Initial import.
A PAST based virtual file system
Added Paths:
-----------
trunk/P2PlayBoot/src/org/p2play/boot/
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ti...@us...> - 2007-01-22 12:36:37
|
Revision: 26
http://p2play.svn.sourceforge.net/p2play/?rev=26&view=rev
Author: tisoft
Date: 2007-01-22 04:36:37 -0800 (Mon, 22 Jan 2007)
Log Message:
-----------
moved stuff from P2Play to P2PlayBoot since it is needed for bootstraping
Modified Paths:
--------------
trunk/P2Play/.classpath
trunk/P2Play/.project
trunk/P2PlayAdmin/.settings/org.eclipse.wst.common.component
trunk/P2PlayBoot/.classpath
trunk/P2PlayBoot/src/org/p2play/net/pastry/time/NTPMessage.java
Added Paths:
-----------
trunk/P2PlayBoot/lib/FreePastry.jar
trunk/P2PlayBoot/lib/sources/FreePastry-source.zip
trunk/P2PlayBoot/lib/xpp3-1.1.3.4d_b2.jar
trunk/P2PlayBoot/lib/xstream-1.1.3.jar
trunk/P2PlayBoot/src/org/p2play/net/
trunk/P2PlayBoot/src/org/p2play/net/pastry/
trunk/P2PlayBoot/src/org/p2play/net/pastry/DefaultNodeHandler.java
trunk/P2PlayBoot/src/org/p2play/net/pastry/NodeHandler.java
trunk/P2PlayBoot/src/org/p2play/net/pastry/Pastry.java
trunk/P2PlayBoot/src/org/p2play/net/pastry/time/
Removed Paths:
-------------
trunk/P2Play/lib/FreePastry.jar
trunk/P2Play/lib/sources/FreePastry-source.zip
trunk/P2Play/lib/xpp3-1.1.3.4d_b2.jar
trunk/P2Play/lib/xstream-1.1.3.jar
trunk/P2Play/src/org/p2play/net/pastry/
Modified: trunk/P2Play/.classpath
===================================================================
--- trunk/P2Play/.classpath 2007-01-22 12:31:10 UTC (rev 25)
+++ trunk/P2Play/.classpath 2007-01-22 12:36:37 UTC (rev 26)
@@ -2,11 +2,9 @@
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
- <classpathentry exported="true" kind="lib" path="lib/FreePastry.jar" sourcepath="lib/sources/FreePastry-source.zip"/>
<classpathentry exported="true" kind="lib" path="lib/javolution.jar" sourcepath="lib/sources/javolution-4.1.0-src.zip"/>
<classpathentry exported="true" kind="lib" path="lib/pnuts.jar" sourcepath="lib/sources/pnuts-1.2-src.zip"/>
<classpathentry exported="true" kind="lib" path="lib/jdom.jar" sourcepath="lib/sources/jdom-1.0.zip"/>
- <classpathentry exported="true" kind="lib" path="lib/xstream-1.1.3.jar"/>
- <classpathentry exported="true" kind="lib" path="lib/xpp3-1.1.3.4d_b2.jar"/>
+ <classpathentry combineaccessrules="false" kind="src" path="/P2PlayBoot"/>
<classpathentry kind="output" path="bin"/>
</classpath>
Modified: trunk/P2Play/.project
===================================================================
--- trunk/P2Play/.project 2007-01-22 12:31:10 UTC (rev 25)
+++ trunk/P2Play/.project 2007-01-22 12:36:37 UTC (rev 26)
@@ -6,12 +6,25 @@
</projects>
<buildSpec>
<buildCommand>
+ <name>org.eclipse.wst.common.project.facet.core.builder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
+ <buildCommand>
+ <name>org.eclipse.wst.validation.validationbuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
+ <nature>org.eclipse.wst.common.project.facet.core.nature</nature>
+ <nature>org.eclipse.wst.common.modulecore.ModuleCoreNature</nature>
+ <nature>org.eclipse.jem.workbench.JavaEMFNature</nature>
</natures>
</projectDescription>
Deleted: trunk/P2Play/lib/FreePastry.jar
===================================================================
(Binary files differ)
Deleted: trunk/P2Play/lib/sources/FreePastry-source.zip
===================================================================
(Binary files differ)
Deleted: trunk/P2Play/lib/xpp3-1.1.3.4d_b2.jar
===================================================================
(Binary files differ)
Deleted: trunk/P2Play/lib/xstream-1.1.3.jar
===================================================================
(Binary files differ)
Modified: trunk/P2PlayAdmin/.settings/org.eclipse.wst.common.component
===================================================================
--- trunk/P2PlayAdmin/.settings/org.eclipse.wst.common.component 2007-01-22 12:31:10 UTC (rev 25)
+++ trunk/P2PlayAdmin/.settings/org.eclipse.wst.common.component 2007-01-22 12:36:37 UTC (rev 26)
@@ -7,12 +7,6 @@
<dependent-module deploy-path="/WEB-INF/lib" handle="module:/resource/P2Play/P2Play">
<dependency-type>uses</dependency-type>
</dependent-module>
-<dependent-module deploy-path="/WEB-INF/lib" handle="module:/classpath/lib/P2Play/lib/xstream-1.1.3.jar">
-<dependency-type>uses</dependency-type>
-</dependent-module>
-<dependent-module deploy-path="/WEB-INF/lib" handle="module:/classpath/lib/P2Play/lib/xpp3-1.1.3.4d_b2.jar">
-<dependency-type>uses</dependency-type>
-</dependent-module>
<dependent-module deploy-path="/WEB-INF/lib" handle="module:/classpath/lib/P2Play/lib/pnuts.jar">
<dependency-type>uses</dependency-type>
</dependent-module>
@@ -22,9 +16,6 @@
<dependent-module deploy-path="/WEB-INF/lib" handle="module:/classpath/lib/P2Play/lib/javolution.jar">
<dependency-type>uses</dependency-type>
</dependent-module>
-<dependent-module deploy-path="/WEB-INF/lib" handle="module:/classpath/lib/P2Play/lib/FreePastry.jar">
-<dependency-type>uses</dependency-type>
-</dependent-module>
<dependent-module deploy-path="/WEB-INF/lib" handle="module:/resource/P2PlayBoot/P2PlayBoot">
<dependency-type>uses</dependency-type>
</dependent-module>
@@ -34,6 +25,15 @@
<dependent-module deploy-path="/WEB-INF/lib" handle="module:/classpath/lib/P2PlayBoot/lib/commons-logging-1.1.jar">
<dependency-type>uses</dependency-type>
</dependent-module>
+<dependent-module deploy-path="/WEB-INF/lib" handle="module:/classpath/lib/P2PlayBoot/lib/xstream-1.1.3.jar">
+<dependency-type>uses</dependency-type>
+</dependent-module>
+<dependent-module deploy-path="/WEB-INF/lib" handle="module:/classpath/lib/P2PlayBoot/lib/xpp3-1.1.3.4d_b2.jar">
+<dependency-type>uses</dependency-type>
+</dependent-module>
+<dependent-module deploy-path="/WEB-INF/lib" handle="module:/classpath/lib/P2PlayBoot/lib/FreePastry.jar">
+<dependency-type>uses</dependency-type>
+</dependent-module>
<property name="context-root" value="P2PlayAdmin"/>
<property name="java-output-path" value="build/classes"/>
</wb-module>
Modified: trunk/P2PlayBoot/.classpath
===================================================================
--- trunk/P2PlayBoot/.classpath 2007-01-22 12:31:10 UTC (rev 25)
+++ trunk/P2PlayBoot/.classpath 2007-01-22 12:36:37 UTC (rev 26)
@@ -2,8 +2,10 @@
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
- <classpathentry combineaccessrules="false" exported="true" kind="src" path="/P2Play"/>
<classpathentry exported="true" kind="lib" path="lib/commons-vfs-20070107.jar" sourcepath="lib/sources/commons-vfs-20070107-src.zip"/>
<classpathentry exported="true" kind="lib" path="lib/commons-logging-1.1.jar" sourcepath="lib/sources/commons-logging-1.1-src.zip"/>
+ <classpathentry exported="true" kind="lib" path="lib/xstream-1.1.3.jar"/>
+ <classpathentry exported="true" kind="lib" path="lib/xpp3-1.1.3.4d_b2.jar"/>
+ <classpathentry exported="true" kind="lib" path="lib/FreePastry.jar" sourcepath="lib/sources/FreePastry-source.zip"/>
<classpathentry kind="output" path="bin"/>
</classpath>
Copied: trunk/P2PlayBoot/lib/FreePastry.jar (from rev 18, trunk/P2Play/lib/FreePastry.jar)
===================================================================
(Binary files differ)
Copied: trunk/P2PlayBoot/lib/sources/FreePastry-source.zip (from rev 18, trunk/P2Play/lib/sources/FreePastry-source.zip)
===================================================================
(Binary files differ)
Copied: trunk/P2PlayBoot/lib/xpp3-1.1.3.4d_b2.jar (from rev 18, trunk/P2Play/lib/xpp3-1.1.3.4d_b2.jar)
===================================================================
(Binary files differ)
Copied: trunk/P2PlayBoot/lib/xstream-1.1.3.jar (from rev 18, trunk/P2Play/lib/xstream-1.1.3.jar)
===================================================================
(Binary files differ)
Added: trunk/P2PlayBoot/src/org/p2play/net/pastry/DefaultNodeHandler.java
===================================================================
--- trunk/P2PlayBoot/src/org/p2play/net/pastry/DefaultNodeHandler.java (rev 0)
+++ trunk/P2PlayBoot/src/org/p2play/net/pastry/DefaultNodeHandler.java 2007-01-22 12:36:37 UTC (rev 26)
@@ -0,0 +1,73 @@
+package org.p2play.net.pastry;
+
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.io.IOException;
+import java.net.InetAddress;
+import java.net.InetSocketAddress;
+import java.net.UnknownHostException;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.p2play.net.pastry.NodeHandler;
+import org.p2play.net.pastry.Pastry;
+
+import rice.p2p.commonapi.Node;
+import rice.p2p.past.Past;
+import rice.p2p.past.PastImpl;
+import rice.p2p.scribe.Scribe;
+import rice.p2p.scribe.ScribeImpl;
+import rice.persistence.LRUCache;
+import rice.persistence.MemoryStorage;
+import rice.persistence.StorageManagerImpl;
+
+public class DefaultNodeHandler implements NodeHandler {
+ private Node node;
+
+ private Map<String, Past> pastMap = new HashMap<String, Past>();
+
+ private Map<String, Scribe> scribeMap = new HashMap<String, Scribe>();
+
+ private static DefaultNodeHandler staticNode;
+
+ public Node getNode() {
+ if (node == null)
+ throw new RuntimeException("Node not initialized!");
+ return node;
+ }
+
+ public Past getPast(String instance) {
+ Past past = pastMap.get(instance);
+
+ if (past == null) {
+ past = new PastImpl(node, new StorageManagerImpl(node
+ .getIdFactory(), new MemoryStorage(node.getIdFactory()),
+ new LRUCache(new MemoryStorage(node.getIdFactory()), 100,
+ node.getEnvironment())), 3, instance);
+
+ pastMap.put(instance, past);
+ }
+
+ return past;
+ }
+
+ public Scribe getScribe(String instance) {
+ Scribe scribe = scribeMap.get(instance);
+
+ if (scribe == null) {
+ scribe = new ScribeImpl(getNode(), instance);
+
+ scribeMap.put(instance, scribe);
+ }
+
+ return scribe;
+ }
+
+ public DefaultNodeHandler(Node node) {
+ super();
+ this.node = node;
+ this.pastMap=new HashMap<String, Past>();
+ this.scribeMap=new HashMap<String, Scribe>();
+ }
+
+}
Added: trunk/P2PlayBoot/src/org/p2play/net/pastry/NodeHandler.java
===================================================================
--- trunk/P2PlayBoot/src/org/p2play/net/pastry/NodeHandler.java (rev 0)
+++ trunk/P2PlayBoot/src/org/p2play/net/pastry/NodeHandler.java 2007-01-22 12:36:37 UTC (rev 26)
@@ -0,0 +1,11 @@
+package org.p2play.net.pastry;
+
+import rice.p2p.commonapi.Node;
+import rice.p2p.past.Past;
+import rice.p2p.scribe.Scribe;
+
+public interface NodeHandler {
+ public Node getNode();
+ public Past getPast(String instance);
+ public Scribe getScribe(String instance);
+}
Copied: trunk/P2PlayBoot/src/org/p2play/net/pastry/Pastry.java (from rev 18, trunk/P2Play/src/org/p2play/net/pastry/Pastry.java)
===================================================================
--- trunk/P2PlayBoot/src/org/p2play/net/pastry/Pastry.java (rev 0)
+++ trunk/P2PlayBoot/src/org/p2play/net/pastry/Pastry.java 2007-01-22 12:36:37 UTC (rev 26)
@@ -0,0 +1,130 @@
+/*
+ * 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.pastry;
+
+import java.io.IOException;
+import java.net.InetAddress;
+import java.net.InetSocketAddress;
+
+import org.p2play.net.pastry.time.NTPTimeSource;
+
+import rice.environment.Environment;
+import rice.environment.logging.LogManager;
+import rice.environment.params.simple.SimpleParameters;
+import rice.p2p.commonapi.Node;
+import rice.pastry.NodeIdFactory;
+import rice.pastry.PastryNode;
+import rice.pastry.socket.SocketPastryNodeFactory;
+import rice.pastry.standard.RandomNodeIdFactory;
+
+public class Pastry {
+ /**
+ * Boot into the Pastry Network
+ *
+ * @param remoteHost
+ * the remote host to boot into
+ * @param remotePort
+ * the port on the remote host to boot into
+ * @param externalHost
+ * our external IP
+ * @param localPort
+ * the port we bind to
+ * @return The local PastryNode, that is connected in the Pastry Network
+ * @throws IOException
+ */
+ public static Node boot(String remoteHost, int remotePort,
+ String externalHost, int localPort) throws IOException {
+ return boot(InetAddress.getByName(remoteHost), remotePort, InetAddress
+ .getByName(externalHost), localPort);
+ }
+
+ /**
+ * Boot into the Pastry Network
+ *
+ * @param remoteHost
+ * the remote host to boot into
+ * @param remotePort
+ * the port on the remote host to boot into
+ * @param externalHost
+ * our external IP
+ * @param localPort
+ * the port we bind to
+ * @return The local PastryNode, that is connected in the Pastry Network
+ * @throws IOException
+ */
+ public static Node boot(InetAddress remoteHost, int remotePort,
+ InetAddress externalHost, int localPort) throws IOException {
+ return boot(new InetSocketAddress(remoteHost, remotePort),
+ externalHost, localPort);
+ }
+ /**
+ * Boot into the Pastry Network
+ *
+ * @param remote
+ * the boot node
+ * @param externalAddress
+ * our external IP
+ * @param localPort
+ * the port we bind to
+ * @return The local PastryNode, that is connected in the Pastry Network
+ * @throws IOException
+ */
+ public static Node boot(InetSocketAddress remote,
+ InetAddress externalAddress, int localPort) throws IOException {
+ return boot(remote,externalAddress,localPort,null);
+ }
+
+
+ /**
+ * Boot into the Pastry Network
+ *
+ * @param remote
+ * the boot node
+ * @param externalAddress
+ * our external IP
+ * @param localPort
+ * the port we bind to
+ * @return The local PastryNode, that is connected in the Pastry Network
+ * @throws IOException
+ */
+ public static Node boot(InetSocketAddress remote,
+ InetAddress externalAddress, int localPort, LogManager logManager) throws IOException {
+ PastryNode node;
+
+ Environment environment = new Environment(null, null, null,
+ NTPTimeSource.getTimeSource(), logManager, new SimpleParameters(
+ new String[]{"mmog"}, null), null);
+ NodeIdFactory nidFactory = new RandomNodeIdFactory(environment);
+ SocketPastryNodeFactory factory = new SocketPastryNodeFactory(
+ nidFactory, externalAddress, localPort, environment, null);
+
+ node = factory.newNode(factory.getNodeHandle(remote));
+
+ while (!node.isReady()) {
+ // delay so we don't busy-wait
+ try {
+ Thread.sleep(100);
+ } catch (InterruptedException e) {
+ // TODO Auto-generated catch block
+ }
+ }
+
+ return node;
+ }
+}
Copied: trunk/P2PlayBoot/src/org/p2play/net/pastry/time (from rev 18, trunk/P2Play/src/org/p2play/net/pastry/time)
Modified: trunk/P2PlayBoot/src/org/p2play/net/pastry/time/NTPMessage.java
===================================================================
--- trunk/P2Play/src/org/p2play/net/pastry/time/NTPMessage.java 2007-01-16 13:11:11 UTC (rev 18)
+++ trunk/P2PlayBoot/src/org/p2play/net/pastry/time/NTPMessage.java 2007-01-22 12:36:37 UTC (rev 26)
@@ -32,10 +32,9 @@
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
+import java.util.Random;
-import org.p2play.util.NetRandom;
-
/**
* This class represents a NTP message, as specified in RFC 2030. The message
* format is compatible with all versions of NTP and SNTP.
@@ -75,7 +74,7 @@
* @author Adam Buckley
*/
public class NTPMessage {
- private static NetRandom random=new NetRandom();
+ private static Random random=new Random();
/**
* This is a two-bit code warning of an impending leap second to be
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ti...@us...> - 2007-01-22 12:31:09
|
Revision: 25
http://p2play.svn.sourceforge.net/p2play/?rev=25&view=rev
Author: tisoft
Date: 2007-01-22 04:31:10 -0800 (Mon, 22 Jan 2007)
Log Message:
-----------
moved stuff from P2Play to P2PlayBoot since it is needed for bootstraping
Added Paths:
-----------
trunk/P2PlayBoot/src/org/
trunk/P2PlayBoot/src/org/p2play/
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ti...@us...> - 2007-01-22 12:08:35
|
Revision: 24
http://p2play.svn.sourceforge.net/p2play/?rev=24&view=rev
Author: tisoft
Date: 2007-01-22 04:08:34 -0800 (Mon, 22 Jan 2007)
Log Message:
-----------
Initial import of project structure.
Added Paths:
-----------
trunk/P2Play/.settings/org.eclipse.jdt.core.prefs
trunk/P2Play/.settings/org.eclipse.wst.common.component
trunk/P2Play/.settings/org.eclipse.wst.common.project.facet.core.xml
trunk/P2Play/src/META-INF/
trunk/P2Play/src/META-INF/MANIFEST.MF
trunk/P2PlayAdmin/src/
trunk/P2PlayBoot/lib/
trunk/P2PlayBoot/lib/commons-logging-1.1.jar
trunk/P2PlayBoot/lib/commons-vfs-20070107.jar
trunk/P2PlayBoot/lib/sources/
trunk/P2PlayBoot/lib/sources/commons-logging-1.1-src.zip
trunk/P2PlayBoot/lib/sources/commons-vfs-20070107-src.zip
trunk/P2PlayBoot/src/META-INF/
trunk/P2PlayBoot/src/META-INF/MANIFEST.MF
Added: trunk/P2Play/.settings/org.eclipse.jdt.core.prefs
===================================================================
--- trunk/P2Play/.settings/org.eclipse.jdt.core.prefs (rev 0)
+++ trunk/P2Play/.settings/org.eclipse.jdt.core.prefs 2007-01-22 12:08:34 UTC (rev 24)
@@ -0,0 +1,7 @@
+#Tue Jan 16 20:32:12 CET 2007
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
+org.eclipse.jdt.core.compiler.compliance=1.5
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.5
Added: trunk/P2Play/.settings/org.eclipse.wst.common.component
===================================================================
--- trunk/P2Play/.settings/org.eclipse.wst.common.component (rev 0)
+++ trunk/P2Play/.settings/org.eclipse.wst.common.component 2007-01-22 12:08:34 UTC (rev 24)
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project-modules id="moduleCoreId" project-version="1.5.0">
+<wb-module deploy-name="P2Play">
+<wb-resource deploy-path="/" source-path="/src"/>
+</wb-module>
+</project-modules>
Added: trunk/P2Play/.settings/org.eclipse.wst.common.project.facet.core.xml
===================================================================
--- trunk/P2Play/.settings/org.eclipse.wst.common.project.facet.core.xml (rev 0)
+++ trunk/P2Play/.settings/org.eclipse.wst.common.project.facet.core.xml 2007-01-22 12:08:34 UTC (rev 24)
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<faceted-project>
+ <fixed facet="jst.utility"/>
+ <fixed facet="jst.java"/>
+ <installed facet="jst.java" version="5.0"/>
+ <installed facet="jst.utility" version="1.0"/>
+</faceted-project>
Added: trunk/P2Play/src/META-INF/MANIFEST.MF
===================================================================
--- trunk/P2Play/src/META-INF/MANIFEST.MF (rev 0)
+++ trunk/P2Play/src/META-INF/MANIFEST.MF 2007-01-22 12:08:34 UTC (rev 24)
@@ -0,0 +1,3 @@
+Manifest-Version: 1.0
+Class-Path:
+
Added: trunk/P2PlayBoot/lib/commons-logging-1.1.jar
===================================================================
(Binary files differ)
Property changes on: trunk/P2PlayBoot/lib/commons-logging-1.1.jar
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: trunk/P2PlayBoot/lib/commons-vfs-20070107.jar
===================================================================
(Binary files differ)
Property changes on: trunk/P2PlayBoot/lib/commons-vfs-20070107.jar
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: trunk/P2PlayBoot/lib/sources/commons-logging-1.1-src.zip
===================================================================
(Binary files differ)
Property changes on: trunk/P2PlayBoot/lib/sources/commons-logging-1.1-src.zip
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: trunk/P2PlayBoot/lib/sources/commons-vfs-20070107-src.zip
===================================================================
(Binary files differ)
Property changes on: trunk/P2PlayBoot/lib/sources/commons-vfs-20070107-src.zip
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: trunk/P2PlayBoot/src/META-INF/MANIFEST.MF
===================================================================
--- trunk/P2PlayBoot/src/META-INF/MANIFEST.MF (rev 0)
+++ trunk/P2PlayBoot/src/META-INF/MANIFEST.MF 2007-01-22 12:08:34 UTC (rev 24)
@@ -0,0 +1,3 @@
+Manifest-Version: 1.0
+Class-Path:
+
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ti...@us...> - 2007-01-22 11:38:16
|
Revision: 23
http://p2play.svn.sourceforge.net/p2play/?rev=23&view=rev
Author: tisoft
Date: 2007-01-22 03:38:13 -0800 (Mon, 22 Jan 2007)
Log Message:
-----------
Initial import of project structure.
Added Paths:
-----------
trunk/P2PlayBoot/.classpath
trunk/P2PlayBoot/.project
trunk/P2PlayBoot/.settings/
trunk/P2PlayBoot/.settings/org.eclipse.jdt.core.prefs
trunk/P2PlayBoot/.settings/org.eclipse.jdt.ui.prefs
trunk/P2PlayBoot/.settings/org.eclipse.wst.common.component
trunk/P2PlayBoot/.settings/org.eclipse.wst.common.project.facet.core.xml
trunk/P2PlayBoot/src/
Added: trunk/P2PlayBoot/.classpath
===================================================================
--- trunk/P2PlayBoot/.classpath (rev 0)
+++ trunk/P2PlayBoot/.classpath 2007-01-22 11:38:13 UTC (rev 23)
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+ <classpathentry combineaccessrules="false" exported="true" kind="src" path="/P2Play"/>
+ <classpathentry exported="true" kind="lib" path="lib/commons-vfs-20070107.jar" sourcepath="lib/sources/commons-vfs-20070107-src.zip"/>
+ <classpathentry exported="true" kind="lib" path="lib/commons-logging-1.1.jar" sourcepath="lib/sources/commons-logging-1.1-src.zip"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
Added: trunk/P2PlayBoot/.project
===================================================================
--- trunk/P2PlayBoot/.project (rev 0)
+++ trunk/P2PlayBoot/.project 2007-01-22 11:38:13 UTC (rev 23)
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>P2PlayBoot</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.wst.common.project.facet.core.builder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.wst.validation.validationbuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ <nature>org.eclipse.wst.common.project.facet.core.nature</nature>
+ <nature>org.eclipse.wst.common.modulecore.ModuleCoreNature</nature>
+ <nature>org.eclipse.jem.workbench.JavaEMFNature</nature>
+ </natures>
+</projectDescription>
Added: trunk/P2PlayBoot/.settings/org.eclipse.jdt.core.prefs
===================================================================
--- trunk/P2PlayBoot/.settings/org.eclipse.jdt.core.prefs (rev 0)
+++ trunk/P2PlayBoot/.settings/org.eclipse.jdt.core.prefs 2007-01-22 11:38:13 UTC (rev 23)
@@ -0,0 +1,7 @@
+#Tue Jan 16 23:20:09 CET 2007
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
+org.eclipse.jdt.core.compiler.compliance=1.5
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.5
Added: trunk/P2PlayBoot/.settings/org.eclipse.jdt.ui.prefs
===================================================================
--- trunk/P2PlayBoot/.settings/org.eclipse.jdt.ui.prefs (rev 0)
+++ trunk/P2PlayBoot/.settings/org.eclipse.jdt.ui.prefs 2007-01-22 11:38:13 UTC (rev 23)
@@ -0,0 +1,3 @@
+#Tue Jan 16 21:03:57 CET 2007
+eclipse.preferences.version=1
+org.eclipse.jdt.ui.text.custom_code_templates=<?xml version\="1.0" encoding\="UTF-8"?><templates><template autoinsert\="true" context\="gettercomment_context" deleted\="false" description\="Comment for getter method" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.gettercomment" name\="gettercomment">/**\n * @return the ${bare_field_name}\n */</template><template autoinsert\="true" context\="settercomment_context" deleted\="false" description\="Comment for setter method" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.settercomment" name\="settercomment">/**\n * @param ${param} the ${bare_field_name} to set\n */</template><template autoinsert\="true" context\="constructorcomment_context" deleted\="false" description\="Comment for created constructors" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.constructorcomment" name\="constructorcomment">/**\n * ${tags}\n */</template><template autoinsert\="false" context\="filecomment_context" deleted\="false" description\="Comment for created Java files" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.filecomment" name\="filecomment">/*\n * Copyright ${year} P2Play.org\n * All rights reserved.\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n * \n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * Lesser General Public License for more details.\n * \n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA\n */</template><template autoinsert\="true" context\="typecomment_context" deleted\="false" description\="Comment for created types" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.typecomment" name\="typecomment">/**\n * @author ${user}\n *\n * ${tags}\n */</template><template autoinsert\="true" context\="fieldcomment_context" deleted\="false" description\="Comment for fields" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.fieldcomment" name\="fieldcomment">/**\n * \n */</template><template autoinsert\="true" context\="methodcomment_context" deleted\="false" description\="Comment for non-overriding methods" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.methodcomment" name\="methodcomment">/**\n * ${tags}\n */</template><template autoinsert\="true" context\="overridecomment_context" deleted\="false" description\="Comment for overriding methods" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.overridecomment" name\="overridecomment">/* (non-Javadoc)\n * ${see_to_overridden}\n */</template><template autoinsert\="true" context\="delegatecomment_context" deleted\="false" description\="Comment for delegate methods" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.delegatecomment" name\="delegatecomment">/**\n * ${tags}\n * ${see_to_target}\n */</template><template autoinsert\="true" context\="newtype_context" deleted\="false" description\="Newly created files" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.newtype" name\="newtype">${filecomment}\n${package_declaration}\n\n${typecomment}\n${type_declaration}</template><template autoinsert\="true" context\="classbody_context" deleted\="false" description\="Code in new class type bodies" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.classbody" name\="classbody">\n</template><template autoinsert\="true" context\="interfacebody_context" deleted\="false" description\="Code in new interface type bodies" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.interfacebody" name\="interfacebody">\n</template><template autoinsert\="true" context\="enumbody_context" deleted\="false" description\="Code in new enum type bodies" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.enumbody" name\="enumbody">\n</template><template autoinsert\="true" context\="annotationbody_context" deleted\="false" description\="Code in new annotation type bodies" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.annotationbody" name\="annotationbody">\n</template><template autoinsert\="true" context\="catchblock_context" deleted\="false" description\="Code in new catch blocks" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.catchblock" name\="catchblock">// ${todo} Auto-generated catch block\n${exception_var}.printStackTrace();</template><template autoinsert\="true" context\="methodbody_context" deleted\="false" description\="Code in created method stubs" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.methodbody" name\="methodbody">// ${todo} Auto-generated method stub\n${body_statement}</template><template autoinsert\="true" context\="constructorbody_context" deleted\="false" description\="Code in created constructor stubs" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.constructorbody" name\="constructorbody">${body_statement}\n// ${todo} Auto-generated constructor stub</template><template autoinsert\="true" context\="getterbody_context" deleted\="false" description\="Code in created getters" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.getterbody" name\="getterbody">return ${field};</template><template autoinsert\="true" context\="setterbody_context" deleted\="false" description\="Code in created setters" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.setterbody" name\="setterbody">${field} \= ${param};</template></templates>
Added: trunk/P2PlayBoot/.settings/org.eclipse.wst.common.component
===================================================================
--- trunk/P2PlayBoot/.settings/org.eclipse.wst.common.component (rev 0)
+++ trunk/P2PlayBoot/.settings/org.eclipse.wst.common.component 2007-01-22 11:38:13 UTC (rev 23)
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project-modules id="moduleCoreId" project-version="1.5.0">
+<wb-module deploy-name="P2PlayBoot">
+<wb-resource deploy-path="/" source-path="/src"/>
+</wb-module>
+</project-modules>
Added: trunk/P2PlayBoot/.settings/org.eclipse.wst.common.project.facet.core.xml
===================================================================
--- trunk/P2PlayBoot/.settings/org.eclipse.wst.common.project.facet.core.xml (rev 0)
+++ trunk/P2PlayBoot/.settings/org.eclipse.wst.common.project.facet.core.xml 2007-01-22 11:38:13 UTC (rev 23)
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<faceted-project>
+ <fixed facet="jst.java"/>
+ <fixed facet="jst.utility"/>
+ <installed facet="jst.utility" version="1.0"/>
+ <installed facet="jst.java" version="5.0"/>
+</faceted-project>
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ti...@us...> - 2007-01-22 11:23:53
|
Revision: 22
http://p2play.svn.sourceforge.net/p2play/?rev=22&view=rev
Author: tisoft
Date: 2007-01-22 03:23:52 -0800 (Mon, 22 Jan 2007)
Log Message:
-----------
Initial import of project structure.
Added Paths:
-----------
trunk/P2PlayAdmin/.classpath
trunk/P2PlayAdmin/.project
trunk/P2PlayAdmin/.settings/
trunk/P2PlayAdmin/.settings/org.eclipse.jdt.core.prefs
trunk/P2PlayAdmin/.settings/org.eclipse.jst.common.project.facet.core.prefs
trunk/P2PlayAdmin/.settings/org.eclipse.wst.common.component
trunk/P2PlayAdmin/.settings/org.eclipse.wst.common.project.facet.core.xml
trunk/P2PlayAdmin/.settings/org.eclipse.wst.validation.prefs
Added: trunk/P2PlayAdmin/.classpath
===================================================================
--- trunk/P2PlayAdmin/.classpath (rev 0)
+++ trunk/P2PlayAdmin/.classpath 2007-01-22 11:23:52 UTC (rev 22)
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.launching.macosx.MacOSXType/JVM 1.5.0 (MacOS X Default)"/>
+ <classpathentry kind="con" path="org.eclipse.jst.server.core.container/org.eclipse.jst.server.tomcat.runtimeTarget/Apache Tomcat v5.5"/>
+ <classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.web.container"/>
+ <classpathentry kind="var" path="GWT_HOME/gwt-user.jar"/>
+ <classpathentry kind="output" path="build/classes"/>
+</classpath>
Added: trunk/P2PlayAdmin/.project
===================================================================
--- trunk/P2PlayAdmin/.project (rev 0)
+++ trunk/P2PlayAdmin/.project 2007-01-22 11:23:52 UTC (rev 22)
@@ -0,0 +1,46 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>P2PlayAdmin</name>
+ <comment></comment>
+ <projects>
+ <project>P2Play</project>
+ <project>P2PlayBoot</project>
+ <project>Servers</project>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>com.googlipse.gwt.gwtBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.wst.common.project.facet.core.builder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.wst.validation.validationbuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>com.googlipse.gwt.gwtNature</nature>
+ <nature>org.eclipse.wst.common.project.facet.core.nature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ <nature>org.eclipse.wst.common.modulecore.ModuleCoreNature</nature>
+ <nature>org.eclipse.jem.workbench.JavaEMFNature</nature>
+ </natures>
+ <linkedResources>
+ <link>
+ <name>WebContent/WEB-INF/lib/gwt-servlet.jar</name>
+ <type>1</type>
+ <locationURI>GWT_HOME/gwt-servlet.jar</locationURI>
+ </link>
+ </linkedResources>
+</projectDescription>
Added: trunk/P2PlayAdmin/.settings/org.eclipse.jdt.core.prefs
===================================================================
--- trunk/P2PlayAdmin/.settings/org.eclipse.jdt.core.prefs (rev 0)
+++ trunk/P2PlayAdmin/.settings/org.eclipse.jdt.core.prefs 2007-01-22 11:23:52 UTC (rev 22)
@@ -0,0 +1,7 @@
+#Tue Jan 16 22:00:17 CET 2007
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
+org.eclipse.jdt.core.compiler.compliance=1.5
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.5
Added: trunk/P2PlayAdmin/.settings/org.eclipse.jst.common.project.facet.core.prefs
===================================================================
--- trunk/P2PlayAdmin/.settings/org.eclipse.jst.common.project.facet.core.prefs (rev 0)
+++ trunk/P2PlayAdmin/.settings/org.eclipse.jst.common.project.facet.core.prefs 2007-01-22 11:23:52 UTC (rev 22)
@@ -0,0 +1,4 @@
+#Tue Jan 16 22:00:18 CET 2007
+classpath.helper/org.eclipse.jdt.launching.JRE_CONTAINER\:\:org.eclipse.jdt.internal.launching.macosx.MacOSXType\:\:JVM\ 1.5.0\ (MacOS\ X\ Default)/owners=jst.java\:5.0
+classpath.helper/org.eclipse.jst.server.core.container\:\:org.eclipse.jst.server.tomcat.runtimeTarget\:\:Apache\ Tomcat\ v5.5/owners=jst.web\:2.4
+eclipse.preferences.version=1
Added: trunk/P2PlayAdmin/.settings/org.eclipse.wst.common.component
===================================================================
--- trunk/P2PlayAdmin/.settings/org.eclipse.wst.common.component (rev 0)
+++ trunk/P2PlayAdmin/.settings/org.eclipse.wst.common.component 2007-01-22 11:23:52 UTC (rev 22)
@@ -0,0 +1,40 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project-modules id="moduleCoreId" project-version="1.5.0">
+<wb-module deploy-name="P2PlayAdmin">
+<wb-resource deploy-path="/" source-path="/WebContent"/>
+<wb-resource deploy-path="/" source-path="/build/gwtOutput"/>
+<wb-resource deploy-path="/WEB-INF/classes" source-path="/src"/>
+<dependent-module deploy-path="/WEB-INF/lib" handle="module:/resource/P2Play/P2Play">
+<dependency-type>uses</dependency-type>
+</dependent-module>
+<dependent-module deploy-path="/WEB-INF/lib" handle="module:/classpath/lib/P2Play/lib/xstream-1.1.3.jar">
+<dependency-type>uses</dependency-type>
+</dependent-module>
+<dependent-module deploy-path="/WEB-INF/lib" handle="module:/classpath/lib/P2Play/lib/xpp3-1.1.3.4d_b2.jar">
+<dependency-type>uses</dependency-type>
+</dependent-module>
+<dependent-module deploy-path="/WEB-INF/lib" handle="module:/classpath/lib/P2Play/lib/pnuts.jar">
+<dependency-type>uses</dependency-type>
+</dependent-module>
+<dependent-module deploy-path="/WEB-INF/lib" handle="module:/classpath/lib/P2Play/lib/jdom.jar">
+<dependency-type>uses</dependency-type>
+</dependent-module>
+<dependent-module deploy-path="/WEB-INF/lib" handle="module:/classpath/lib/P2Play/lib/javolution.jar">
+<dependency-type>uses</dependency-type>
+</dependent-module>
+<dependent-module deploy-path="/WEB-INF/lib" handle="module:/classpath/lib/P2Play/lib/FreePastry.jar">
+<dependency-type>uses</dependency-type>
+</dependent-module>
+<dependent-module deploy-path="/WEB-INF/lib" handle="module:/resource/P2PlayBoot/P2PlayBoot">
+<dependency-type>uses</dependency-type>
+</dependent-module>
+<dependent-module deploy-path="/WEB-INF/lib" handle="module:/classpath/lib/P2PlayBoot/lib/commons-vfs-20070107.jar">
+<dependency-type>uses</dependency-type>
+</dependent-module>
+<dependent-module deploy-path="/WEB-INF/lib" handle="module:/classpath/lib/P2PlayBoot/lib/commons-logging-1.1.jar">
+<dependency-type>uses</dependency-type>
+</dependent-module>
+<property name="context-root" value="P2PlayAdmin"/>
+<property name="java-output-path" value="build/classes"/>
+</wb-module>
+</project-modules>
Added: trunk/P2PlayAdmin/.settings/org.eclipse.wst.common.project.facet.core.xml
===================================================================
--- trunk/P2PlayAdmin/.settings/org.eclipse.wst.common.project.facet.core.xml (rev 0)
+++ trunk/P2PlayAdmin/.settings/org.eclipse.wst.common.project.facet.core.xml 2007-01-22 11:23:52 UTC (rev 22)
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<faceted-project>
+ <runtime name="Apache Tomcat v5.5"/>
+ <fixed facet="jst.java"/>
+ <fixed facet="jst.web"/>
+ <installed facet="jst.web" version="2.4"/>
+ <installed facet="jst.java" version="5.0"/>
+ <installed facet="com.googlipse.gwt.gwtFacet" version="1.0"/>
+</faceted-project>
Added: trunk/P2PlayAdmin/.settings/org.eclipse.wst.validation.prefs
===================================================================
--- trunk/P2PlayAdmin/.settings/org.eclipse.wst.validation.prefs (rev 0)
+++ trunk/P2PlayAdmin/.settings/org.eclipse.wst.validation.prefs 2007-01-22 11:23:52 UTC (rev 22)
@@ -0,0 +1,6 @@
+#Fri Jan 19 13:22:55 CET 2007
+DELEGATES_PREFERENCE=delegateValidatorListorg.eclipse.wst.xsd.core.internal.validation.eclipse.XSDDelegatingValidator\=org.eclipse.wst.xsd.core.internal.validation.eclipse.Validator;org.eclipse.wst.wsdl.validation.internal.eclipse.WSDLDelegatingValidator\=org.eclipse.wst.wsdl.validation.internal.eclipse.Validator;
+USER_BUILD_PREFERENCE=enabledBuildValidatorListorg.eclipse.wst.html.internal.validation.HTMLValidator;org.eclipse.wst.xml.core.internal.validation.eclipse.Validator;org.eclipse.wst.xsd.core.internal.validation.eclipse.XSDDelegatingValidator;org.eclipse.wst.dtd.core.internal.validation.eclipse.Validator;org.eclipse.wst.wsi.ui.internal.WSIMessageValidator;org.eclipse.wst.common.componentcore.internal.ModuleCoreValidator;org.eclipse.wst.wsdl.validation.internal.eclipse.WSDLDelegatingValidator;org.eclipse.jst.jsp.core.internal.validation.JSPBatchValidator;
+USER_MANUAL_PREFERENCE=enabledManualValidatorListorg.eclipse.wst.html.internal.validation.HTMLValidator;org.eclipse.wst.xml.core.internal.validation.eclipse.Validator;org.eclipse.wst.xsd.core.internal.validation.eclipse.XSDDelegatingValidator;org.eclipse.wst.dtd.core.internal.validation.eclipse.Validator;org.eclipse.wst.wsi.ui.internal.WSIMessageValidator;org.eclipse.wst.common.componentcore.internal.ModuleCoreValidator;org.eclipse.wst.wsdl.validation.internal.eclipse.WSDLDelegatingValidator;org.eclipse.jst.jsp.core.internal.validation.JSPBatchValidator;
+USER_PREFERENCE=overrideGlobalPreferencestruedisableAllValidationfalseversion1.1.2.v200610162137
+eclipse.preferences.version=1
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ti...@us...> - 2007-01-22 11:01:55
|
Revision: 21
http://p2play.svn.sourceforge.net/p2play/?rev=21&view=rev
Author: tisoft
Date: 2007-01-22 03:01:43 -0800 (Mon, 22 Jan 2007)
Log Message:
-----------
Initial import.
Added Paths:
-----------
trunk/P2PlayAdmin/
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ti...@us...> - 2007-01-22 10:43:53
|
Revision: 20
http://p2play.svn.sourceforge.net/p2play/?rev=20&view=rev
Author: tisoft
Date: 2007-01-22 02:43:54 -0800 (Mon, 22 Jan 2007)
Log Message:
-----------
moved P2PlayBoot to trunk
Added Paths:
-----------
trunk/P2PlayBoot/
Removed Paths:
-------------
P2PlayBoot/
Copied: trunk/P2PlayBoot (from rev 19, P2PlayBoot)
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ti...@us...> - 2007-01-22 10:38:12
|
Revision: 19
http://p2play.svn.sourceforge.net/p2play/?rev=19&view=rev
Author: tisoft
Date: 2007-01-22 02:38:06 -0800 (Mon, 22 Jan 2007)
Log Message:
-----------
Initial import.
Added Paths:
-----------
P2PlayBoot/
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ti...@us...> - 2007-01-16 13:11:13
|
Revision: 18
http://p2play.svn.sourceforge.net/p2play/?rev=18&view=rev
Author: tisoft
Date: 2007-01-16 05:11:11 -0800 (Tue, 16 Jan 2007)
Log Message:
-----------
fixed not serializable exception
Modified Paths:
--------------
trunk/P2Play/src/org/p2play/resource/impl/ByteArrayResource.java
Modified: trunk/P2Play/src/org/p2play/resource/impl/ByteArrayResource.java
===================================================================
--- trunk/P2Play/src/org/p2play/resource/impl/ByteArrayResource.java 2006-12-30 20:30:03 UTC (rev 17)
+++ trunk/P2Play/src/org/p2play/resource/impl/ByteArrayResource.java 2007-01-16 13:11:11 UTC (rev 18)
@@ -66,16 +66,15 @@
}
public PastContentHandle getHandle(final Past local) {
- return new PastContentHandle(){
-
+ final NodeHandle handle=local.getLocalNodeHandle();
+ return new PastContentHandle() {
public Id getId() {
- return id;
+ return ByteArrayResource.this.getId();
}
-
public NodeHandle getNodeHandle() {
- return local.getLocalNodeHandle();
- }};
- }
+ return handle;
+ }
+ }; }
public Id getId() {
return id;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ti...@us...> - 2006-12-30 20:30:20
|
Revision: 17
http://p2play.svn.sourceforge.net/p2play/?rev=17&view=rev
Author: tisoft
Date: 2006-12-30 12:30:03 -0800 (Sat, 30 Dec 2006)
Log Message:
-----------
transfered from university cvs
added license header
changed package name to org.p2play.*
Added Paths:
-----------
trunk/P2Play/src/org/p2play/net/pastry/NetworkHandler.java
trunk/P2Play/src/org/p2play/net/pastry/RegionScribe.java
Added: trunk/P2Play/src/org/p2play/net/pastry/NetworkHandler.java
===================================================================
--- trunk/P2Play/src/org/p2play/net/pastry/NetworkHandler.java (rev 0)
+++ trunk/P2Play/src/org/p2play/net/pastry/NetworkHandler.java 2006-12-30 20:30:03 UTC (rev 17)
@@ -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.net.pastry;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.logging.Level;
+
+import org.p2play.io.Serializer;
+import org.p2play.net.region.GameAction;
+import org.p2play.net.region.GameState;
+import org.p2play.net.region.Region;
+import org.p2play.net.region.RegionInstance;
+import org.p2play.net.region.RegionManager;
+import org.p2play.net.region.message.GameActionMessage;
+import org.p2play.net.region.message.GameStateHashMessage;
+import org.p2play.net.region.message.GameStateMessage;
+import org.p2play.net.region.message.JoinMessage;
+import org.p2play.net.region.message.MessageDeserializer;
+import org.p2play.net.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/net/pastry/RegionScribe.java
===================================================================
--- trunk/P2Play/src/org/p2play/net/pastry/RegionScribe.java (rev 0)
+++ trunk/P2Play/src/org/p2play/net/pastry/RegionScribe.java 2006-12-30 20:30:03 UTC (rev 17)
@@ -0,0 +1,41 @@
+package org.p2play.net.pastry;
+
+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;
+ }
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ti...@us...> - 2006-12-27 18:19:50
|
Revision: 16
http://p2play.svn.sourceforge.net/p2play/?rev=16&view=rev
Author: tisoft
Date: 2006-12-27 10:19:51 -0800 (Wed, 27 Dec 2006)
Log Message:
-----------
transfered from university cvs
added license header
changed package name to org.p2play.*
Added Paths:
-----------
trunk/P2Play/src/org/p2play/scripting/pnuts/PnutsSerializer.java
trunk/P2Play/src/org/p2play/scripting/pnuts/PnutsServer.java
trunk/P2Play/src/org/p2play/scripting/pnuts/PnutsServerFactory.java
Added: trunk/P2Play/src/org/p2play/scripting/pnuts/PnutsSerializer.java
===================================================================
--- trunk/P2Play/src/org/p2play/scripting/pnuts/PnutsSerializer.java (rev 0)
+++ trunk/P2Play/src/org/p2play/scripting/pnuts/PnutsSerializer.java 2006-12-27 18:19:51 UTC (rev 16)
@@ -0,0 +1,40 @@
+/*
+ * 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.scripting.pnuts;
+
+import java.io.IOException;
+
+import org.p2play.io.Serializer;
+import org.p2play.scripting.pnuts.object.GameObject;
+
+import rice.p2p.commonapi.rawserialization.InputBuffer;
+import rice.p2p.commonapi.rawserialization.OutputBuffer;
+
+public class PnutsSerializer implements Serializer {
+
+ public Object deserialize(InputBuffer inputBuffer) throws IOException {
+ return GameObject.deserializeObject(inputBuffer);
+ }
+
+ public void serialize(Object object, OutputBuffer outputBuffer)
+ throws IOException {
+ GameObject.serializeObject(outputBuffer, object);
+ }
+
+}
Added: trunk/P2Play/src/org/p2play/scripting/pnuts/PnutsServer.java
===================================================================
--- trunk/P2Play/src/org/p2play/scripting/pnuts/PnutsServer.java (rev 0)
+++ trunk/P2Play/src/org/p2play/scripting/pnuts/PnutsServer.java 2006-12-27 18:19:51 UTC (rev 16)
@@ -0,0 +1,156 @@
+/*
+ * 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.scripting.pnuts;
+
+import java.util.Iterator;
+import java.util.LinkedList;
+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.resource.ResourceClassLoader;
+import org.p2play.scripting.pnuts.api.object.ObjectAPI;
+import org.p2play.scripting.pnuts.api.region.RegionChangeAPI;
+import org.p2play.scripting.pnuts.api.region.RegionChangeGameAction;
+import org.p2play.scripting.pnuts.manager.PackageHandler;
+import org.p2play.scripting.pnuts.object.GameDescriptor;
+import org.p2play.scripting.pnuts.object.GameObject;
+import org.p2play.scripting.pnuts.object.GameStateObject;
+
+import pnuts.lang.Context;
+import pnuts.lang.Pnuts;
+import pnuts.lang.PnutsFunction;
+
+public class PnutsServer implements Server {
+
+ private Pnuts pnuts;
+
+ private Region region;
+
+ private PnutsHandler pnutsHandler;
+
+ private GameDescriptor gameDescriptor;
+
+ private Random random;
+
+ public PnutsServer(RegionChangeAPI regionChangeAPI, Region region) {
+ this.region = region;
+
+ System.out.println(region);
+
+ gameDescriptor = GameDescriptor.getGameDescriptor(region.getGame());
+
+ PackageHandler packageHandler = new PackageHandler();
+
+ regionChangeAPI.registerAPI(region, packageHandler);
+
+ ObjectAPI objectAPI = new ObjectAPI(gameDescriptor);
+ objectAPI.registerAPI(packageHandler);
+
+ // TODO: make script api
+ packageHandler.getRootPackage().set("random", new PnutsFunction(){@Override
+ public boolean defined(int narg) {
+ return narg==1;
+ }
+
+ @Override
+ protected Object exec(Object[] args, Context context) {
+ return getRandom().nextInt((Integer)args[0]);
+ }});
+
+ // NutCracker.debug=true;
+
+ pnutsHandler = new PnutsHandler(packageHandler);
+
+ pnuts = pnutsHandler.getPnuts(ResourceClassLoader
+ .getResourceClassLoader().getResourceAsStream(
+ gameDescriptor.getServerScript()));
+
+ pnutsHandler.execute(pnuts);
+ }
+
+ public Random getRandom() {
+ return random;
+ }
+
+ public void assignGameObject(GameState gamestate, GameObject object,
+ Region region) {
+ synchronized (gamestate) {
+ pnutsHandler.callFunction("assignGameObject", gamestate, object,
+ region);
+ }
+ }
+
+ public Region getRegion() {
+ return region;
+ }
+
+ public List<Region> getNeighbourRegionIdentifiers() {
+ return gameDescriptor.getNeighbourRegionIdentifiers(region);
+ }
+
+ public boolean isEmpty(GameState gameState) {
+ return (Boolean) pnutsHandler.callFunction(gameDescriptor
+ .getEmptyFunction(), gameState);
+ }
+
+ public final GameState tick(GameState abstractGameState,
+ List<GameAction> interactions) {
+ synchronized (abstractGameState) {
+
+ random=abstractGameState.getRandom();
+
+ if (interactions == null) {
+ interactions = new LinkedList<GameAction>();
+ }
+ abstractGameState.tick();
+
+ Iterator iterator = interactions.iterator();
+ while (iterator.hasNext()) {
+ GameAction element = (GameAction) iterator.next();
+
+ if (element instanceof RegionChangeGameAction) {// TODO: darf
+ // die
+ // gameaction
+ // \x9Fberhaupt
+ // verarbeitet
+ // werden?
+ RegionChangeGameAction rcga = (RegionChangeGameAction) element;
+
+ assignGameObject(abstractGameState, rcga.getGameObject(),
+ rcga.getSourceRegion());
+
+ iterator.remove();
+ }
+ }
+
+ return (GameState) pnutsHandler.callFunction("tick",
+ abstractGameState, interactions);
+ }
+ }
+
+ public GameState init(long gameTime, long randomSeed) {
+ GameStateObject gameState = gameDescriptor.getGameStateClass()
+ .createInstance(region, gameTime);
+ return (GameState) pnutsHandler.callFunction("init", gameState);
+ }
+}
\ No newline at end of file
Added: trunk/P2Play/src/org/p2play/scripting/pnuts/PnutsServerFactory.java
===================================================================
--- trunk/P2Play/src/org/p2play/scripting/pnuts/PnutsServerFactory.java (rev 0)
+++ trunk/P2Play/src/org/p2play/scripting/pnuts/PnutsServerFactory.java 2006-12-27 18:19:51 UTC (rev 16)
@@ -0,0 +1,40 @@
+/*
+ * 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.scripting.pnuts;
+
+import org.p2play.net.region.Region;
+import org.p2play.net.region.Server;
+import org.p2play.net.region.ServerFactory;
+import org.p2play.scripting.pnuts.api.region.RegionChangeAPI;
+
+
+public class PnutsServerFactory implements ServerFactory {
+ private RegionChangeAPI regionChangeAPI;
+
+ public PnutsServerFactory(RegionChangeAPI regionChangeAPI) {
+ super();
+ this.regionChangeAPI = regionChangeAPI;
+ }
+
+ public Server getServer(Region region) {
+ System.out.println(region);
+ return new PnutsServer(regionChangeAPI, region);
+ }
+
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ti...@us...> - 2006-12-27 18:09:23
|
Revision: 15
http://p2play.svn.sourceforge.net/p2play/?rev=15&view=rev
Author: tisoft
Date: 2006-12-27 10:09:23 -0800 (Wed, 27 Dec 2006)
Log Message:
-----------
transfered from university cvs
added license header
changed package name to org.p2play.*
Added Paths:
-----------
trunk/P2Play/src/org/p2play/scripting/pnuts/api/region/
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
Added: trunk/P2Play/src/org/p2play/scripting/pnuts/api/region/RegionAPI.java
===================================================================
--- trunk/P2Play/src/org/p2play/scripting/pnuts/api/region/RegionAPI.java (rev 0)
+++ trunk/P2Play/src/org/p2play/scripting/pnuts/api/region/RegionAPI.java 2006-12-27 18:09:23 UTC (rev 15)
@@ -0,0 +1,180 @@
+/*
+ * 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.scripting.pnuts.api.region;
+
+import java.util.Iterator;
+
+import org.p2play.net.region.Client;
+import org.p2play.net.region.GameAction;
+import org.p2play.net.region.GameState;
+import org.p2play.net.region.Region;
+import org.p2play.net.region.RegionManager;
+import org.p2play.scripting.pnuts.api.object.ObjectAPI;
+import org.p2play.scripting.pnuts.manager.PackageHandler;
+import org.p2play.scripting.pnuts.object.GameActionClass;
+import org.p2play.scripting.pnuts.object.GameDescriptor;
+import org.p2play.scripting.pnuts.object.GameObject;
+import org.p2play.util.ListMap;
+
+import pnuts.lang.Context;
+import pnuts.lang.Package;
+import pnuts.lang.PnutsFunction;
+
+/**
+ * The almighty RegionAPI to make calls on the regionManager via Pnuts
+ * Here you can join and leave regions in our pastry network,
+ * send gameActions
+ * @author markus
+ *
+ */
+public class RegionAPI implements Client {
+
+ RegionManager regionManager;
+ private ListMap<Region, RegionDelegate> callbackMap;
+
+ public RegionAPI(RegionManager regionManager){
+ this.regionManager = regionManager;
+ this.callbackMap = new ListMap<Region, RegionDelegate>();
+ }
+
+ /**
+ * Joins the region with the name "regionName" and adds it to the local region map
+ * Additionally the ObjectAPI for the specified region is registered
+ * @param context the Pnuts context
+ * @param regionName the name of the region to join
+ * @param callback the Pnuts callback function
+ * @return
+ */
+ public RegionDelegate joinRegion(Context context, Region regionName, PnutsFunction receivedFunction, PnutsFunction changeFunction) {
+ RegionDelegate region = new RegionDelegate(this, context, regionName, receivedFunction, changeFunction);
+ joinRegion(context, region);
+ return region;
+ }
+
+ void joinRegion(Context context, RegionDelegate region) {
+ synchronized (callbackMap) {
+ callbackMap.add(region.getRegion(), region);
+ }
+ GameDescriptor gameDescriptor=GameDescriptor.getGameDescriptor(region.getRegion().getGame());
+
+ PackageHandler packageHandler=new PackageHandler();
+ packageHandler.putPackage("ROOT", context.getCurrentPackage());
+ ObjectAPI objectAPI=new ObjectAPI(gameDescriptor);
+ objectAPI.registerAPI(packageHandler);
+
+ //set region name
+ Iterator<GameActionClass> iterator=gameDescriptor.getGameActionMap().values().iterator();
+ while (iterator.hasNext()) {
+ GameActionClass element = iterator.next();
+ element.setRegion(region.getRegion());
+ }
+
+ regionManager.joinRegion(region.getRegion(),this);
+ }
+
+ /**
+ * Leaves the region if it is in the region map.
+ * If it is not in the local region map --> nothing to do.
+ * @param region the region to leave
+ */
+ public void leaveRegion(RegionDelegate region) {
+ callbackMap.remove(region.getRegion(),region);
+ if(callbackMap.isEmpty(region.getRegion()))
+ regionManager.leaveRegion(region.getRegion(),this);
+ }
+
+ /**
+ * Registers the RegionAPI functions in the root package of Pnuts.
+ * Only the joinRegion function is defined yet!
+ * @param scriptAPI the ScriptAPI from the scriptmanager
+ */
+ public void registerAPI(PackageHandler packageHandler) {
+ Package chatPackage = packageHandler.getRootPackage();
+ // Root package for now
+
+ PackageHandler.addFunction(chatPackage, "joinRegion",
+ new PnutsFunction() {
+
+ @Override
+ public boolean defined(int narg) {
+ return narg == 3;
+ }
+
+ @Override
+ protected Object exec(Object[] args, Context context) {
+ return joinRegion(context, (Region) args[0], (PnutsFunction) args[1], (PnutsFunction) args[2]);
+
+ }
+ });
+
+ PackageHandler.addFunction(chatPackage, "loadGame",
+ new PnutsFunction() {
+
+ @Override
+ public boolean defined(int narg) {
+ return narg == 1;
+ }
+
+ @Override
+ protected Object exec(Object[] args, Context context) {
+ loadGame(context, (String)args[0]);
+ return null;
+ }
+ });
+
+ }
+
+ public void loadGame(Context context,String game){
+ GameDescriptor gameDescriptor=GameDescriptor.getGameDescriptor(game);
+
+ PackageHandler packageHandler=new PackageHandler(context.getCurrentPackage());
+ ObjectAPI objectAPI=new ObjectAPI(gameDescriptor);
+ objectAPI.registerAPI(packageHandler);
+
+ }
+
+ /**
+ * Executes the given gameAction
+ * @param gameAction what do you want to do today
+ */
+ public void sendAction(GameAction gameAction){
+ regionManager.scheduleInteraction(this,gameAction);
+ }
+
+ /* (non-Javadoc)
+ * @see de.upb.mmog.net.region.Client#handleGameStateChanged(java.lang.String, de.upb.mmog.net.region.GameState)
+ */
+ public void handleGameStateChanged(Region region, GameState gameState) {
+ Iterator<RegionDelegate> iterator=callbackMap.clonedIterator(region);
+ while (iterator.hasNext()) {
+ RegionDelegate region2 = iterator.next();
+
+ region2.gameStateReceived(gameState);
+ }
+ }
+
+ public void handleRegionChange(Region oldRegion, Region newRegion, Object gameObject) {
+ Iterator<RegionDelegate> iterator=callbackMap.clonedIterator(oldRegion);
+ while (iterator.hasNext()) {
+ RegionDelegate region2 = iterator.next();
+
+ region2.regionChangeReceived(newRegion, (GameObject)gameObject);
+ }
+ }
+}
Added: trunk/P2Play/src/org/p2play/scripting/pnuts/api/region/RegionChangeAPI.java
===================================================================
--- trunk/P2Play/src/org/p2play/scripting/pnuts/api/region/RegionChangeAPI.java (rev 0)
+++ trunk/P2Play/src/org/p2play/scripting/pnuts/api/region/RegionChangeAPI.java 2006-12-27 18:09:23 UTC (rev 15)
@@ -0,0 +1,83 @@
+/*
+ * 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.scripting.pnuts.api.region;
+
+import org.p2play.net.region.Region;
+import org.p2play.net.region.RegionManager;
+import org.p2play.scripting.pnuts.manager.PackageHandler;
+import org.p2play.scripting.pnuts.object.GameObject;
+
+import pnuts.lang.Context;
+import pnuts.lang.Package;
+import pnuts.lang.PnutsFunction;
+
+public class RegionChangeAPI {
+ private RegionManager regionManager;
+
+ public RegionChangeAPI(RegionManager regionManager) {
+ super();
+ this.regionManager = regionManager;
+ }
+
+ public RegionChangeAPI() {
+ this(null);
+ }
+
+ public void setRegionManager(RegionManager regionManager) {
+ this.regionManager = regionManager;
+ }
+
+ /**
+ * Registers the RegionAPI functions in the root package of Pnuts. Only the
+ * joinRegion function is defined yet!
+ *
+ * @param scriptAPI
+ * the ScriptAPI from the scriptmanager
+ */
+ public void registerAPI(final Region region, PackageHandler packageHandler) {
+ if (regionManager == null)
+ throw new IllegalStateException("No region manager was set!");
+
+ Package chatPackage = packageHandler.getRootPackage();
+ // Root package for now
+
+ PackageHandler.addFunction(chatPackage, "changeRegion",
+ new PnutsFunction() {
+
+ @Override
+ public boolean defined(int narg) {
+ return narg == 2;
+ }
+
+ @Override
+ protected Object exec(Object[] args, Context context) {
+ changeRegion(context, region, (Region) args[0],
+ (GameObject) args[1]);
+ return null;
+ }
+ });
+
+ }
+
+ protected void changeRegion(Context context, Region srcRegion,
+ Region trgRegion, GameObject object) {
+ regionManager.scheduleInteraction(null, new RegionChangeGameAction(
+ srcRegion, trgRegion, object));
+ }
+}
Added: trunk/P2Play/src/org/p2play/scripting/pnuts/api/region/RegionChangeGameAction.java
===================================================================
--- trunk/P2Play/src/org/p2play/scripting/pnuts/api/region/RegionChangeGameAction.java (rev 0)
+++ trunk/P2Play/src/org/p2play/scripting/pnuts/api/region/RegionChangeGameAction.java 2006-12-27 18:09:23 UTC (rev 15)
@@ -0,0 +1,60 @@
+/*
+ * 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.scripting.pnuts.api.region;
+
+import org.p2play.net.region.GameAction;
+import org.p2play.net.region.Region;
+import org.p2play.scripting.pnuts.object.GameObject;
+
+
+public class RegionChangeGameAction implements GameAction {
+ private GameObject gameObject;
+
+ private Region sourceRegion;
+
+ private Region region;
+
+ public RegionChangeGameAction(Region sourceRegion, Region region,
+ GameObject gameObject) {
+ super();
+ this.sourceRegion = sourceRegion;
+ this.region = region;
+ this.gameObject = gameObject;
+ }
+
+ public Region getRegion() {
+ return region;
+ }
+
+ public GameObject getGameObject() {
+ return gameObject;
+ }
+
+ public Region getSourceRegion() {
+ return sourceRegion;
+ }
+
+ public long getGameTime() {
+ return 0;
+ }
+
+ public boolean sendToAll() {
+ return true;
+ }
+}
Added: trunk/P2Play/src/org/p2play/scripting/pnuts/api/region/RegionDelegate.java
===================================================================
--- trunk/P2Play/src/org/p2play/scripting/pnuts/api/region/RegionDelegate.java (rev 0)
+++ trunk/P2Play/src/org/p2play/scripting/pnuts/api/region/RegionDelegate.java 2006-12-27 18:09:23 UTC (rev 15)
@@ -0,0 +1,65 @@
+/*
+ * 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.scripting.pnuts.api.region;
+
+import org.p2play.net.region.GameAction;
+import org.p2play.net.region.GameState;
+import org.p2play.net.region.Region;
+import org.p2play.scripting.pnuts.object.GameObject;
+
+import pnuts.lang.Context;
+import pnuts.lang.PnutsFunction;
+
+public class RegionDelegate {
+ private Region region;
+ private RegionAPI regionAPI;
+ private Context context;
+ private PnutsFunction receivedFunction;
+ private PnutsFunction changeFunction;
+
+ public RegionDelegate( RegionAPI regionAPI, Context context, Region regionName, PnutsFunction receivedFunction, PnutsFunction changeFunction) {
+ this.regionAPI=regionAPI;
+ this.region=regionName;
+ this.context=context;
+ this.receivedFunction=receivedFunction;
+ this.changeFunction=changeFunction;
+ }
+
+ public void sendGameAction(GameAction action){
+ regionAPI.sendAction(action);
+ }
+
+ public void leaveRegion(){
+ regionAPI.leaveRegion(this);
+ }
+
+ public Region getRegion() {
+ return region;
+ }
+
+ void gameStateReceived(GameState gameState){
+ receivedFunction.call(new Object[]{this,gameState},context);
+ }
+
+ void regionChangeReceived(Region newRegion, GameObject object){
+ RegionDelegate newRegionDelegate=new RegionDelegate(regionAPI,context,newRegion,receivedFunction,changeFunction);
+ if((Boolean)changeFunction.call(new Object[]{this,newRegionDelegate,object}, context))
+ regionAPI.joinRegion(context, newRegionDelegate);
+ }
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ti...@us...> - 2006-12-27 18:05:33
|
Revision: 14
http://p2play.svn.sourceforge.net/p2play/?rev=14&view=rev
Author: tisoft
Date: 2006-12-27 10:05:30 -0800 (Wed, 27 Dec 2006)
Log Message:
-----------
transfered from university cvs
added license header
changed package name to org.p2play.*
Added Paths:
-----------
trunk/P2Play/src/org/p2play/scripting/pnuts/api/object/
trunk/P2Play/src/org/p2play/scripting/pnuts/api/object/ObjectAPI.java
trunk/P2Play/src/org/p2play/scripting/pnuts/object/
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/GameClass.java
trunk/P2Play/src/org/p2play/scripting/pnuts/object/GameDescriptor.java
trunk/P2Play/src/org/p2play/scripting/pnuts/object/GameField.java
trunk/P2Play/src/org/p2play/scripting/pnuts/object/GameList.java
trunk/P2Play/src/org/p2play/scripting/pnuts/object/GameMap.java
trunk/P2Play/src/org/p2play/scripting/pnuts/object/GameObject.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/RegionClass.java
trunk/P2Play/src/org/p2play/scripting/pnuts/object/RegionObject.java
Added: trunk/P2Play/src/org/p2play/scripting/pnuts/api/object/ObjectAPI.java
===================================================================
--- trunk/P2Play/src/org/p2play/scripting/pnuts/api/object/ObjectAPI.java (rev 0)
+++ trunk/P2Play/src/org/p2play/scripting/pnuts/api/object/ObjectAPI.java 2006-12-27 18:05:30 UTC (rev 14)
@@ -0,0 +1,180 @@
+/*
+ * 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.scripting.pnuts.api.object;
+
+import java.util.Iterator;
+
+import org.p2play.scripting.pnuts.api.ScriptAPI;
+import org.p2play.scripting.pnuts.manager.PackageHandler;
+import org.p2play.scripting.pnuts.object.GameClass;
+import org.p2play.scripting.pnuts.object.GameDescriptor;
+import org.p2play.scripting.pnuts.object.GameField;
+import org.p2play.scripting.pnuts.object.GameList;
+import org.p2play.scripting.pnuts.object.GameMap;
+
+import pnuts.lang.Context;
+import pnuts.lang.Package;
+import pnuts.lang.PnutsFunction;
+
+/**
+ *
+ * @author tisoft_media
+ *
+ */
+public class ObjectAPI implements ScriptAPI{
+ private GameDescriptor gameDescriptor;
+
+ public ObjectAPI(GameDescriptor gameDescriptor) {
+ this.gameDescriptor=gameDescriptor;
+ }
+
+ public void registerAPI(PackageHandler packageHandler) {
+ Package chatPackage = packageHandler.getRootPackage();//TODO: Root package for now
+
+ // Register predifined first (Map and List)
+ PackageHandler.addFunction(chatPackage, "Map", new PnutsFunction("Map") {
+
+ @Override
+ public boolean defined(int narg) {
+ return true;// todo check max arhs
+ }
+
+ @Override
+ protected Object exec(Object[] args, Context context) {
+ return createGameMap(context, args);
+
+ }
+
+ });
+
+ PackageHandler.addFunction(chatPackage, "Field", new PnutsFunction(
+ "Field") {
+
+ @Override
+ public boolean defined(int narg) {
+ return true;// todo check max arhs
+ }
+
+ @Override
+ protected Object exec(Object[] args, Context context) {
+ return createGameField(context, args);
+
+ }
+
+ });
+
+ PackageHandler.addFunction(chatPackage, "List",
+ new PnutsFunction("List") {
+
+ @Override
+ public boolean defined(int narg) {
+ return true;// todo check max arhs
+ }
+
+ @Override
+ protected Object exec(Object[] args, Context context) {
+ return createGameList(context, args);
+
+ }
+
+ });
+
+ Iterator<String> names = gameDescriptor.getGameActionMap().keySet()
+ .iterator();
+ while (names.hasNext()) {
+ String name = names.next().intern();
+
+ final GameClass clazz = gameDescriptor.getGameActionMap().get(name);
+
+ PackageHandler.addFunction(chatPackage, name,
+ new PnutsFunction(name) {
+
+ @Override
+ public boolean defined(int narg) {
+ return true;// todo check max arhs
+ }
+
+ @Override
+ protected Object exec(Object[] args, Context context) {
+ return createInstance(context, clazz, args);
+
+ }
+
+ });
+
+ }
+
+ names = gameDescriptor.getGameClassMap().keySet().iterator();
+ while (names.hasNext()) {
+ String name = names.next().intern();
+
+ final GameClass clazz = gameDescriptor.getGameClassMap().get(name);
+
+ PackageHandler.addFunction(chatPackage, name,
+ new PnutsFunction(name) {
+
+ @Override
+ public boolean defined(int narg) {
+ return true;// todo check max arhs
+ }
+
+ @Override
+ protected Object exec(Object[] args, Context context) {
+ return createInstance(context, clazz, args);
+
+ }
+
+ });
+
+ }
+
+ //finally register the reguion
+ PackageHandler.addFunction(chatPackage, gameDescriptor.getRegionClass().getType(), new PnutsFunction(gameDescriptor.getRegionClass().getType()) {
+
+ @Override
+ public boolean defined(int narg) {
+ return true;// todo check max args
+ }
+
+ @Override
+ protected Object exec(Object[] args, Context context) {
+ return createInstance(context, gameDescriptor.getRegionClass(), args);
+
+ }
+
+ });
+ }
+
+ private Object createInstance(Context context, GameClass prototype,
+ Object[] args) {
+ return prototype.createInstance(args);
+ }
+
+ private Object createGameMap(Context context, Object[] args) {
+ return new GameMap();
+ }
+
+ private Object createGameField(Context context, Object[] args) {
+ return new GameField();
+ }
+
+ private Object createGameList(Context context, Object[] args) {
+ return new GameList();
+ }
+}
\ No newline at end of file
Added: trunk/P2Play/src/org/p2play/scripting/pnuts/object/GameActionClass.java
===================================================================
--- trunk/P2Play/src/org/p2play/scripting/pnuts/object/GameActionClass.java (rev 0)
+++ trunk/P2Play/src/org/p2play/scripting/pnuts/object/GameActionClass.java 2006-12-27 18:05:30 UTC (rev 14)
@@ -0,0 +1,53 @@
+/*
+ * 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.scripting.pnuts.object;
+
+import org.jdom.Element;
+import org.p2play.net.region.Region;
+
+public class GameActionClass extends GameClass {
+
+ private Region region;
+
+ public GameActionClass(String game, String name, Element element) {
+ super(game, name, element);
+ }
+
+ public void setRegion(Region region) {
+ this.region = region;
+ }
+
+ @Override
+ public GameObject createInstance(Object... objects) {
+ GameObject gameObject= new GameActionObject(this,region);
+
+ if(objects!=null){
+ for (int i = 0; i < objects.length; i++) {
+ try{
+ gameObject.set(getVariable(i), objects[i]);
+ }
+ catch(Exception e){
+ throw new IllegalArgumentException("Too many parameters in Constructor for "+getType());
+ }
+ }
+ }
+
+ return gameObject;
+ }
+}
Added: trunk/P2Play/src/org/p2play/scripting/pnuts/object/GameActionObject.java
===================================================================
--- trunk/P2Play/src/org/p2play/scripting/pnuts/object/GameActionObject.java (rev 0)
+++ trunk/P2Play/src/org/p2play/scripting/pnuts/object/GameActionObject.java 2006-12-27 18:05:30 UTC (rev 14)
@@ -0,0 +1,79 @@
+/*
+ * 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.scripting.pnuts.object;
+
+import java.io.IOException;
+
+import org.p2play.net.region.GameAction;
+import org.p2play.net.region.Region;
+
+import pnuts.lang.Context;
+import rice.p2p.commonapi.rawserialization.InputBuffer;
+import rice.p2p.commonapi.rawserialization.OutputBuffer;
+
+public class GameActionObject extends GameObject implements GameAction {
+
+ private Region region;
+
+ public GameActionObject(GameClass gameClass, Region region) {
+ super(gameClass);
+ this.region = region;
+ }
+
+ public GameActionObject(InputBuffer buffer) throws IOException {
+ super(buffer);
+ region = (Region) deserializeObject(buffer);
+ }
+
+ public long getGameTime() {
+ return 0;
+ }
+
+ public Region getRegion() {
+ return region;
+ }
+
+ @Override
+ public Object get(String name, Context context) {
+ if ("Type".equals(name)) {
+ return getType().intern();
+ } else {
+ return super.get(name, context);
+ }
+ }
+
+ @Override
+ public GameClass getGameClass() {
+ if (super.getGameClass() == null)
+ setGameClass(GameDescriptor.getGameDescriptor(getGame())
+ .getGameActionMap().get(getType()));
+ return super.getGameClass();
+ }
+
+ public boolean sendToAll() {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ @Override
+ public void doSerialize(OutputBuffer buffer) throws IOException {
+ super.doSerialize(buffer);
+ serializeObject(buffer, region);
+ }
+}
Added: trunk/P2Play/src/org/p2play/scripting/pnuts/object/GameClass.java
===================================================================
--- trunk/P2Play/src/org/p2play/scripting/pnuts/object/GameClass.java (rev 0)
+++ trunk/P2Play/src/org/p2play/scripting/pnuts/object/GameClass.java 2006-12-27 18:05:30 UTC (rev 14)
@@ -0,0 +1,173 @@
+/*
+ * 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.scripting.pnuts.object;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+
+import org.jdom.Element;
+
+public class GameClass {
+ private Map<String, Object> variableMap; // Name,Type
+ private List<String> variableList;
+
+ private String type;
+
+ private Element element;
+
+ private String game;
+
+ public GameClass(String game, String name, Element element) {
+ super();
+ this.game=game;
+ this.type = name;
+ this.element = element;
+ variableMap = new HashMap<String, Object>();
+ variableList=new LinkedList<String>();
+ }
+
+ @SuppressWarnings("unchecked")
+ void parse(HashMap<String, GameClass> classMap) {
+ Iterator<Element> varElementIterator = element.getChildren("var")
+ .iterator();
+
+ while (varElementIterator.hasNext()) {
+ Element element = varElementIterator.next();
+
+ String name = element.getAttributeValue("name").trim();
+ String type = element.getAttributeValue("type").trim();
+
+ if (classMap.containsKey(type)) {
+ // its a userdefined class
+ addVariable(name, classMap.get(type));
+ } else if (type.equals("List")) {
+ addVariable(name, List.class);
+ } else if (type.equals("Field")) {
+ addVariable(name, GameField.class);
+ }else if (type.equals("Map")) {
+ addVariable(name, Map.class);
+ } else if (type.equals("String")) {
+ addVariable(name, String.class);
+ } else if (convertPrimitiveFromString(type) != null) {
+ addVariable(name, convertPrimitiveFromString(type));
+ } else if (type.equals("any")) {
+ addVariable(name, Object.class);
+ }
+ }
+
+ System.out.println(getType() + ": " + variableMap);
+ }
+
+ void addVariable(String name, Object type){
+ variableMap.put(name, type);
+ variableList.add(name);
+ }
+
+ String getVariable(int index){
+ return variableList.get(index);
+ }
+
+ Iterator<String> iteratorOfVariables(){
+ return variableList.iterator();
+ }
+
+ public String getType() {
+ return type;
+ }
+
+ public String getGame() {
+ return game;
+ }
+
+ public void checkVariable(String name, Object value) {
+ //System.out.println("Checking: "+name+" ("+variableMap.get(name)+")="+value);
+ if(variableMap.get(name)==null)
+ throw new RuntimeException(new IllegalAccessException("Variable "+name+" is not defined for type "+getType()));
+ //TODO: typecheck
+ }
+
+ public GameObject createInstance(Object... objects){
+ GameObject gameObject= new GameObject(this);
+
+ fillObject(gameObject, objects);
+
+ return gameObject;
+ }
+
+ protected void fillObject(GameObject gameObject, Object... objects) {
+ if(objects!=null){
+ for (int i = 0; i < objects.length; i++) {
+ try{
+ gameObject.set(getVariable(i), objects[i]);
+ }
+ catch(Exception e){
+ throw new IllegalArgumentException("Too many parameters in Constructor for "+getType());
+ }
+ }
+ }
+ }
+
+ public Class convertPrimitiveFromString(String s) {
+ if (s.equalsIgnoreCase("boolean"))
+ return Boolean.class;
+ if (s.equalsIgnoreCase("char"))
+ return Character.class;
+ if (s.equalsIgnoreCase("byte"))
+ return Byte.class;
+ if (s.equalsIgnoreCase("short"))
+ return Short.class;
+ if (s.equalsIgnoreCase("int"))
+ return Integer.class;
+ if (s.equalsIgnoreCase("long"))
+ return Long.class;
+ if (s.equalsIgnoreCase("float"))
+ return Float.class;
+ if (s.equalsIgnoreCase("double"))
+ return Double.class;
+ return null;
+ }
+
+ public static Class convertPrimitive(Class c) {
+ if (c == boolean.class)
+ return Boolean.class;
+ if (c == char.class)
+ return Character.class;
+ if (c == byte.class)
+ return Byte.class;
+ if (c == short.class)
+ return Short.class;
+ if (c == int.class)
+ return Integer.class;
+ if (c == long.class)
+ return Long.class;
+ if (c == float.class)
+ return Float.class;
+ if (c == double.class)
+ return Double.class;
+ return c;
+ }
+
+ public static boolean isPrimitive(Object object){
+ return object.getClass().isPrimitive();
+ }
+
+}
Added: trunk/P2Play/src/org/p2play/scripting/pnuts/object/GameDescriptor.java
===================================================================
--- trunk/P2Play/src/org/p2play/scripting/pnuts/object/GameDescriptor.java (rev 0)
+++ trunk/P2Play/src/org/p2play/scripting/pnuts/object/GameDescriptor.java 2006-12-27 18:05:30 UTC (rev 14)
@@ -0,0 +1,253 @@
+/*
+ * 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.scripting.pnuts.object;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+
+import org.jdom.Document;
+import org.jdom.Element;
+import org.jdom.JDOMException;
+import org.jdom.input.SAXBuilder;
+import org.p2play.net.region.GameState;
+import org.p2play.net.region.Region;
+import org.p2play.resource.ResourceClassLoader;
+import org.p2play.scripting.pnuts.PnutsHandler;
+import org.p2play.scripting.pnuts.api.object.ObjectAPI;
+import org.p2play.scripting.pnuts.manager.PackageHandler;
+
+
+public class GameDescriptor {
+ private static HashMap<String, GameDescriptor> gameDescriptorMap = new HashMap<String, GameDescriptor>();
+
+ private String clientScript;
+
+ private String serverScript;
+
+ private GameStateClass gameStateClass;
+
+ private HashMap<String, GameClass> gameClassMap;
+
+ private HashMap<String, GameActionClass> gameActionMap;
+
+ private String neighbourFunction;
+
+ private String emptyFunction;
+
+ private RegionClass regionClass;
+
+ private String game;
+
+ private PnutsHandler pnutsHandler;
+
+ private GameDescriptor() {
+ gameClassMap = new HashMap<String, GameClass>();
+ gameActionMap = new HashMap<String, GameActionClass>();
+ }
+
+ public String getClientScript() {
+ return clientScript;
+ }
+
+ public HashMap<String, GameClass> getGameClassMap() {
+ return gameClassMap;
+ }
+
+ public HashMap<String, GameActionClass> getGameActionMap() {
+ return gameActionMap;
+ }
+
+ public GameStateClass getGameStateClass() {
+ return gameStateClass;
+ }
+
+ public RegionClass getRegionClass() {
+ return regionClass;
+ }
+
+ public String getServerScript() {
+ return serverScript;
+ }
+
+ public String getNeighbourFunction() {
+ return neighbourFunction;
+ }
+
+ public String getEmptyFunction() {
+ return emptyFunction;
+ }
+
+ @SuppressWarnings("unchecked")
+ private static GameDescriptor parse(InputStream inputStream) {
+ GameDescriptor gameDescriptor = new GameDescriptor();
+
+ SAXBuilder builder = new SAXBuilder();
+ Document doc = null;
+ try {
+ doc = builder.build(inputStream);
+ } catch (JDOMException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ Element root = doc.getRootElement();
+
+ gameDescriptor.game = root.getAttributeValue("name");
+
+ // load neighbour function
+ Element neighbourElement = root.getChild("neighbour");
+ if (neighbourElement != null)
+ gameDescriptor.neighbourFunction = neighbourElement.getValue()
+ .trim();
+
+ // load empty function
+ Element emptyElement = root.getChild("empty");
+ if (emptyElement != null)
+ gameDescriptor.emptyFunction = emptyElement.getValue().trim();
+
+ // load script names
+ Iterator<Element> scriptElementIterator = root.getChildren("script")
+ .iterator();
+ while (scriptElementIterator.hasNext()) {
+ Element element = scriptElementIterator.next();
+
+ String type = element.getAttributeValue("type");
+
+ if (type.equals("client"))
+ gameDescriptor.clientScript = element.getValue().trim();
+ else if (type.equals("server"))
+ gameDescriptor.serverScript = element.getValue().trim();
+ }
+
+ // create classes
+ Iterator<Element> classElementIterator = root.getChild("classes")
+ .getChildren("class").iterator();
+ while (classElementIterator.hasNext()) {
+ Element element = classElementIterator.next();
+
+ String type = element.getAttributeValue("type").trim();
+
+ gameDescriptor.gameClassMap.put(type, new GameClass(
+ gameDescriptor.game, type, element));
+ }
+
+ // then fill in the variables
+ Iterator<GameClass> gameClassIterator = gameDescriptor.gameClassMap
+ .values().iterator();
+ while (gameClassIterator.hasNext()) {
+ GameClass gameClass = gameClassIterator.next();
+
+ gameClass.parse(gameDescriptor.gameClassMap);
+ }
+
+ // create Actions
+ Iterator<Element> actionElementIterator = root.getChild("actions")
+ .getChildren("action").iterator();
+ while (actionElementIterator.hasNext()) {
+ Element element = actionElementIterator.next();
+
+ String type = element.getAttributeValue("type").trim();
+
+ gameDescriptor.gameActionMap.put(type, new GameActionClass(
+ gameDescriptor.game, type, element));
+
+ gameDescriptor.gameActionMap.get(type).parse(
+ gameDescriptor.gameClassMap);
+ }
+
+ // create game state class
+ gameDescriptor.gameStateClass = new GameStateClass(gameDescriptor.game,
+ "GameState", root.getChild("state"));
+ gameDescriptor.gameStateClass.parse(gameDescriptor.gameClassMap);
+
+ // create region class
+ gameDescriptor.regionClass = new RegionClass(gameDescriptor.game, root
+ .getChild("region").getAttributeValue("type"), root
+ .getChild("region"));
+ gameDescriptor.regionClass.parse(gameDescriptor.gameClassMap);
+
+ return gameDescriptor;
+ }
+
+ public static GameDescriptor getGameDescriptor(String game) {
+ synchronized (gameDescriptorMap) {
+ GameDescriptor gameDescriptor = gameDescriptorMap.get(game);
+
+ if (gameDescriptor == null) {
+ gameDescriptor = parse(ResourceClassLoader
+ .getResourceClassLoader().getResourceAsStream(
+ game + ".xml"));
+ gameDescriptorMap.put(game, gameDescriptor);
+ }
+
+ return gameDescriptor;
+ }
+ }
+
+ public List<Region> getNeighbourRegionIdentifiers(Region region) {
+ LinkedList<Region> neigbours = new LinkedList<Region>();
+ PnutsHandler pnutsHandler=getNutCracker();
+ if (getNeighbourFunction() != null) {
+ Object[] tmp = (Object[]) pnutsHandler.callFunction(
+ getNeighbourFunction(), region);
+
+ for (int i = 0; i < tmp.length; i++) {
+ neigbours.add((Region) tmp[i]);
+ }
+
+ }
+
+ if (!neigbours.contains(region))
+ neigbours.add(region);
+
+ return neigbours;
+
+ }
+
+ private PnutsHandler getNutCracker() {
+ if (pnutsHandler == null) {
+ PackageHandler packageHandler = new PackageHandler();
+
+ new ObjectAPI(this).registerAPI(packageHandler);
+
+ pnutsHandler = new PnutsHandler(packageHandler);
+ try {
+ pnutsHandler.execute(pnutsHandler.getPnuts(ResourceClassLoader
+ .getResourceClassLoader().getResourceAsStream(
+ getServerScript())));
+ } catch (Exception e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+
+ return pnutsHandler;
+ }
+
+ public boolean isIdle(GameState gameState){
+ return (Boolean)pnutsHandler.callFunction(
+ getEmptyFunction(), gameState);
+ }
+}
Added: trunk/P2Play/src/org/p2play/scripting/pnuts/object/GameField.java
===================================================================
--- trunk/P2Play/src/org/p2play/scripting/pnuts/object/GameField.java (rev 0)
+++ trunk/P2Play/src/org/p2play/scripting/pnuts/object/GameField.java 2006-12-27 18:05:30 UTC (rev 14)
@@ -0,0 +1,44 @@
+/*
+ * 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.scripting.pnuts.object;
+
+import java.io.IOException;
+
+import rice.p2p.commonapi.rawserialization.InputBuffer;
+
+public class GameField extends GameMap{
+
+ public GameField() {
+ super();
+ }
+
+ public GameField(InputBuffer buffer) throws IOException {
+ super(buffer);
+ }
+
+ @Override
+ public Object get(Object key) {
+ GameMap map=(GameMap) super.get(key);
+ if(map==null){
+ map=new GameMap();
+ put(key, map);
+ }
+ return map;
+ }
+}
Added: trunk/P2Play/src/org/p2play/scripting/pnuts/object/GameList.java
===================================================================
--- trunk/P2Play/src/org/p2play/scripting/pnuts/object/GameList.java (rev 0)
+++ trunk/P2Play/src/org/p2play/scripting/pnuts/object/GameList.java 2006-12-27 18:05:30 UTC (rev 14)
@@ -0,0 +1,160 @@
+/*
+ * 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.scripting.pnuts.object;
+
+import java.io.IOException;
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+import java.util.ListIterator;
+
+import rice.p2p.commonapi.rawserialization.InputBuffer;
+import rice.p2p.commonapi.rawserialization.OutputBuffer;
+
+public class GameList implements List<Object>, Serializable {
+ private List<Object> list;
+
+ public GameList() {
+ this.list = new ArrayList<Object>();
+ }
+
+ public GameList(InputBuffer buffer) throws IOException {
+ this();
+
+ int size = buffer.readInt();
+ for (int i = 0; i < size; i++) {
+ list.add(GameObject.deserializeObject(buffer));
+ }
+ }
+
+ public void add(int index, Object element) {
+ list.add(index, element);
+ }
+
+ public boolean add(Object o) {
+ return list.add(o);
+ }
+
+ public boolean addAll(Collection<? extends Object> c) {
+ return list.addAll(c);
+ }
+
+ public boolean addAll(int index, Collection<? extends Object> c) {
+ return list.addAll(index, c);
+ }
+
+ public void clear() {
+ list.clear();
+ }
+
+ public boolean contains(Object o) {
+ return list.contains(o);
+ }
+
+ public boolean containsAll(Collection<? extends Object> c) {
+ return list.containsAll(c);
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ return list.equals(o);
+ }
+
+ public Object get(int index) {
+ return list.get(index);
+ }
+
+ @Override
+ public int hashCode() {
+ return list.hashCode();
+ }
+
+ public int indexOf(Object o) {
+ return list.indexOf(o);
+ }
+
+ public boolean isEmpty() {
+ return list.isEmpty();
+ }
+
+ public Iterator<Object> iterator() {
+ return list.iterator();
+ }
+
+ public int lastIndexOf(Object o) {
+ return list.lastIndexOf(o);
+ }
+
+ public ListIterator<Object> listIterator() {
+ return list.listIterator();
+ }
+
+ public ListIterator<Object> listIterator(int index) {
+ return list.listIterator(index);
+ }
+
+ public Object remove(int index) {
+ return list.remove(index);
+ }
+
+ public boolean remove(Object o) {
+ return list.remove(o);
+ }
+
+ public boolean removeAll(Collection c) {
+ return list.removeAll(c);
+ }
+
+ public boolean retainAll(Collection c) {
+ return list.retainAll(c);
+ }
+
+ public Object set(int index, Object element) {
+ return list.set(index, element);
+ }
+
+ public int size() {
+ return list.size();
+ }
+
+ public List<Object> subList(int fromIndex, int toIndex) {
+ return list.subList(fromIndex, toIndex);
+ }
+
+ public Object[] toArray() {
+ return list.toArray();
+ }
+
+ public <T> T[] toArray(T[] a) {
+ return list.toArray(a);
+ }
+
+ public void doSerialize(OutputBuffer buffer) throws IOException {
+ Object[] objects = toArray();
+
+ buffer.writeInt(objects.length);
+
+ for (int i = 0; i < objects.length; i++) {
+ GameObject.serializeObject(buffer, objects[i]);
+ }
+ }
+
+}
Added: trunk/P2Play/src/org/p2play/scripting/pnuts/object/GameMap.java
===================================================================
--- trunk/P2Play/src/org/p2play/scripting/pnuts/object/GameMap.java (rev 0)
+++ trunk/P2Play/src/org/p2play/scripting/pnuts/object/GameMap.java 2006-12-27 18:05:30 UTC (rev 14)
@@ -0,0 +1,125 @@
+/*
+ * 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.scripting.pnuts.object;
+
+import java.io.IOException;
+import java.io.Serializable;
+import java.util.Collection;
+import java.util.Map;
+import java.util.Set;
+
+import javolution.util.FastMap;
+import rice.p2p.commonapi.rawserialization.InputBuffer;
+import rice.p2p.commonapi.rawserialization.OutputBuffer;
+
+public class GameMap implements Map<Object, Object>, Serializable {
+ private Map<Object, Object> map;
+
+ public GameMap() {
+ this.map = new FastMap<Object, Object>();
+ }
+
+ public GameMap(InputBuffer buffer) throws IOException {
+ this();
+
+ int size = buffer.readInt();
+
+ for (int i = 0; i < size; i++) {
+ put(GameObject.deserializeObject(buffer), GameObject
+ .deserializeObject(buffer));
+ }
+ }
+
+ public void clear() {
+ map.clear();
+ }
+
+ public boolean containsKey(Object key) {
+ return map.containsKey(key);
+ }
+
+ public boolean containsValue(Object value) {
+ return map.containsValue(value);
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ return map.equals(o);
+ }
+
+ public Object get(Object key) {
+ return map.get(key);
+ }
+
+ @Override
+ public int hashCode() {
+ return map.hashCode();
+ }
+
+ public boolean isEmpty() {
+ return map.isEmpty();
+ }
+
+ public Set<Object> keySet() {
+ return map.keySet();
+ }
+
+ public Object put(Object key, Object value) {
+ return map.put(key, value);
+ }
+
+ public Object remove(Object key) {
+ return map.remove(key);
+ }
+
+ public int size() {
+ return map.size();
+ }
+
+ public Collection<Object> values() {
+ return map.values();
+ }
+
+ @Override
+ public String toString() {
+ // TODO Auto-generated method stub
+ return "GameMap: " + map.toString();
+ }
+
+ public void doSerialize(OutputBuffer buffer) throws IOException {
+ Object keys[] = map.keySet().toArray();
+
+ buffer.writeInt(keys.length);
+
+ for (int i = 0; i < keys.length; i++) {
+ GameObject.serializeObject(buffer, keys[i]);
+ GameObject.serializeObject(buffer, map.get(keys[i]));
+ }
+ }
+
+ public void putAll(Map<? extends Object, ? extends Object> t) {
+ map.putAll(t);
+
+ }
+
+ public Set<java.util.Map.Entry<Object, Object>> entrySet() {
+ return map.entrySet();
+ }
+
+}
Added: trunk/P2Play/src/org/p2play/scripting/pnuts/object/GameObject.java
===================================================================
--- trunk/P2Play/src/org/p2play/scripting/pnuts/object/GameObject.java (rev 0)
+++ trunk/P2Play/src/org/p2play/scripting/pnuts/object/GameObject.java 2006-12-27 18:05:30 UTC (rev 14)
@@ -0,0 +1,352 @@
+/*
+ * 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.scripting.pnuts.object;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.OutputStream;
+import java.io.Serializable;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+import org.p2play.util.Hashable;
+import org.p2play.util.NetRandom;
+
+import pnuts.lang.Context;
+import pnuts.lang.Property;
+import rice.p2p.commonapi.rawserialization.InputBuffer;
+import rice.p2p.commonapi.rawserialization.OutputBuffer;
+
+public class GameObject implements Serializable, Property, Hashable {
+ public static final byte TYPE_NULL = 0;
+
+ public static final byte TYPE_BOOLEAN = 1;
+
+ public static final byte TYPE_CHARACTER = 2;
+
+ public static final byte TYPE_BYTE = 3;
+
+ public static final byte TYPE_SHORT = 4;
+
+ public static final byte TYPE_INTEGER = 5;
+
+ public static final byte TYPE_LONG = 6;
+
+ public static final byte TYPE_FLOAT = 7;
+
+ public static final byte TYPE_STRING = 8;
+
+ public static final byte TYPE_GAMELIST = 9;
+
+ public static final byte TYPE_GAMEMAP = 10;
+
+ public static final byte TYPE_GAMEFIELD = 11;
+
+ public static final byte TYPE_GAMESTATEOBJECT = 12;
+
+ public static final byte TYPE_GAMEACTIONOBJECT = 13;
+
+ public static final byte TYPE_REGIONOBJECT = 14;
+
+ public static final byte TYPE_GAMEOBJECT = 15;
+
+ public static final byte TYPE_NETRANDOM = 16;
+
+ public static final byte TYPE_OBJECT = 17;
+
+ private transient GameClass gameClass;
+
+ private Map<String, Object> content;
+
+ private String type;
+
+ private String game;
+
+ GameObject(GameClass gameClass) {
+ super();
+ this.type = gameClass.getType();
+ this.game = gameClass.getGame();
+ this.gameClass = gameClass;
+ content = new HashMap<String, Object>();
+ }
+
+ public GameObject(InputBuffer buffer) throws IOException {
+ super();
+ // read game and type
+ game = buffer.readUTF();
+ type = buffer.readUTF();
+
+ content = new HashMap<String, Object>();
+
+ // now retrieve the content
+ Iterator<String> variables = getGameClass().iteratorOfVariables();
+ while (variables.hasNext()) {
+ String variable = variables.next();
+ Object object = deserializeObject(buffer);
+ if (object != null)
+ content.put(variable, object);
+
+ }
+ }
+
+ public Object get(String name, Context context) {
+ return content.get(name);
+ }
+
+ public void set(String name, Object value, Context context) {
+ getGameClass().checkVariable(name, value);
+ content.put(name, value);
+ }
+
+ protected void setGameClass(GameClass gameClass) {
+ this.gameClass = gameClass;
+ }
+
+ public GameClass getGameClass() {
+ if (gameClass == null)
+ gameClass = GameDescriptor.getGameDescriptor(game)
+ .getGameClassMap().get(type);
+ return gameClass;
+ }
+
+ public Object get(String name) {
+ return get(name, null);
+ }
+
+ public void set(String name, Object value) {
+ set(name, value, null);
+ }
+
+ public String getGame() {
+ return game;
+ }
+
+ public String getType() {
+ return type;
+ }
+
+ public int hash() {
+ return 0;
+ }
+
+ @Override
+ public String toString() {
+ return "Game: " + game + " Type: " + type + " Content: " + content;
+ }
+
+ public void doSerialize(OutputBuffer buffer) throws IOException {
+ // first write the game and type
+ buffer.writeUTF(game);
+ buffer.writeUTF(type);
+
+ // now store the content
+ Iterator<String> variables = getGameClass().iteratorOfVariables();
+ while (variables.hasNext()) {
+ String variable = variables.next();
+ Object object = content.get(variable);
+ serializeObject(buffer, object);
+ }
+ }
+
+ public static byte getType(Object object) {
+ if (object == null)
+ return TYPE_NULL;
+ else if (object instanceof Boolean)
+ return TYPE_BOOLEAN;
+ else if (object instanceof Character)
+ return TYPE_CHARACTER;
+ else if (object instanceof Byte)
+ return TYPE_BYTE;
+ else if (object instanceof Short)
+ return TYPE_SHORT;
+ else if (object instanceof Integer)
+ return TYPE_INTEGER;
+ else if (object instanceof Long)
+ return TYPE_LONG;
+ else if (object instanceof Float)
+ return TYPE_FLOAT;
+ else if (object instanceof String)
+ return TYPE_STRING;
+ else if (object instanceof GameList)
+ return TYPE_GAMELIST;
+ else if (object instanceof GameField)// this has to be before
+ // GameMap, because it is a
+ // subtype of it
+ return TYPE_GAMEFIELD;
+ else if (object instanceof GameMap)
+ return TYPE_GAMEMAP;
+ else if (object instanceof RegionObject)// this has to be before
+ // GameObject, because it is a
+ // subtype of it
+ return TYPE_REGIONOBJECT;
+ else if (object instanceof GameStateObject)// this has to be before
+ // GameObject, because it is
+ // a subtype of it
+ return TYPE_GAMESTATEOBJECT;
+ else if (object instanceof GameActionObject)// this has to be before
+ // GameObject, because it is
+ // a subtype of it
+ return TYPE_GAMEACTIONOBJECT;
+ else if (object instanceof GameObject)
+ return TYPE_GAMEOBJECT;
+ else if (object instanceof NetRandom)
+ return TYPE_NETRANDOM;
+ else
+ return TYPE_OBJECT;
+ }
+
+ public static void serializeObject(OutputBuffer buffer, Object object)
+ throws IOException {
+ byte type = getType(object);
+ buffer.writeByte(type);
+
+ switch (type) {
+ case TYPE_NULL:
+ // do nothing
+ break;
+ case TYPE_BOOLEAN:
+ buffer.writeBoolean((Boolean) object);
+ break;
+ case TYPE_CHARACTER:
+ buffer.writeChar((Character) object);
+ break;
+ case TYPE_BYTE:
+ buffer.writeByte((Byte) object);
+ break;
+ case TYPE_SHORT:
+ buffer.writeShort((Short) object);
+ break;
+ case TYPE_INTEGER:
+ buffer.writeInt((Integer) object);
+ break;
+ case TYPE_LONG:
+ buffer.writeLong((Long) object);
+ break;
+ case TYPE_FLOAT:
+ buffer.writeFloat((Float) object);
+ break;
+ case TYPE_STRING:
+ buffer.writeUTF((String) object);
+ break;
+ case TYPE_GAMELIST:
+ ((GameList) object).doSerialize(buffer);
+ break;
+ case TYPE_GAMEMAP:
+ ((GameMap) object).doSerialize(buffer);
+ break;
+ case TYPE_GAMEFIELD:
+ ((GameField) object).doSerialize(buffer);
+ break;
+ case TYPE_GAMESTATEOBJECT:
+ ((GameStateObject) object).doSerialize(buffer);
+ break;
+ case TYPE_GAMEACTIONOBJECT:
+ ((GameActionObject) object).doSerialize(buffer);
+ break;
+ case TYPE_REGIONOBJECT:
+ ((RegionObject) object).doSerialize(buffer);
+ break;
+ case TYPE_GAMEOBJECT:
+ ((GameObject) object).doSerialize(buffer);
+ break;
+ case TYPE_NETRANDOM:
+ ((NetRandom) object).doSerialize(buffer);
+ break;
+ case TYPE_OBJECT:
+ // java serialisation...
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ OutputStream gos = bos;// new GZIPOutputStream(bos);
+ ObjectOutputStream oos = new ObjectOutputStream(gos);
+
+ oos.writeObject(object);
+
+ gos.close();
+
+ byte[] b = bos.toByteArray();
+ buffer.writeInt(b.length);
+ buffer.write(b, 0, b.length);
+ break;
+ default:
+ throw new IllegalArgumentException(
+ "Object serialisation not supported: " + type + " "
+ + object.getClass() + " " + object);
+ }
+ }
+
+ public static Object deserializeObject(InputBuffer buffer)
+ throws IOException {
+ byte type = buffer.readByte();
+
+ switch (type) {
+ case TYPE_NULL:
+ return null;
+ case TYPE_BOOLEAN:
+ return buffer.readBoolean();
+ case TYPE_CHARACTER:
+ return buffer.readChar();
+ case TYPE_BYTE:
+ return buffer.readByte();
+ case TYPE_SHORT:
+ return buffer.readShort();
+ case TYPE_INTEGER:
+ return buffer.readInt();
+ case TYPE_LONG:
+ return buffer.readLong();
+ case TYPE_FLOAT:
+ return buffer.readFloat();
+ case TYPE_STRING:
+ return buffer.readUTF();
+ case TYPE_GAMELIST:
+ return new GameList(buffer);
+ case TYPE_GAMEMAP:
+ return new GameMap(buffer);
+ case TYPE_GAMEFIELD:
+ return new GameField(buffer);
+ case TYPE_GAMESTATEOBJECT:
+ return new GameStateObject(buffer);
+ case TYPE_GAMEACTIONOBJECT:
+ return new GameActionObject(buffer);
+ case TYPE_REGIONOBJECT:
+ return new RegionObject(buffer);
+ case TYPE_GAMEOBJECT:
+ return new GameObject(buffer);
+ case TYPE_NETRANDOM:
+ return new NetRandom(buffer);
+ case TYPE_OBJECT:
+ byte[] b = new byte[buffer.readInt()];
+ buffer.read(b);
+ ObjectInputStream ois = new ObjectInputStream(
+ /* new GZIPInputStream */(new ByteArrayInputStream(b)));
+ try {
+ return ois.readObject();
+ } catch (ClassNotFoundException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ return null;
+ }
+ default:
+ throw new IllegalArgumentException(
+ "Object deserilation not supported: " + type);
+ }
+ }
+}
Added: trunk/P2Play/src/org/p2play/scripting/pnuts/object/GameStateClass.java
===================================================================
--- trunk/P2Play/src/org/p2play/scripting/pnuts/object/GameStateClass.java (rev 0)
+++ trunk/P2Play/src/org/p2play/scripting/pnuts/object/GameStateClass.java 2006-12-27 18:05:30 UTC (rev 14)
@@ -0,0 +1,53 @@
+/*
+ * 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.scripting.pnuts.object;
+
+import java.util.HashMap;
+import java.util.Random;
+
+import org.jdom.Element;
+import org.p2play.net.region.Region;
+
+public class GameStateClass extends GameClass{
+ public static final String GAME_TIME="GAMETIME";
+ public static final String RANDOM="RANDOM";
+ public static final String REGION = "REGION";
+
+ public GameStateClass(String game, String name, Element element) {
+ super(game, name, element);
+ }
+
+ @Override
+ void parse(HashMap<String, GameClass> classMap) {
+ super.parse(classMap);
+
+ addVariable(GAME_TIME, Long.class);
+ addVariable(RANDOM, Random.class);
+ addVariable(REGION, String.class);
+ }
+
+ @Override
+ public GameObject createInstance(Object... objects) {
+ throw new IllegalArgumentException();
+ }
+
+ public GameStateObject createInstance(Region region, long gameTime) {
+ return new GameStateObject(this,region,gameTime);
+ }
+}
Added: trunk/P2Play/src/org/p2play/scripting/pnuts/object/GameStateObject.java
===================================================================
--- trunk/P2Play/src/org/p2play/scripting/pnuts/object/GameStateObject.java (rev 0)
+++ trunk/P2Play/src/org/p2play/scripting/pnuts/object/GameStateObject.java 2006-12-27 18:05:30 UTC (rev 14)
@@ -0,0 +1,86 @@
+/*
+ * 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.scripting.pnuts.object;
+
+import java.io.IOException;
+import java.util.List;
+import java.util.Random;
+
+import org.p2play.net.region.GameState;
+import org.p2play.net.region.Region;
+import org.p2play.util.NetRandom;
+
+import rice.p2p.commonapi.rawserialization.InputBuffer;
+
+public class GameStateObject extends GameObject implements GameState {
+ private transient GameClass gameClass = null;
+
+ public GameStateObject(GameClass gameClass, Region region, long gameTime) {
+ super(gameClass);
+ set(GameStateClass.GAME_TIME, gameTime);
+ set(GameStateClass.RANDOM, new NetRandom(gameTime));
+ set(GameStateClass.REGION, region);
+ }
+
+ public GameStateObject(InputBuffer buffer) throws IOException {
+ super(buffer);
+ // TODO Auto-generated constructor stub
+ }
+
+ public long getGameTime() {
+ return (Long) get(GameStateClass.GAME_TIME);
+ }
+
+ public Random getRandom() {
+ return (Random) get(GameStateClass.RANDOM);
+ }
+
+ public Region getRegion() {
+ return (Region) get(GameStateClass.REGION);
+ }
+
+ public void tick() {
+ set(GameStateClass.GAME_TIME, (Long) get(GameStateClass.GAME_TIME) + 1);
+ }
+
+ public int randomInt() {
+ return getRandom().nextInt();
+ }
+
+ public int randomInt(int n) {
+ return getRandom().nextInt(n);
+ }
+
+ @Override
+ public GameClass getGameClass() {
+ if (gameClass == null)
+ gameClass = GameDescriptor.getGameDescriptor(getGame())
+ .getGameStateClass();
+ return gameClass;
+ }
+
+ public boolean isIdle() {
+ return GameDescriptor.getGameDescriptor(getGame()).isIdle(this);
+ }
+
+ public List<Region> getNeighbourRegions() {
+ return GameDescriptor.getGameDescriptor(getGame())
+ .getNeighbourRegionIdentifiers(this.getRegion());
+ }
+}
Added: trunk/P2Play/src/org/p2play/scripting/pnuts/object/RegionClass.java
===================================================================
--- trunk/P2Play/src/org/p2play/scripting/pnuts/object/RegionClass.java (rev 0)
+++ trunk/P2Play/src/org/p2play/scripting/pnuts/object/RegionClass.java 2006-12-27 18:05:30 UTC (rev 14)
@@ -0,0 +1,36 @@
+/*
+ * 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.scripting.pnuts.object;
+
+import org.jdom.Element;
+
+public class RegionClass extends GameClass {
+ public RegionClass(String game, String name, Element element) {
+ super(game, name, element);
+ }
+
+ @Override
+ public GameObject createInstance(Object... objects) {
+ GameObject gameObject=new RegionObject(this);
+
+ fillObject(gameObject, objects);
+
+ return gameObject;
+ }
+}
Added: trunk/P2Play/src/org/p2play/scripting/pnuts/object/RegionObject.java
===================================================================
--- trunk/P2Play/src/org/p2play/scripting/pnuts/object/RegionObject.java (rev 0)
+++ trunk/P2Play/src/org/p2play/scripting/pnuts/object/RegionObject.java 2006-12-27 18:05:30 UTC (rev 14)
@@ -0,0 +1,93 @@
+/*
+ * 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.scripting.pnuts.object;
+
+import java.io.IOException;
+import java.util.Iterator;
+
+import org.p2play.net.region.Region;
+
+import pnuts.lang.Context;
+import rice.p2p.commonapi.rawserialization.InputBuffer;
+
+public class RegionObject extends GameObject implements Region {
+
+ private transient String regionIdentifier;
+
+ public RegionObject(GameClass gameClass) {
+ super(gameClass);
+ }
+
+ public RegionObject(InputBuffer buffer) throws IOException {
+ super(buffer);
+ }
+
+ @Override
+ public GameClass getGameClass() {
+ if (super.getGameClass() == null)
+ setGameClass(GameDescriptor.getGameDescriptor(getGame())
+ .getRegionClass());
+ return super.getGameClass();
+ }
+
+ @Override
+ public void set(String name, Object value) {
+ super.set(name, value);
+ regionIdentifier = null;
+ }
+
+ @Override
+ public void set(String name, Object value, Context context) {
+ super.set(name, value, context);
+ regionIdentifier = null;
+ ;
+ }
+
+ public String getRegionIdentifier() {
+ if (regionIdentifier == null) {
+ regionIdentifier = getGame();
+
+ Iterator<String> iterator = getGameClass().iteratorOfVariables();
+ while (iterator.hasNext()) {
+ String name = iterator.next();
+ regionIdentifier += "." + get(name).toString();
+ }
+ }
+ return regionIdentifier;
+ }
+
+ @Override
+ public String toString() {
+ return getRegionIdentifier();
+ }
+
+ @Override
+ public int hashCode() {
+ return getRegionIdentifier().hashCode();
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (!(obj instanceof RegionObject))
+ return false;
+ else
+ return getRegionIdentifier().equals(
+ ((RegionObject) obj).getRegionIdentifier());
+ }
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ti...@us...> - 2006-12-27 18:04:58
|
Revision: 13
http://p2play.svn.sourceforge.net/p2play/?rev=13&view=rev
Author: tisoft
Date: 2006-12-27 10:04:52 -0800 (Wed, 27 Dec 2006)
Log Message:
-----------
transfered from university cvs
added license header
changed package name to org.p2play.*
Added Paths:
-----------
trunk/P2Play/src/org/p2play/net/pastry/
trunk/P2Play/src/org/p2play/net/pastry/Pastry.java
trunk/P2Play/src/org/p2play/net/pastry/time/
trunk/P2Play/src/org/p2play/net/pastry/time/NTPMessage.java
trunk/P2Play/src/org/p2play/net/pastry/time/NTPTimeSource.java
trunk/P2Play/src/org/p2play/net/pastry/time/TimeManager.java
Added: trunk/P2Play/src/org/p2play/net/pastry/Pastry.java
===================================================================
--- trunk/P2Play/src/org/p2play/net/pastry/Pastry.java (rev 0)
+++ trunk/P2Play/src/org/p2play/net/pastry/Pastry.java 2006-12-27 18:04:52 UTC (rev 13)
@@ -0,0 +1,130 @@
+/*
+ * 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.pastry;
+
+import java.io.IOException;
+import java.net.InetAddress;
+import java.net.InetSocketAddress;
+
+import org.p2play.net.pastry.time.NTPTimeSource;
+
+import rice.environment.Environment;
+import rice.environment.logging.LogManager;
+import rice.environment.params.simple.SimpleParameters;
+import rice.p2p.commonapi.Node;
+import rice.pastry.NodeIdFactory;
+import rice.pastry.PastryNode;
+import rice.pastry.socket.SocketPastryNodeFactory;
+import rice.pastry.standard.RandomNodeIdFactory;
+
+public class Pastry {
+ /**
+ * Boot into the Pastry Network
+ *
+ * @param remoteHost
+ * the remote host to boot into
+ * @param remotePort
+ * the port on the remote host to boot into
+ * @param externalHost
+ * our external IP
+ * @param localPort
+ * the port we bind to
+ * @return The local PastryNode, that is connected in the Pastry Network
+ * @throws IOException
+ */
+ public static Node boot(String remoteHost, int remotePort,
+ String externalHost, int localPort) throws IOException {
+ return boot(InetAddress.getByName(remoteHost), remotePort, InetAddress
+ .getByName(externalHost), localPort);
+ }
+
+ /**
+ * Boot into the Pastry Network
+ *
+ * @param remoteHost
+ * the remote host to boot into
+ * @param remotePort
+ * the port on the remote host to boot into
+ * @param externalHost
+ * our external IP
+ * @param localPort
+ * the port we bind to
+ * @return The local PastryNode, that is connected in the Pastry Network
+ * @throws IOException
+ */
+ public static Node boot(InetAddress remoteHost, int remotePort,
+ InetAddress externalHost, int localPort) throws IOException {
+ return boot(new InetSocketAddress(remoteHost, remotePort),
+ externalHost, localPort);
+ }
+ /**
+ * Boot into the Pastry Network
+ *
+ * @param remote
+ * the boot node
+ * @param externalAddress
+ * our external IP
+ * @param localPort
+ * the port we bind to
+ * @return The local PastryNode, that is connected in the Pastry Network
+ * @throws IOException
+ */
+ public static Node boot(InetSocketAddress remote,
+ InetAddress externalAddress, int localPort) throws IOException {
+ return boot(remote,externalAddress,localPort,null);
+ }
+
+
+ /**
+ * Boot into the Pastry Network
+ *
+ * @param remote
+ * the boot node
+ * @param externalAddress
+ * our external IP
+ * @param localPort
+ * the port we bind to
+ * @return The local PastryNode, that is connected in the Pastry Network
+ * @throws IOException
+ */
+ public static Node boot(InetSocketAddress remote,
+ InetAddress externalAddress, int localPort, LogManager logManager) throws IOException {
+ PastryNode node;
+
+ Environment environment = new Environment(null, null, null,
+ NTPTimeSource.getTimeSource(), logManager, new SimpleParameters(
+ new String[]{"mmog"}, null));
+ NodeIdFactory nidFactory = new RandomNodeIdFactory(environment);
+ SocketPastryNodeFactory factory = new SocketPastryNodeFactory(
+ nidFactory, externalAddress, localPort, environment, null);
+
+ node = factory.newNode(factory.getNodeHandle(remote));
+
+ while (!node.isReady()) {
+ // delay so we don't busy-wait
+ try {
+ Thread.sleep(100);
+ } catch (InterruptedException e) {
+ // TODO Auto-generated catch block
+ }
+ }
+
+ return node;
+ }
+}
Added: trunk/P2Play/src/org/p2play/net/pastry/time/NTPMessage.java
===================================================================
--- trunk/P2Play/src/org/p2play/net/pastry/time/NTPMessage.java (rev 0)
+++ trunk/P2Play/src/org/p2play/net/pastry/time/NTPMessage.java 2006-12-27 18:04:52 UTC (rev 13)
@@ -0,0 +1,473 @@
+package org.p2play.net.pastry.time;
+/*
+ * Copyright (c) 2004, Adam Buckley
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * - Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * - Neither the name of Adam Buckley nor the names of its contributors may be
+ * used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+import java.text.DecimalFormat;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
+import org.p2play.util.NetRandom;
+
+
+/**
+ * This class represents a NTP message, as specified in RFC 2030. The message
+ * format is compatible with all versions of NTP and SNTP.
+ *
+ * This class does not support the optional authentication protocol, and
+ * ignores the key ID and message digest fields.
+ *
+ * For convenience, this class exposes message values as native Java types, not
+ * the NTP-specified data formats. For example, timestamps are
+ * stored as doubles (as opposed to the NTP unsigned 64-bit fixed point
+ * format).
+ *
+ * However, the contructor NtpMessage(byte[]) and the method toByteArray()
+ * allow the import and export of the raw NTP message format.
+ *
+ *
+ * Usage example
+ *
+ * // Send message
+ * DatagramSocket socket = new DatagramSocket();
+ * InetAddress address = InetAddress.getByName("ntp.cais.rnp.br");
+ * byte[] buf = new NtpMessage().toByteArray();
+ * DatagramPacket packet = new DatagramPacket(buf, buf.length, address, 123);
+ * socket.send(packet);
+ *
+ * // Get response
+ * socket.receive(packet);
+ * System.out.println(msg.toString());
+ *
+ * Comments for member variables are taken from RFC2030 by David Mills,
+ * University of Delaware.
+ *
+ * Number format conversion code in NtpMessage(byte[] array) and toByteArray()
+ * inspired by http://www.pps.jussieu.fr/~jch/enseignement/reseaux/
+ * NTPMessage.java which is copyright (c) 2003 by Juliusz Chroboczek
+ *
+ * @author Adam Buckley
+ */
+public class NTPMessage {
+ private static NetRandom random=new NetRandom();
+
+ /**
+ * This is a two-bit code warning of an impending leap second to be
+ * inserted/deleted in the last minute of the current day. It's values
+ * may be as follows:
+ *
+ * Value Meaning
+ * ----- -------
+ * 0 no warning
+ * 1 last minute has 61 seconds
+ * 2 last minute has 59 seconds)
+ * 3 alarm condition (clock not synchronized)
+ */
+ public byte leapIndicator = 0;
+
+
+ /**
+ * This value indicates the NTP/SNTP version number. The version number
+ * is 3 for Version 3 (IPv4 only) and 4 for Version 4 (IPv4, IPv6 and OSI).
+ * If necessary to distinguish between IPv4, IPv6 and OSI, the
+ * encapsulating context must be inspected.
+ */
+ public byte version = 3;
+
+
+ /**
+ * This value indicates the mode, with values defined as follows:
+ *
+ * Mode Meaning
+ * ---- -------
+ * 0 reserved
+ * 1 symmetric active
+ * 2 symmetric passive
+ * 3 client
+ * 4 server
+ * 5 broadcast
+ * 6 reserved for NTP control message
+ * 7 reserved for private use
+ *
+ * In unicast and anycast modes, the client sets this field to 3 (client)
+ * in the request and the server sets it to 4 (server) in the reply. In
+ * multicast mode, the server sets this field to 5 (broadcast).
+ */
+ public byte mode = 0;
+
+
+ /**
+ * This value indicates the stratum level of the local clock, with values
+ * defined as follows:
+ *
+ * Stratum Meaning
+ * ----------------------------------------------
+ * 0 unspecified or unavailable
+ * 1 primary reference (e.g., radio clock)
+ * 2-15 secondary reference (via NTP or SNTP)
+ * 16-255 reserved
+ */
+ public short stratum = 0;
+
+
+ /**
+ * This value indicates the maximum interval between successive messages,
+ * in seconds to the nearest power of two. The values that can appear in
+ * this field presently range from 4 (16 s) to 14 (16284 s); however, most
+ * applications use only the sub-range 6 (64 s) to 10 (1024 s).
+ */
+ public byte pollInterval = 0;
+
+
+ /**
+ * This value indicates the precision of the local clock, in seconds to
+ * the nearest power of two. The values that normally appear in this field
+ * range from -6 for mains-frequency clocks to -20 for microsecond clocks
+ * found in some workstations.
+ */
+ public byte precision = 0;
+
+
+ /**
+ * This value indicates the total roundtrip delay to the primary reference
+ * source, in seconds. Note that this variable can take on both positive
+ * and negative values, depending on the relative time and frequency
+ * offsets. The values that normally appear in this field range from
+ * negative values of a few milliseconds to positive values of several
+ * hundred milliseconds.
+ */
+ public double rootDelay = 0;
+
+
+ /**
+ * This value indicates the nominal error relative to the primary reference
+ * source, in seconds. The values that normally appear in this field
+ * range from 0 to several hundred milliseconds.
+ */
+ public double rootDispersion = 0;
+
+
+ /**
+ * This is a 4-byte array identifying the particular reference source.
+ * In the case of NTP Version 3 or Version 4 stratum-0 (unspecified) or
+ * stratum-1 (primary) servers, this is a four-character ASCII string, left
+ * justified and zero padded to 32 bits. In NTP Version 3 secondary
+ * servers, this is the 32-bit IPv4 address of the reference source. In NTP
+ * Version 4 secondary servers, this is the low order 32 bits of the latest
+ * transmit timestamp of the reference source. NTP primary (stratum 1)
+ * servers should set this field to a code identifying the external
+ * reference source according to the following list. If the external
+ * reference is one of those listed, the associated code should be used.
+ * Codes for sources not listed can be contrived as appropriate.
+ *
+ * Code External Reference Source
+ * ---- -------------------------
+ * LOCL uncalibrated local clock used as a primary reference for
+ * a subnet without external means of synchronization
+ * PPS atomic clock or other pulse-per-second source
+ * individually calibrated to national standards
+ * ACTS NIST dialup modem service
+ * USNO USNO modem service
+ * PTB PTB (Germany) modem service
+ * TDF Allouis (France) Radio 164 kHz
+ * DCF Mainflingen (Germany) Radio 77.5 kHz
+ * MSF Rugby (UK) Radio 60 kHz
+ * WWV Ft. Collins (US) Radio 2.5, 5, 10, 15, 20 MHz
+ * WWVB Boulder (US) Radio 60 kHz
+ * WWVH Kaui Hawaii (US) Radio 2.5, 5, 10, 15 MHz
+ * CHU Ottawa (Canada) Radio 3330, 7335, 14670 kHz
+ * LORC LORAN-C radionavigation system
+ * OMEG OMEGA radionavigation system
+ * GPS Global Positioning Service
+ * GOES Geostationary Orbit Environment Satellite
+ */
+ public byte[] referenceIdentifier = {0, 0, 0, 0};
+
+
+ /**
+ * This is the time at which the local clock was last set or corrected, in
+ * seconds since 00:00 1-Jan-1900.
+ */
+ public double referenceTimestamp = 0;
+
+
+ /**
+ * This is the time at which the request departed the client for the
+ * server, in seconds since 00:00 1-Jan-1900.
+ */
+ public double originateTimestamp = 0;
+
+
+ /**
+ * This is the time at which the request arrived at the server, in seconds
+ * since 00:00 1-Jan-1900.
+ */
+ public double receiveTimestamp = 0;
+
+
+ /**
+ * This is the time at which the reply departed the server for the client,
+ * in seconds since 00:00 1-Jan-1900.
+ */
+ public double transmitTimestamp = 0;
+
+
+
+ /**
+ * Constructs a new NtpMessage from an array of bytes.
+ */
+ public NTPMessage(byte[] array) {
+ // See the packet format diagram in RFC 2030 for details
+ leapIndicator = (byte) ((array[0] >> 6) & 0x3);
+ version = (byte) ((array[0] >> 3) & 0x7);
+ mode = (byte) (array[0] & 0x7);
+ stratum = unsignedByteToShort(array[1]);
+ pollInterval = array[2];
+ precision = array[3];
+
+ rootDelay = (array[4] * 256.0) +
+ unsignedByteToShort(array[5]) +
+ (unsignedByteToShort(array[6]) / 256.0) +
+ (unsignedByteToShort(array[7]) / 65536.0);
+
+ rootDispersion = (unsignedByteToShort(array[8]) * 256.0) +
+ unsignedByteToShort(array[9]) +
+ (unsignedByteToShort(array[10]) / 256.0) +
+ (unsignedByteToShort(array[11]) / 65536.0);
+
+ referenceIdentifier[0] = array[12];
+ referenceIdentifier[1] = array[13];
+ referenceIdentifier[2] = array[14];
+ referenceIdentifier[3] = array[15];
+
+ referenceTimestamp = decodeTimestamp(array, 16);
+ originateTimestamp = decodeTimestamp(array, 24);
+ receiveTimestamp = decodeTimestamp(array, 32);
+ transmitTimestamp = decodeTimestamp(array, 40);
+ }
+
+
+
+ /**
+ * Constructs a new NtpMessage in client -> server mode, and sets the
+ * transmit timestamp to the current time.
+ */
+ public NTPMessage() {
+ // Note that all the other member variables are already set with
+ // appropriate default values.
+ this.mode = 3;
+ this.transmitTimestamp = (System.currentTimeMillis()/1000.0) + 2208988800.0;
+ }
+
+
+
+ /**
+ * This method constructs the data bytes of a raw NTP packet.
+ */
+ public byte[] toByteArray() {
+ // All bytes are automatically set to 0
+ byte[] p = new byte[48];
+
+ p[0] = (byte) (leapIndicator << 6 | version << 3 | mode);
+ p[1] = (byte) stratum;
+ p[2] = pollInterval;
+ p[3] = precision;
+
+ // root delay is a signed 16.16-bit FP, in Java an int is 32-bits
+ int l = (int) (rootDelay * 65536.0);
+ p[4] = (byte) ((l >> 24) & 0xFF);
+ p[5] = (byte) ((l >> 16) & 0xFF);
+ p[6] = (byte) ((l >> 8) & 0xFF);
+ p[7] = (byte) (l & 0xFF);
+
+ // root dispersion is an unsigned 16.16-bit FP, in Java there are no
+ // unsigned primitive types, so we use a long which is 64-bits
+ long ul = (long) (rootDispersion * 65536.0);
+ p[8] = (byte) ((ul >> 24) & 0xFF);
+ p[9] = (byte) ((ul >> 16) & 0xFF);
+ p[10] = (byte) ((ul >> 8) & 0xFF);
+ p[11] = (byte) (ul & 0xFF);
+
+ p[12] = referenceIdentifier[0];
+ p[13] = referenceIdentifier[1];
+ p[14] = referenceIdentifier[2];
+ p[15] = referenceIdentifier[3];
+
+ encodeTimestamp(p, 16, referenceTimestamp);
+ encodeTimestamp(p, 24, originateTimestamp);
+ encodeTimestamp(p, 32, receiveTimestamp);
+ encodeTimestamp(p, 40, transmitTimestamp);
+
+ return p;
+ }
+
+
+
+ /**
+ * Returns a string representation of a NtpMessage
+ */
+ @Override
+ public String toString() {
+ String precisionStr = new DecimalFormat("0.#E0").format(Math.pow(2, precision));
+
+ return "Leap indicator: " + leapIndicator + "\n" +
+ "Version: " + version + "\n" +
+ "Mode: " + mode + "\n" +
+ "Stratum: " + stratum + "\n" +
+ "Poll: " + pollInterval + "\n" +
+ "Precision: " + precision + " (" + precisionStr + " seconds)\n" +
+ "Root delay: " + new DecimalFormat("0.00").format(rootDelay*1000) + " ms\n" +
+ "Root dispersion: " + new DecimalFormat("0.00").format(rootDispersion*1000) + " ms\n" +
+ "Reference identifier: " + referenceIdentifierToString(referenceIdentifier, stratum, version) + "\n" +
+ "Reference timestamp: " + timestampToString(referenceTimestamp) + "\n" +
+ "Originate timestamp: " + timestampToString(originateTimestamp) + "\n" +
+ "Receive timestamp: " + timestampToString(receiveTimestamp) + "\n" +
+ "Transmit timestamp: " + timestampToString(transmitTimestamp);
+ }
+
+
+
+ /**
+ * Converts an unsigned byte to a short. By default, Java assumes that
+ * a byte is signed.
+ */
+ public static short unsignedByteToShort(byte b) {
+ if((b & 0x80)==0x80) {
+ return (short) (128 + (b & 0x7f));
+ } else {
+ return b;
+ }
+ }
+
+
+
+ /**
+ * Will read 8 bytes of a message beginning at <code>pointer</code>
+ * and return it as a double, according to the NTP 64-bit timestamp
+ * format.
+ */
+ public static double decodeTimestamp(byte[] array, int pointer) {
+ double r = 0.0;
+
+ for(int i=0; i<8; i++) {
+ r += unsignedByteToShort(array[pointer+i]) * Math.pow(2, (3-i)*8);
+ }
+
+ return r;
+ }
+
+
+
+ /**
+ * Encodes a timestamp in the specified position in the message
+ */
+ public static void encodeTimestamp(byte[] array, int pointer, double timestamp) {
+ // Converts a double into a 64-bit fixed point
+ for(int i=0; i<8; i++) {
+ // 2^24, 2^16, 2^8, .. 2^-32
+ double base = Math.pow(2, (3-i)*8);
+
+ // Capture byte value
+ array[pointer+i] = (byte) (timestamp / base);
+
+ // Subtract captured value from remaining total
+ timestamp -= (unsignedByteToShort(array[pointer+i]) * base);
+ }
+
+ // From RFC 2030: It is advisable to fill the non-significant
+ // low order bits of the timestamp with a random, unbiased
+ // bitstring, both to avoid systematic roundoff errors and as
+ // a means of loop detection and replay detection.
+ array[7+pointer] = (byte) (random.nextInt(255));
+ }
+
+
+
+ /**
+ * Returns a timestamp (number of seconds since 00:00 1-Jan-1900) as a
+ * formatted date/time string.
+ */
+ public static String timestampToString(double timestamp) {
+ if(timestamp==0) {
+ return "0";
+ }
+
+ // timestamp is relative to 1900, utc is used by Java and is relative
+ // to 1970
+ double utc = timestamp - (2208988800.0);
+
+ // milliseconds
+ long ms = (long) (utc * 1000.0);
+
+ // date/time
+ String date = new SimpleDateFormat("dd-MMM-yyyy HH:mm:ss").format(new Date(ms));
+
+ // fraction
+ double fraction = timestamp - ((long) timestamp);
+ String fractionSting = new DecimalFormat(".000000").format(fraction);
+
+ return date + fractionSting;
+ }
+
+
+
+ /**
+ * Returns a string representation of a reference identifier according
+ * to the rules set out in RFC 2030.
+ */
+ public static String referenceIdentifierToString(byte[] ref, short stratum, byte version) {
+ // From the RFC 2030:
+ // In the case of NTP Version 3 or Version 4 stratum-0 (unspecified)
+ // or stratum-1 (primary) servers, this is a four-character ASCII
+ // string, left justified and zero padded to 32 bits.
+ if(stratum==0 || stratum==1) {
+ return new String(ref);
+ }
+
+ // In NTP Version 3 secondary servers, this is the 32-bit IPv4
+ // address of the reference source.
+ else if(version==3) {
+ return unsignedByteToShort(ref[0]) + "." +
+ unsignedByteToShort(ref[1]) + "." +
+ unsignedByteToShort(ref[2]) + "." +
+ unsignedByteToShort(ref[3]);
+ }
+
+ // In NTP Version 4 secondary servers, this is the low order 32 bits
+ // of the latest transmit timestamp of the reference source.
+ else if(version==4) {
+ return "" + ((unsignedByteToShort(ref[0]) / 256.0) +
+ (unsignedByteToShort(ref[1]) / 65536.0) +
+ (unsignedByteToShort(ref[2]) / 16777216.0) +
+ (unsignedByteToShort(ref[3]) / 4294967296.0));
+ }
+
+ return "";
+ }
+}
Added: trunk/P2Play/src/org/p2play/net/pastry/time/NTPTimeSource.java
===================================================================
--- trunk/P2Play/src/org/p2play/net/pastry/time/NTPTimeSource.java (rev 0)
+++ trunk/P2Play/src/org/p2play/net/pastry/time/NTPTimeSource.java 2006-12-27 18:04:52 UTC (rev 13)
@@ -0,0 +1,151 @@
+/*
+ * 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.pastry.time;
+
+import java.io.IOException;
+import java.io.InterruptedIOException;
+import java.net.DatagramPacket;
+import java.net.DatagramSocket;
+import java.net.InetAddress;
+import java.util.ArrayList;
+import java.util.Collections;
+
+import rice.environment.time.TimeSource;
+
+public class NTPTimeSource implements TimeSource, Runnable {
+
+ private static NTPTimeSource timeSource=new NTPTimeSource();
+
+ private NTPTimeSource() {
+ Thread t=new Thread(this);
+ t.setPriority(Thread.MIN_PRIORITY);
+ t.start();
+ }
+
+ private long currentOffset;
+
+ /** difference between the unix epoch and jan 1 1900 (NTP uses that) */
+ private final static double SECONDS_1900_TO_EPOCH = 2208988800.0;
+ private final static int NTP_PORT = 123;
+
+ private static final String[] NTP_SERVERS = {"ntp1.ptb.de"};
+
+ /**
+ * Query the ntp servers, returning the current time from first one we find
+ *
+ * @return milliseconds since january 1, 1970 (UTC)
+ * @throws IllegalArgumentException if none of the servers are reachable
+ */
+ private static long calculateCurrentOffset(String serverNames[]) {
+ if (serverNames == null) {
+ throw new IllegalArgumentException("No NTP servers specified");
+ }
+ ArrayList<String> names = new ArrayList<String>(serverNames.length);
+ for (String element : serverNames) {
+ names.add(element);
+ }
+ Collections.shuffle(names);
+ for (int i = 0; i < names.size(); i++) {
+ long now = calculateCurrentOffset(names.get(i));
+ if (now != Long.MIN_VALUE) {
+ return now;
+ }
+ }
+ throw new IllegalArgumentException("No reachable NTP servers specified");
+ }
+
+ /**
+ * Query the given NTP server, returning the current internet time
+ *
+ * @return milliseconds since january 1, 1970 (UTC), or -1 on error
+ */
+ private static long calculateCurrentOffset(String serverName) {
+ try {
+ // Send request
+ DatagramSocket socket = new DatagramSocket();
+ InetAddress address = InetAddress.getByName(serverName);
+ byte[] buf = new NTPMessage().toByteArray();
+ DatagramPacket packet = new DatagramPacket(buf, buf.length, address, NTP_PORT);
+
+ // Set the transmit timestamp *just* before sending the packet
+ // ToDo: Does this actually improve performance or not?
+ NTPMessage.encodeTimestamp(packet.getData(), 40,
+ (System.currentTimeMillis()/1000.0)
+ + SECONDS_1900_TO_EPOCH);
+
+ socket.send(packet);
+
+ // Get response
+ packet = new DatagramPacket(buf, buf.length);
+ socket.setSoTimeout(10*1000);
+ try {
+ socket.receive(packet);
+ } catch (InterruptedIOException iie) {
+ socket.close();
+ return -1;
+ }
+
+ // Immediately record the incoming timestamp
+ double destinationTimestamp = (System.currentTimeMillis()/1000.0) + SECONDS_1900_TO_EPOCH;
+
+ // Process response
+ NTPMessage msg = new NTPMessage(packet.getData());
+ /*double roundTripDelay = (destinationTimestamp-msg.originateTimestamp) -
+ (msg.receiveTimestamp-msg.transmitTimestamp);*/
+ double localClockOffset = ((msg.receiveTimestamp - msg.originateTimestamp) +
+ (msg.transmitTimestamp - destinationTimestamp)) / 2;
+ socket.close();
+
+ long rv = (long)(localClockOffset*1000);
+ //System.out.println("host: " + address.getHostAddress() + " rtt: " + roundTripDelay + " offset: " + localClockOffset + " seconds");
+ return rv;
+ } catch (IOException ioe) {
+ //ioe.printStackTrace();
+ return Long.MIN_VALUE;
+ }
+ }
+
+
+ public long currentTimeMillis() {
+ return System.currentTimeMillis()+currentOffset;
+ }
+
+ public void run() {
+ while(true){
+ currentOffset=calculateCurrentOffset(NTP_SERVERS);
+
+ //System.out.println("current offset: "+currentOffset);
+
+ try {
+ Thread.sleep(5000);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+
+ public static NTPTimeSource getTimeSource() {
+ return timeSource;
+ }
+
+ public void sleep(long delay) throws InterruptedException {
+ Thread.sleep(delay);
+ }
+
+}
Added: trunk/P2Play/src/org/p2play/net/pastry/time/TimeManager.java
===================================================================
--- trunk/P2Play/src/org/p2play/net/pastry/time/TimeManager.java (rev 0)
+++ trunk/P2Play/src/org/p2play/net/pastry/time/TimeManager.java 2006-12-27 18:04:52 UTC (rev 13)
@@ -0,0 +1,53 @@
+/*
+ * 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.pastry.time;
+
+import rice.p2p.commonapi.Node;
+
+public class TimeManager {
+ private static TimeManager timeManager;
+
+ private Node node;
+
+ private long baseTime=0;
+
+ private TimeManager(Node node) {
+ super();
+ this.node = node;
+ }
+
+ public static TimeManager getTimeManager() {
+ if(timeManager==null) {
+ throw new IllegalStateException("No TimeManager created. You have to call TimeManager.create() once before using it.");
+ }
+ return timeManager;
+ }
+
+ public static TimeManager create(Node node){
+ if(timeManager==null) {
+ timeManager=new TimeManager(node);
+ }
+
+ return timeManager;
+ }
+
+ public long getGameTime(){
+ return (baseTime+node.getEnvironment().getTimeSource().currentTimeMillis())/100L;
+ }
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ti...@us...> - 2006-12-27 17:39:32
|
Revision: 12
http://p2play.svn.sourceforge.net/p2play/?rev=12&view=rev
Author: tisoft
Date: 2006-12-27 09:39:32 -0800 (Wed, 27 Dec 2006)
Log Message:
-----------
transfered from university cvs
added license header
changed package name to org.p2play.*
Added Paths:
-----------
trunk/P2Play/src/org/p2play/scripting/pnuts/PnutsHandler.java
trunk/P2Play/src/org/p2play/util/logging/
trunk/P2Play/src/org/p2play/util/logging/LogManager.java
trunk/P2Play/src/org/p2play/util/logging/SysoutLogger.java
Added: trunk/P2Play/src/org/p2play/scripting/pnuts/PnutsHandler.java
===================================================================
--- trunk/P2Play/src/org/p2play/scripting/pnuts/PnutsHandler.java (rev 0)
+++ trunk/P2Play/src/org/p2play/scripting/pnuts/PnutsHandler.java 2006-12-27 17:39:32 UTC (rev 12)
@@ -0,0 +1,247 @@
+/*
+ * 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.scripting.pnuts;
+
+/**
+ * NutCracker is an Class that provides a simple possibility to run a Pnuts-Script.
+ * The variable Package rootPackage represents the highest level of available functionality for all scripts.
+ * The Vector packageVector stores a set of custom Packages, to expand the functional range. For all scripts the
+ * should only be ONE set of Packages.
+ *
+ * For each script there should be at least ONE context existing. Each Context will be filled with the
+ * PackageSet available bye the NutCracker-class.
+ *
+ */
+
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.Reader;
+import java.io.StringReader;
+
+import org.p2play.resource.Resource;
+import org.p2play.resource.ResourceClassLoader;
+import org.p2play.scripting.pnuts.manager.PackageHandler;
+
+import pnuts.compiler.Compiler;
+import pnuts.lang.Context;
+import pnuts.lang.Package;
+import pnuts.lang.PackageFactory;
+import pnuts.lang.ParseException;
+import pnuts.lang.Pnuts;
+import pnuts.lang.PnutsFunction;
+
+/**
+ * @author Johannes Lintner, Markus Heberling
+ *
+ * NutCracker provides functionality to work with Pnuts. It stores a Package,
+ * the Script-Source and creates a Context. It also switches between Normal- and
+ * Debug-Mode.
+ *
+ */
+
+public class PnutsHandler implements PackageFactory {
+ private Context context;
+
+ private PackageHandler packageHandler;
+
+ /**
+ * Constructor. It needs the PackagesHandler to add the packages to the
+ * created Context. Creates the Context.
+ *
+ * @param packageHandler,
+ * the PackageHandler, which stores the available PnutsFunctions.
+ */
+ public PnutsHandler(PackageHandler packageHandler) {
+ this.packageHandler = packageHandler;
+ context = this.createContext();
+ }
+
+ /**
+ * Creates a new package, named by pPkgName. The parentPackage is the
+ * Package, which is in the hierarchy the next higher Package.
+ *
+ * @param pPkgName
+ * the name of the new Package
+ * @param parentPackage
+ * the Package, of the next higher layer.
+ *
+ * @return returns the new Package
+ */
+ public Package createPackage(String pPkgName, Package parentPackage) {
+ Package pkg = new Package(pPkgName, parentPackage);
+ return pkg;
+ }
+
+ /**
+ * Creates a Context, filled with the added Packages stored in
+ * PackageHandler. First it creates a new Context, filled with the
+ * rootPackage. If the debug is true, the ScriptDebugger is initiated and a
+ * DebugContext is created. To use the published function, each package are
+ * added to the context.
+ *
+ * @return the created Context
+ */
+ private Context createContext() {
+ Context newContext = new Context(packageHandler.getRootPackage());
+ // Context newContext = new
+ // Terminator(packageHandler.getPackage("ROOT"));
+ newContext.setClassLoader(ResourceClassLoader.getResourceClassLoader());
+ return newContext;
+ }
+
+ /**
+ * Executes a given Pnuts-object
+ *
+ * @param pnuts,
+ * a parsed or compiled Punts-bject
+ * @return Object, returns the result of the executed script.
+ */
+ public Object execute(Pnuts pnuts) {
+ return pnuts.run(context);
+ }
+
+ /**
+ * Calls the given function in the actual context with the specified
+ * parameters
+ *
+ * @param function,
+ * A PnutsFunctions
+ * @param parameters,
+ * A set of parameters expected by the PnutsFunction
+ * @return returns the return value of the called function
+ */
+ protected Object callFunction(PnutsFunction function, Object... parameters) {
+ return function.call(parameters, context);
+ }
+
+ /**
+ * Calls a named function in the actual context with the specified
+ * parameters in a static way
+ *
+ * @param name,
+ * The name of a PnutsFunctions
+ * @param parameters,
+ * A set of parameters expected by the PnutsFunction
+ * @return returns the return value of the called function
+ */
+ public Object callFunction(String name, Object... parameters) {
+ return PnutsFunction.call(name, parameters, context);
+ }
+
+ /**
+ * Parses and, if not debugMode (debug = true), compiles the given Reader
+ * and initializes the ScriptLogger. If a ParseException occurs, the
+ * Exception will also be loged with the ScriptLogger
+ *
+ * @param reader,
+ * A Reader will be parsed to a Pnuts-Object.
+ * @return Pnuts, returns the parsed or compiled Pnuts-Object.
+ */
+ public Pnuts getPnuts(Reader reader) {
+ Pnuts pnuts = null;
+ // LogManager logM = new LogManager();
+ try {
+ pnuts = Pnuts.parse(reader);
+ Compiler comp = new Compiler();
+ pnuts = comp.compile(pnuts, this.context);
+ comp.setTraceMode(true);
+ } catch (ParseException e) {
+ e.printStackTrace();
+ }
+ return pnuts;
+ }
+
+ /**
+ * Parses and, if not debugMode (debug = true), compiles the given String
+ * and initializes the ScriptLogger. If a ParseException occurs, the
+ * Exception will also be loged with the ScriptLogger
+ *
+ * @param reader,
+ * A Reader will be parsed to a Pnuts-Object.
+ * @return Pnuts, returns the parsed or compiled Pnuts-Object.
+ *
+ * @deprecated use getPnuts(String)
+ */
+ public Pnuts compileString(String expr) throws ParseException {
+ Pnuts pnuts = null;
+ try {
+ pnuts = Pnuts.parse(expr);
+ Compiler comp = new Compiler();
+ pnuts = comp.compile(pnuts, this.context);
+ comp.setTraceMode(true);
+ } catch (ParseException e) {
+ e.printStackTrace();
+ }
+ return pnuts;
+ }
+
+ /**
+ * TODO: Change description of param String script!!!
+ *
+ */
+
+ /**
+ * Redirects the call to getPnuts(Reader)
+ *
+ * @param script,
+ * XXXXXXXXXXXXXXXXXXXXXX
+ * @return Pnuts, the parsed or compiled Pnuts-object.
+ */
+ public Pnuts getPnuts(String script) // throws ParseException
+ {
+ return getPnuts(new StringReader(script));
+ }
+
+ /**
+ * Redirects the call to getPnuts(Reader)
+ *
+ * @param inputStream,
+ * the ScriptFile as InputStream.
+ * @return Pnuts, the parsed or compiled Pnuts-object.
+ */
+ public Pnuts getPnuts(InputStream inputStream)// throws ParseException
+ {
+ return getPnuts(new InputStreamReader(inputStream));
+ }
+
+ /**
+ * Redirects the call to getPnuts(Reader)
+ *
+ * @param script,
+ * the ScriptFile as DataStream from the RessourceManager.
+ * @return Pnuts, the parsed or compiled Pnuts-object.
+ */
+ public Pnuts getPnuts(Resource resource)// throws ParseException
+ {
+ return getPnuts(resource.getDataAsStream());
+ }
+
+ /**
+ * Returns the actual context
+ *
+ * @return Context, the actual Context.
+ */
+ public Context getContext() {
+ return this.context;
+ }
+
+ public PackageHandler getPackageHandler() {
+ return packageHandler;
+ }
+}
\ No newline at end of file
Added: trunk/P2Play/src/org/p2play/util/logging/LogManager.java
===================================================================
--- trunk/P2Play/src/org/p2play/util/logging/LogManager.java (rev 0)
+++ trunk/P2Play/src/org/p2play/util/logging/LogManager.java 2006-12-27 17:39:32 UTC (rev 12)
@@ -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.util.logging;
+
+import java.util.Iterator;
+import java.util.Vector;
+
+import rice.environment.logging.Logger;
+
+
+public class LogManager implements rice.environment.logging.LogManager {
+ private Vector<Logger> logger;
+
+ public LogManager() {
+ logger=new Vector<Logger>();
+ }
+
+ public void registerLogger(Logger logger) {
+ this.logger.addElement(logger);
+ }
+
+ public Logger getLogger(Class clazz, String instance) {
+ return new LoggerLogger(this);
+ }
+
+ void log(String message) {
+ Iterator<Logger> iterator = logger
+ .iterator();
+ while (iterator.hasNext()) {
+ Logger logger = iterator.next();
+ logger.log(message);
+ }
+ }
+}
+
+class LoggerLogger extends Logger {
+ private LogManager logmanager;
+
+ public LoggerLogger(LogManager logmanager) {
+ super();
+ this.logmanager = logmanager;
+ level=Logger.WARNING;
+ }
+
+ @Override
+ public void log(String message) {
+ logmanager.log(message);
+ }
+
+ @Override
+ public void logException(String message, Throwable exception) {
+ logmanager.log(message);
+ exception.printStackTrace();
+ }
+}
\ No newline at end of file
Added: trunk/P2Play/src/org/p2play/util/logging/SysoutLogger.java
===================================================================
--- trunk/P2Play/src/org/p2play/util/logging/SysoutLogger.java (rev 0)
+++ trunk/P2Play/src/org/p2play/util/logging/SysoutLogger.java 2006-12-27 17:39:32 UTC (rev 12)
@@ -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.util.logging;
+
+import rice.environment.logging.Logger;
+
+public class SysoutLogger extends Logger {
+
+ @Override
+ public void log(String message) {
+ System.out.println(message);
+ }
+
+ @Override
+ public void logException(String message, Throwable exception) {
+ System.out.println(message);
+ exception.printStackTrace();
+ }
+}
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ti...@us...> - 2006-12-26 23:21:52
|
Revision: 11
http://p2play.svn.sourceforge.net/p2play/?rev=11&view=rev
Author: tisoft
Date: 2006-12-26 15:21:50 -0800 (Tue, 26 Dec 2006)
Log Message:
-----------
transfered from university cvs
added license header
changed package name to org.p2play.*
Added Paths:
-----------
trunk/P2Play/src/org/p2play/resource/
trunk/P2Play/src/org/p2play/resource/Resource.java
trunk/P2Play/src/org/p2play/resource/ResourceClassLoader.java
trunk/P2Play/src/org/p2play/resource/ResourceContainer.java
trunk/P2Play/src/org/p2play/resource/ResourceListener.java
trunk/P2Play/src/org/p2play/resource/ResourceManager.java
trunk/P2Play/src/org/p2play/resource/ResourceURLConnection.java
trunk/P2Play/src/org/p2play/resource/ResourceURLStreamHandler.java
trunk/P2Play/src/org/p2play/resource/impl/
trunk/P2Play/src/org/p2play/resource/impl/ByteArrayResource.java
trunk/P2Play/src/org/p2play/resource/impl/LocalResourceManager.java
Added: trunk/P2Play/src/org/p2play/resource/Resource.java
===================================================================
--- trunk/P2Play/src/org/p2play/resource/Resource.java (rev 0)
+++ trunk/P2Play/src/org/p2play/resource/Resource.java 2006-12-26 23:21:50 UTC (rev 11)
@@ -0,0 +1,28 @@
+/*
+ * 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.resource;
+
+import java.io.InputStream;
+
+import rice.p2p.past.gc.GCPastContent;
+
+public interface Resource extends GCPastContent{
+ public byte[] getData();
+ public InputStream getDataAsStream();
+}
Added: trunk/P2Play/src/org/p2play/resource/ResourceClassLoader.java
===================================================================
--- trunk/P2Play/src/org/p2play/resource/ResourceClassLoader.java (rev 0)
+++ trunk/P2Play/src/org/p2play/resource/ResourceClassLoader.java 2006-12-26 23:21:50 UTC (rev 11)
@@ -0,0 +1,76 @@
+/*
+ * 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.resource;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.HashSet;
+
+public class ResourceClassLoader extends ClassLoader {
+ private ResourceManager resourceManager;
+
+ private static ResourceClassLoader resourceClassLoader;
+
+ public static ResourceClassLoader getResourceClassLoader() {
+ if (resourceClassLoader == null)
+ throw new IllegalStateException(
+ "ResourceClassLoader has not been created yet.");
+ return resourceClassLoader;
+ }
+
+ public static void create(ResourceManager resourceManager) {
+ if (resourceClassLoader != null)
+ throw new IllegalStateException(
+ "ResourceClassLoader has already been created.");
+ resourceClassLoader = new ResourceClassLoader(resourceManager);
+ }
+
+ private ResourceClassLoader(ResourceManager resourceManager) {
+ super();
+ this.resourceManager = resourceManager;
+ }
+
+ @Override
+ public URL getResource(String name) {
+ try {
+ return new URL("PAST", "localhost", 0, name, resourceManager
+ .getURLStreamHandler());
+ } catch (MalformedURLException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ return null;
+ }
+ }
+
+ private HashSet<String> failedClasses = new HashSet<String>();
+
+ @Override
+ public Class<?> loadClass(String name) throws ClassNotFoundException {
+ if (failedClasses.contains(name))
+ throw new ClassNotFoundException();
+ else {
+ try {
+ return super.loadClass(name);
+ } catch (ClassNotFoundException e) {
+ failedClasses.add(name);
+ throw e;
+ }
+ }
+ }
+}
Added: trunk/P2Play/src/org/p2play/resource/ResourceContainer.java
===================================================================
--- trunk/P2Play/src/org/p2play/resource/ResourceContainer.java (rev 0)
+++ trunk/P2Play/src/org/p2play/resource/ResourceContainer.java 2006-12-26 23:21:50 UTC (rev 11)
@@ -0,0 +1,106 @@
+/*
+ * 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.resource;
+
+import javolution.util.FastSet;
+import javolution.util.FastCollection.Record;
+import rice.Continuation;
+
+public class ResourceContainer implements Continuation {
+ private Resource resource;
+
+ private String name;
+
+ private FastSet<ResourceListener> listeners = new FastSet<ResourceListener>();
+
+ private Exception exception;
+
+ public ResourceContainer(String name) {
+ this.name = name;
+ }
+
+ ResourceContainer(String name, Resource resource) {
+ this(name);
+ this.resource = resource;
+ }
+
+ public Resource getResource() {
+ if (exception != null) {
+ throw new RuntimeException(exception);
+ }
+ return resource;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ void setResource(Resource resource) {
+ this.resource = resource;
+ this.exception = null;
+ notifyListeners();
+ }
+
+ void setException(Exception exception) {
+ this.resource = null;
+ this.exception = exception;
+ notifyListeners();
+ }
+
+ public Exception getException() {
+ return exception;
+ }
+
+ public boolean isReady() {
+ return resource != null || exception != null;
+ }
+
+ public void receiveResult(Object result) {
+ setResource((Resource) result);
+ }
+
+ public void receiveException(Exception result) {
+ setException(result);
+ result.printStackTrace();
+ }
+
+ public void removeResourceListener(ResourceListener listener) {
+ synchronized (listeners) {
+ listeners.remove(listener);
+ }
+ }
+
+ public void addResourceListener(ResourceListener listener) {
+ synchronized (listeners) {
+ listeners.add(listener);
+ }
+ }
+
+ private void notifyListeners() {
+ synchronized (listeners) {
+ for (Record r = listeners.head(), end = listeners.tail(); (r = r.getNext()) != end;) {
+ if (exception != null) {
+ listeners.valueOf(r).resourceException(this);
+ } else {
+ listeners.valueOf(r).resourceUpdated(this);
+ }
+ }
+ }
+ }
+}
Added: trunk/P2Play/src/org/p2play/resource/ResourceListener.java
===================================================================
--- trunk/P2Play/src/org/p2play/resource/ResourceListener.java (rev 0)
+++ trunk/P2Play/src/org/p2play/resource/ResourceListener.java 2006-12-26 23:21:50 UTC (rev 11)
@@ -0,0 +1,24 @@
+/*
+ * 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.resource;
+
+public interface ResourceListener {
+ public void resourceUpdated(ResourceContainer container);
+ public void resourceException(ResourceContainer container);
+}
Added: trunk/P2Play/src/org/p2play/resource/ResourceManager.java
===================================================================
--- trunk/P2Play/src/org/p2play/resource/ResourceManager.java (rev 0)
+++ trunk/P2Play/src/org/p2play/resource/ResourceManager.java 2006-12-26 23:21:50 UTC (rev 11)
@@ -0,0 +1,45 @@
+/*
+ * 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.resource;
+
+import java.net.URLStreamHandler;
+
+
+/**
+ * Used to load static resources
+ *
+ * @author markush
+ *
+ */
+public interface ResourceManager {
+ /**
+ * Loads the Resource with the given name
+ *
+ * @param name
+ * The name of the Resource to load
+ * @return the loaded resource
+ * @throws Exception
+ * thrown if the resource could not be retrieved or is not found
+ */
+ public ResourceContainer loadResource(String name);
+
+ public ResourceContainer loadResource(String name, ResourceListener listener);
+
+ public URLStreamHandler getURLStreamHandler();
+}
Added: trunk/P2Play/src/org/p2play/resource/ResourceURLConnection.java
===================================================================
--- trunk/P2Play/src/org/p2play/resource/ResourceURLConnection.java (rev 0)
+++ trunk/P2Play/src/org/p2play/resource/ResourceURLConnection.java 2006-12-26 23:21:50 UTC (rev 11)
@@ -0,0 +1,83 @@
+/*
+ * 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.resource;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+import java.net.URLConnection;
+
+public class ResourceURLConnection extends URLConnection implements ResourceListener {
+
+ private String name;
+
+ private ResourceManager manager;
+
+ private ResourceContainer container;
+
+ public ResourceURLConnection(URL url, ResourceManager manager) {
+ super(url);
+ this.name = url.getFile();
+ this.manager = manager;
+
+ }
+
+ @Override
+ public void connect() throws IOException {
+ if (this.container == null) {
+ this.container = manager.loadResource(name, this);
+ }
+ connected = true;
+ }
+
+ @Override
+ public InputStream getInputStream() throws IOException {
+ if (container == null)
+ connect();
+
+ InputStream inputStream;
+
+ if (!container.isReady()) {
+ synchronized (container) {
+ try {
+ container.wait();
+ } catch (InterruptedException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+ }
+
+ inputStream = this.container.getResource().getDataAsStream();
+
+ return inputStream;
+ }
+
+ public void resourceException(ResourceContainer container) {
+ synchronized (container) {
+ container.notifyAll();
+ }
+ }
+
+ public void resourceUpdated(ResourceContainer container) {
+ synchronized (container) {
+ container.notifyAll();
+ }
+ }
+}
\ No newline at end of file
Added: trunk/P2Play/src/org/p2play/resource/ResourceURLStreamHandler.java
===================================================================
--- trunk/P2Play/src/org/p2play/resource/ResourceURLStreamHandler.java (rev 0)
+++ trunk/P2Play/src/org/p2play/resource/ResourceURLStreamHandler.java 2006-12-26 23:21:50 UTC (rev 11)
@@ -0,0 +1,39 @@
+/*
+ * 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.resource;
+
+import java.io.IOException;
+import java.net.URL;
+import java.net.URLConnection;
+import java.net.URLStreamHandler;
+
+public class ResourceURLStreamHandler extends URLStreamHandler {
+ private ResourceManager resourceManager;
+
+ public ResourceURLStreamHandler(ResourceManager resourceManager) {
+ super();
+ this.resourceManager = resourceManager;
+ }
+
+ @Override
+ protected URLConnection openConnection(URL u) throws IOException {
+ return new ResourceURLConnection(u, resourceManager);
+ }
+
+}
\ No newline at end of file
Added: trunk/P2Play/src/org/p2play/resource/impl/ByteArrayResource.java
===================================================================
--- trunk/P2Play/src/org/p2play/resource/impl/ByteArrayResource.java (rev 0)
+++ trunk/P2Play/src/org/p2play/resource/impl/ByteArrayResource.java 2006-12-26 23:21:50 UTC (rev 11)
@@ -0,0 +1,125 @@
+/*
+ * 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.resource.impl;
+
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+
+import org.p2play.resource.Resource;
+
+import rice.p2p.commonapi.Id;
+import rice.p2p.commonapi.NodeHandle;
+import rice.p2p.past.Past;
+import rice.p2p.past.PastContent;
+import rice.p2p.past.PastContentHandle;
+import rice.p2p.past.PastException;
+import rice.p2p.past.gc.GCPast;
+import rice.p2p.past.gc.GCPastContentHandle;
+import rice.p2p.past.gc.GCPastMetadata;
+
+public class ByteArrayResource implements Resource {
+ private byte[] data;
+
+ private Id id;
+
+ private long version=0;
+
+ private long expiration;
+
+ public ByteArrayResource(Id id, byte[] data, long expiration) {
+ this.data = data;
+ this.id = id;
+ this.expiration=expiration;
+ }
+
+ public ByteArrayResource(Id id, byte[] data) {
+ this(id,data,GCPast.INFINITY_EXPIRATION);
+ }
+
+ public byte[] getData() {
+ return data;
+ }
+
+ public InputStream getDataAsStream(){
+ return new ByteArrayInputStream(data);
+ }
+
+ public PastContent checkInsert(Id id, PastContent existingContent)
+ throws PastException {
+ return this;
+ }
+
+ public PastContentHandle getHandle(final Past local) {
+ return new PastContentHandle(){
+
+ public Id getId() {
+ return id;
+ }
+
+ public NodeHandle getNodeHandle() {
+ return local.getLocalNodeHandle();
+ }};
+ }
+
+ public Id getId() {
+ return id;
+ }
+
+ public boolean isMutable() {
+ return true;
+ }
+
+ @Override
+ public String toString() {
+ return id.toString()+" version: "+version+" content: "+new String(data);
+ }
+
+ public long getVersion() {
+ return version;
+ }
+
+ public long getExpiration() {
+ return expiration;
+ }
+
+ public GCPastContentHandle getHandle(final GCPast local, final long expiration) {
+ return new GCPastContentHandle(){
+
+ public Id getId() {
+ return id;
+ }
+
+ public NodeHandle getNodeHandle() {
+ return local.getLocalNodeHandle();
+ }
+
+ public long getVersion() {
+ return version;
+ }
+
+ public long getExpiration() {
+ return this.getExpiration();
+ }};
+ }
+
+ public GCPastMetadata getMetadata(long expiration) {
+ return new GCPastMetadata(this.expiration);
+ }
+
+}
Added: trunk/P2Play/src/org/p2play/resource/impl/LocalResourceManager.java
===================================================================
--- trunk/P2Play/src/org/p2play/resource/impl/LocalResourceManager.java (rev 0)
+++ trunk/P2Play/src/org/p2play/resource/impl/LocalResourceManager.java 2006-12-26 23:21:50 UTC (rev 11)
@@ -0,0 +1,93 @@
+/*
+ * 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.resource.impl;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.InputStream;
+import java.net.URL;
+import java.net.URLConnection;
+import java.net.URLStreamHandler;
+
+import org.p2play.resource.ResourceContainer;
+import org.p2play.resource.ResourceListener;
+import org.p2play.resource.ResourceManager;
+import org.p2play.resource.ResourceURLStreamHandler;
+
+import rice.environment.Environment;
+import rice.pastry.commonapi.PastryIdFactory;
+
+public class LocalResourceManager implements ResourceManager {
+ private String baseDir;
+
+ private URLStreamHandler streamHandler;
+
+ public LocalResourceManager(String baseDir) {
+ super();
+ this.baseDir = baseDir;
+ this.streamHandler = new ResourceURLStreamHandler(this);
+ }
+
+ public ResourceContainer loadResource(final String name) {
+ final ResourceContainer rc = new ResourceContainer(name);
+ new Thread() {
+ @Override
+ public void run() {
+ try {
+ // Thread.sleep(10000);
+ URL url=getClass().getResource("/"+name);
+
+ int lenght;
+ InputStream inputStream;
+
+ if (url!=null){
+ URLConnection connection=url.openConnection();
+ lenght=connection.getContentLength();
+ inputStream=connection.getInputStream();
+ }
+ else{
+ File f = new File(baseDir + name);
+ inputStream = new FileInputStream(f);
+ lenght = (int) f.length();
+ }
+ byte[] b = new byte[lenght];
+ inputStream.read(b);
+ rc.receiveResult(new ByteArrayResource(new PastryIdFactory(
+ new Environment()).buildId(name), b));
+ } catch (Exception e) {
+ rc.receiveException(e);
+ }
+ }
+ }.start();
+ return rc;
+ }
+
+ public ResourceContainer loadResource(String name, ResourceListener listener) {
+ ResourceContainer rc = loadResource(name);
+ if (rc.isReady()) {
+ listener.resourceUpdated(rc);
+ } else
+ rc.addResourceListener(listener);
+ return rc;
+ }
+
+ public URLStreamHandler getURLStreamHandler() {
+ return streamHandler;
+ }
+}
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ti...@us...> - 2006-12-26 22:59:40
|
Revision: 10
http://p2play.svn.sourceforge.net/p2play/?rev=10&view=rev
Author: tisoft
Date: 2006-12-26 14:59:39 -0800 (Tue, 26 Dec 2006)
Log Message:
-----------
transfered from university cvs
added license header
changed package name to org.p2play.*
Modified Paths:
--------------
trunk/P2Play/src/org/p2play/net/region/RegionInstance.java
Added Paths:
-----------
trunk/P2Play/src/org/p2play/scripting/
trunk/P2Play/src/org/p2play/scripting/pnuts/
trunk/P2Play/src/org/p2play/scripting/pnuts/api/
trunk/P2Play/src/org/p2play/scripting/pnuts/api/ScriptAPI.java
trunk/P2Play/src/org/p2play/scripting/pnuts/api/chat/
trunk/P2Play/src/org/p2play/scripting/pnuts/api/chat/Chat.java
trunk/P2Play/src/org/p2play/scripting/pnuts/api/chat/ChatAPI.java
trunk/P2Play/src/org/p2play/scripting/pnuts/api/statistic/
trunk/P2Play/src/org/p2play/scripting/pnuts/api/statistic/Statistic.java
trunk/P2Play/src/org/p2play/scripting/pnuts/api/statistic/StatisticAPI.java
trunk/P2Play/src/org/p2play/scripting/pnuts/manager/
trunk/P2Play/src/org/p2play/scripting/pnuts/manager/PackageHandler.java
trunk/P2Play/src/org/p2play/util/EmptyIterator.java
trunk/P2Play/src/org/p2play/util/ListMap.java
Removed Paths:
-------------
trunk/P2Play/src/org/p2play/scripted/
Modified: trunk/P2Play/src/org/p2play/net/region/RegionInstance.java
===================================================================
--- trunk/P2Play/src/org/p2play/net/region/RegionInstance.java 2006-12-26 22:18:35 UTC (rev 9)
+++ trunk/P2Play/src/org/p2play/net/region/RegionInstance.java 2006-12-26 22:59:39 UTC (rev 10)
@@ -20,9 +20,7 @@
import java.io.Serializable;
-import org.p2play.net.region.Region;
-
public class RegionInstance implements Serializable{
private Region region;
Copied: trunk/P2Play/src/org/p2play/scripting (from rev 9, trunk/P2Play/src/org/p2play/scripted)
Added: trunk/P2Play/src/org/p2play/scripting/pnuts/api/ScriptAPI.java
===================================================================
--- trunk/P2Play/src/org/p2play/scripting/pnuts/api/ScriptAPI.java (rev 0)
+++ trunk/P2Play/src/org/p2play/scripting/pnuts/api/ScriptAPI.java 2006-12-26 22:59:39 UTC (rev 10)
@@ -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.scripting.pnuts.api;
+
+import org.p2play.scripting.pnuts.manager.PackageHandler;
+
+/**
+ *
+ * @author Johannes Lintner, Markus Heberling
+ *
+ */
+public interface ScriptAPI
+{
+ /**
+ * Add this script API to the package Handler
+ * @param packageHandler
+ */
+ public void registerAPI(PackageHandler packageHandler);
+}
\ No newline at end of file
Added: trunk/P2Play/src/org/p2play/scripting/pnuts/api/chat/Chat.java
===================================================================
--- trunk/P2Play/src/org/p2play/scripting/pnuts/api/chat/Chat.java (rev 0)
+++ trunk/P2Play/src/org/p2play/scripting/pnuts/api/chat/Chat.java 2006-12-26 22:59:39 UTC (rev 10)
@@ -0,0 +1,92 @@
+/*
+ * 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.scripting.pnuts.api.chat;
+
+import java.util.LinkedList;
+import java.util.List;
+import java.util.TreeSet;
+
+import pnuts.lang.Context;
+import pnuts.lang.PnutsFunction;
+
+public class Chat {
+ public static final String TEXT="text";
+ public static final String LEAVE="leave";
+ public static final String JOIN="join";
+
+ private PnutsFunction textCallback;
+
+ private Context context;
+
+ private String channel;
+
+ private String user;
+
+ private ChatAPI chatAPI;
+
+ private TreeSet<String> users;
+
+ public Chat(ChatAPI chatAPI, String channel, String user,
+ PnutsFunction callback, Context context) {
+ super();
+ this.chatAPI = chatAPI;
+ this.channel = channel;
+ this.user = user;
+ this.textCallback = callback;
+ this.context = context;
+ users=new TreeSet<String>();
+ }
+
+ public String getChannel() {
+ return channel;
+ }
+
+ public void sendText(String text) {
+ chatAPI.sendText(channel, user, text);
+ }
+
+ public void leave() {
+ chatAPI.leaveChannel(this);
+ }
+
+ public List<String> getUsers() {
+ return new LinkedList<String>(users);
+ }
+
+ public String getUser() {
+ return user;
+ }
+
+ void userJoined(String user){
+ users.add(user);
+ if (textCallback != null)
+ textCallback.call(new Object[] {Chat.JOIN, this, user, "" }, context);
+ }
+
+ void userLeft(String user){
+ users.remove(user);
+ if (textCallback != null)
+ textCallback.call(new Object[] {Chat.LEAVE, this, user, "" }, context);
+ }
+
+ void receiveMessage(String user, String text) {
+ if (textCallback != null)
+ textCallback.call(new Object[] {Chat.TEXT, this, user, text }, context);
+ }
+}
Added: trunk/P2Play/src/org/p2play/scripting/pnuts/api/chat/ChatAPI.java
===================================================================
--- trunk/P2Play/src/org/p2play/scripting/pnuts/api/chat/ChatAPI.java (rev 0)
+++ trunk/P2Play/src/org/p2play/scripting/pnuts/api/chat/ChatAPI.java 2006-12-26 22:59:39 UTC (rev 10)
@@ -0,0 +1,241 @@
+/*
+ * 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.scripting.pnuts.api.chat;
+
+import java.util.Iterator;
+
+import org.p2play.scripting.pnuts.api.ScriptAPI;
+import org.p2play.scripting.pnuts.manager.PackageHandler;
+import org.p2play.util.ListMap;
+
+import pnuts.lang.Context;
+import pnuts.lang.Package;
+import pnuts.lang.PnutsFunction;
+import rice.p2p.commonapi.Node;
+import rice.p2p.commonapi.NodeHandle;
+import rice.p2p.scribe.Scribe;
+import rice.p2p.scribe.ScribeClient;
+import rice.p2p.scribe.ScribeContent;
+import rice.p2p.scribe.ScribeImpl;
+import rice.p2p.scribe.Topic;
+/**
+ *
+ * @author Marco Giessmann
+ *
+ */
+public class ChatAPI implements ScribeClient, ScriptAPI {
+ private ListMap<String, Chat> callbackMap;
+
+ private Node node;
+
+ private Scribe scribe;
+
+ public ChatAPI(Node node) {
+ this.node = node;
+ this.scribe = new ScribeImpl(node, "scribe.chat");
+ callbackMap = new ListMap<String, Chat>();
+ }
+
+ public void registerAPI(PackageHandler scriptAPI) {
+ Package chatPackage = scriptAPI.getRootPackage();//TODO: Root package for now
+
+ PackageHandler.addFunction(chatPackage, "joinChannel",
+ new PnutsFunction() {
+
+ @Override
+ public boolean defined(int narg) {
+ return narg == 3;
+ }
+
+ @Override
+ protected Object exec(Object[] args, Context context) {
+ return joinChannel(context, (String) args[0],
+ (String) args[1], (PnutsFunction) args[2]);
+
+ }
+ });
+
+ }
+
+ public Chat joinChannel(Context context, String channel, String user,
+ PnutsFunction callback) {
+ Chat chat = new Chat(this, channel, user, callback, context);
+ synchronized (callbackMap) {
+ callbackMap.add(channel, chat);
+ }
+ // System.out.println(channel + ": (join) " + user);
+ scribe.subscribe(new Topic(node.getIdFactory(), channel), this);
+ scribe.publish(new Topic(node.getIdFactory(), chat.getChannel()),
+ new JoinMessage(chat.getChannel(), chat.getUser()));
+ return chat;
+ }
+
+ void sendText(String channel, String user, String text) {
+ // System.out.println(channel + ": " + user + " says: " + text);
+ scribe.publish(new Topic(node.getIdFactory(), channel),
+ new ChatTextMessage(channel, user, text));
+ }
+
+ void leaveChannel(Chat chat) {
+ synchronized (callbackMap) {
+ callbackMap.remove(chat.getChannel(), chat);
+ if (callbackMap.isEmpty(chat.getChannel())) {
+ scribe.publish(
+ new Topic(node.getIdFactory(), chat.getChannel()),
+ new LeaveMessage(chat.getChannel(), chat.getUser()));
+ scribe.unsubscribe(new Topic(node.getIdFactory(), chat
+ .getChannel()), this);
+ }
+ }
+ // System.out.println(channel + ": (leave) " + user);
+ }
+
+ private void receiveText(String channel, String user, String text) {
+ synchronized (callbackMap) {
+ Iterator<Chat> iterator = callbackMap.iterator(channel);
+
+ while (iterator.hasNext()) {
+ Chat fc = iterator.next();
+
+ fc.receiveMessage(user, text);
+ }
+ }
+
+ }
+
+ public boolean anycast(Topic topic, ScribeContent content) {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ public void childAdded(Topic topic, NodeHandle child) {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void childRemoved(Topic topic, NodeHandle child) {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void deliver(Topic topic, ScribeContent content) {
+ if (content instanceof ChatTextMessage) {
+ ChatTextMessage chatMessage = (ChatTextMessage) content;
+
+ receiveText(chatMessage.getChannel(), chatMessage.getUser(),
+ chatMessage.getText());
+ } else if (content instanceof JoinMessage) {
+ JoinMessage joinMessage = (JoinMessage) content;
+ synchronized (callbackMap) {
+ Iterator<Chat> iterator = callbackMap.iterator(joinMessage
+ .getChannel());
+
+ while (iterator.hasNext()) {
+ Chat fc = iterator.next();
+
+ fc.userJoined(joinMessage.getUser());
+ }
+ }
+ } else if (content instanceof LeaveMessage) {
+ LeaveMessage leaveMessage = (LeaveMessage) content;
+ synchronized (callbackMap) {
+ Iterator<Chat> iterator = callbackMap.iterator(leaveMessage
+ .getChannel());
+
+ while (iterator.hasNext()) {
+ Chat fc = iterator.next();
+
+ fc.userJoined(leaveMessage.getUser());
+ }
+ }
+ }
+
+ }
+
+ public void subscribeFailed(Topic topic) {
+ scribe.subscribe(topic, this);
+ }
+}
+
+class ChatTextMessage implements ScribeContent {
+ private String channel;
+
+ private String user;
+
+ private String text;
+
+ public ChatTextMessage(String channel, String user, String text) {
+ super();
+ this.channel = channel;
+ this.user = user;
+ this.text = text;
+ }
+
+ public String getChannel() {
+ return channel;
+ }
+
+ public String getUser() {
+ return user;
+ }
+
+ public String getText() {
+ return text;
+ }
+}
+
+class JoinMessage implements ScribeContent {
+ private String channel;
+
+ private String user;
+
+ public JoinMessage(String channel, String user) {
+ super();
+ this.channel = channel;
+ this.user = user;
+ }
+
+ public String getChannel() {
+ return channel;
+ }
+
+ public String getUser() {
+ return user;
+ }
+}
+
+class LeaveMessage implements ScribeContent {
+ private String channel;
+
+ private String user;
+
+ public LeaveMessage(String channel, String user) {
+ super();
+ this.channel = channel;
+ this.user = user;
+ }
+
+ public String getChannel() {
+ return channel;
+ }
+
+ public String getUser() {
+ return user;
+ }
+}
\ No newline at end of file
Added: trunk/P2Play/src/org/p2play/scripting/pnuts/api/statistic/Statistic.java
===================================================================
--- trunk/P2Play/src/org/p2play/scripting/pnuts/api/statistic/Statistic.java (rev 0)
+++ trunk/P2Play/src/org/p2play/scripting/pnuts/api/statistic/Statistic.java 2006-12-26 22:59:39 UTC (rev 10)
@@ -0,0 +1,83 @@
+/*
+ * 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.scripting.pnuts.api.statistic;
+
+import java.net.InetSocketAddress;
+
+public class Statistic {
+ private int upload = 0;
+ private int download = 0;
+ private int nextCurrentUpload = 0;
+ private int nextCurrentDownload = 0;
+ private int currentUpload = 0;
+ private int currentDownload = 0;
+ private long lastNullifyUpload;
+ private long lastNullifyDownload;
+ private int packageCountUp;
+ private int packageCountDown;
+
+
+ public synchronized int getCurrentDownload() {
+ return currentDownload;
+ }
+ public synchronized int getCurrentUpload() {
+ return currentUpload;
+ }
+ public synchronized int getDownload() {
+ return download;
+ }
+ public synchronized int getUpload() {
+ return upload;
+ }
+
+ synchronized void dataSent(int msgAddress, short msgType, InetSocketAddress socketAddress, int size, int wireType) {
+ // TODO Auto-generated method stub
+ if(System.currentTimeMillis()-lastNullifyUpload>1000){
+ currentUpload=nextCurrentUpload;
+ nextCurrentUpload=0;
+ lastNullifyUpload=System.currentTimeMillis();
+ }
+ upload+=size;
+ nextCurrentUpload+=size;
+ packageCountUp++;
+ }
+
+ synchronized void dataReceived(int msgAddress, short msgType, InetSocketAddress socketAddress, int size, int wireType) {
+ if(System.currentTimeMillis()-lastNullifyDownload>1000){
+ currentDownload=nextCurrentDownload;
+ nextCurrentDownload=0;
+ lastNullifyDownload=System.currentTimeMillis();
+ }
+ download+=size;
+ nextCurrentDownload+=size;
+ packageCountDown++;
+ }
+
+ public synchronized int getPackageSize(){
+ if(packageCountDown+packageCountUp==0)
+ return 0;
+ else
+ return (download+upload)/(packageCountDown+packageCountUp);
+ }
+
+ @Override
+ public String toString() {
+ return "Network Statistics:"+" DOWN: "+getCurrentDownload()+" UP: "+getCurrentUpload()+" DOWN: "+getDownload()+" UP: "+getUpload();
+ }
+}
Added: trunk/P2Play/src/org/p2play/scripting/pnuts/api/statistic/StatisticAPI.java
===================================================================
--- trunk/P2Play/src/org/p2play/scripting/pnuts/api/statistic/StatisticAPI.java (rev 0)
+++ trunk/P2Play/src/org/p2play/scripting/pnuts/api/statistic/StatisticAPI.java 2006-12-26 22:59:39 UTC (rev 10)
@@ -0,0 +1,86 @@
+/*
+ * 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.scripting.pnuts.api.statistic;
+
+import java.net.InetSocketAddress;
+
+import org.p2play.scripting.pnuts.api.ScriptAPI;
+import org.p2play.scripting.pnuts.manager.PackageHandler;
+
+import pnuts.lang.Context;
+import pnuts.lang.Package;
+import pnuts.lang.PnutsFunction;
+import rice.p2p.commonapi.Node;
+import rice.pastry.NetworkListener;
+import rice.pastry.dist.DistPastryNode;
+
+public class StatisticAPI implements NetworkListener, ScriptAPI{
+ private Statistic statistic;
+
+ public StatisticAPI(Node node) {
+ statistic=new Statistic();
+ //only add if we have a DistPastryNode
+ if(node instanceof DistPastryNode)
+ ((DistPastryNode) node).addNetworkListener(this);
+ }
+
+ public void registerAPI(PackageHandler packageHandler) {
+ Package chatPackage = packageHandler.getRootPackage();
+ //TODO: Root package for now
+
+ PackageHandler.addFunction(chatPackage, "getNetStats",
+ new PnutsFunction() {
+
+ @Override
+ public boolean defined(int narg) {
+ return narg == 0;
+ }
+
+ @Override
+ protected Object exec(Object[] args, Context context) {
+ return getNetStats();
+
+ }
+ });
+
+
+ }
+
+ public Statistic getNetStats(){
+ return statistic;
+ }
+
+ public void channelOpened(InetSocketAddress addr, int reason) {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void channelClosed(InetSocketAddress addr) {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void dataSent(int msgAddress, short msgType, InetSocketAddress socketAddress, int size, int wireType) {
+ statistic.dataSent(msgAddress, msgType, socketAddress, size, wireType);
+ }
+
+ public void dataReceived(int msgAddress, short msgType, InetSocketAddress socketAddress, int size, int wireType) {
+ statistic.dataReceived(msgAddress, msgType, socketAddress, size, wireType);
+ }
+}
Added: trunk/P2Play/src/org/p2play/scripting/pnuts/manager/PackageHandler.java
===================================================================
--- trunk/P2Play/src/org/p2play/scripting/pnuts/manager/PackageHandler.java (rev 0)
+++ trunk/P2Play/src/org/p2play/scripting/pnuts/manager/PackageHandler.java 2006-12-26 22:59:39 UTC (rev 10)
@@ -0,0 +1,151 @@
+/*
+ * 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.scripting.pnuts.manager;
+
+
+import java.util.HashMap;
+import java.util.NoSuchElementException;
+
+import pnuts.lang.Package;
+import pnuts.lang.PnutsFunction;
+
+/**
+ * @author Johannes Lintner, Markus Heberling
+ *
+ * PackageHandler stores a set of PnutsFunctions in packages and provides
+ * access.
+ *
+ */
+public class PackageHandler {
+ public String ROOT = "root"+(count++);
+
+ private HashMap<String, Package> pkgMap = new HashMap<String, Package>();
+
+ private static int count = 0;
+
+ public PackageHandler() {
+ newPackage(ROOT,null);
+
+ newPackage("self", getRootPackage());
+ }
+
+ public PackageHandler(Package rootPackage) {
+ ROOT=rootPackage.getName();
+ pkgMap.put(ROOT, rootPackage);
+ }
+
+ /**
+ * Creates a new Package, named pPkgName. If parentPackage is NULL or
+ * "ROOT", the parentPackage will be the GLOBAL rootPackage.
+ *
+ * @param pPkgName
+ * the name of the Package
+ * @param parentPackage
+ * the parent package of the new package
+ *
+ * @return Package returns the new package
+ */
+ public Package newPackage(String pkgName, Package parentPackage) {
+ Package pkg = null;
+
+ if (pkgName.equalsIgnoreCase(ROOT) && parentPackage == null) {
+ pkg = new Package(pkgName);
+ } else {
+ pkgName=pkgName.intern();
+ pkg = new Package(pkgName, parentPackage);
+ parentPackage.set(pkgName, pkg);
+ }
+
+ pkgMap.put(pkgName, pkg);
+ return pkg;
+ }
+
+ /**
+ * Puts a custom function, named by pFunctionName and the defined by the
+ * functionDeclaration (Object) to the Package, defined by pPackage.
+ *
+ * @param pPackage
+ * the Package, the new function should be added to.
+ * @param pFunctionName
+ * the name of the function, with which the function can be
+ * called from the scripts.
+ * @param pObject
+ * to Object casted PnutsFunction, the definition (logic) of the
+ * function
+ */
+ public void setMethod(Package pkg, String pfn, Object obj) {
+ pkg.set(pfn, obj);
+ }
+
+ /**
+ * returns the package specified by pPkgName. Searches in the HashMap<String,
+ * Package> for the given package
+ *
+ * @param pPkgName
+ * the name (key) of the wanted package
+ * @return Package the found package
+ */
+ public Package getPackage(String pkgName) {
+ if(pkgName.equalsIgnoreCase("root"))
+ throw new IllegalArgumentException("Package name may not be ROOT.");
+
+ Package pkg = pkgMap.get(pkgName);
+ if (pkg == null)
+ throw new NoSuchElementException("No such Package: " + pkgName);
+ return pkg;
+ }
+
+ /**
+ * registers a package in the HashMap of Packages.
+ *
+ * @param pkgName,
+ * The name of the package, which should be registred.
+ * @param newPackage,
+ * The Package, which should be registered.
+ */
+ public void putPackage(String pkgName, Package newPackage) {
+ pkgMap.put(pkgName, newPackage);
+ }
+
+ /**
+ * Gives back a HashMap<String, Package>, containing the names of the
+ * Packages as keys and the packages itself as values. With Object []
+ * packages = ScriptAPI.getAllPackages().keySet().toArray(); you get an
+ * Array of the keys of all packages. Read out e.g. with for (int index = 0;
+ * index < functions.length; index++)
+ * System.out.println(functions[index].toString());
+ *
+ * @return HashMap<String, Package>, containing the names as keys and the
+ * packages as values
+ */
+ public HashMap<String, Package> getAllPackages() {
+ if (pkgMap == null || pkgMap.isEmpty())
+ throw new NoSuchElementException("There are no Packages available");
+ return pkgMap;
+ }
+
+ public Package getRootPackage() {
+ return getPackage(ROOT);
+ }
+
+ public static void addFunction(Package package1, String name,
+ PnutsFunction function) {
+ package1.set(name.intern(), function);
+ }
+}
Added: trunk/P2Play/src/org/p2play/util/EmptyIterator.java
===================================================================
--- trunk/P2Play/src/org/p2play/util/EmptyIterator.java (rev 0)
+++ trunk/P2Play/src/org/p2play/util/EmptyIterator.java 2006-12-26 22:59:39 UTC (rev 10)
@@ -0,0 +1,37 @@
+/*
+ * 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.util;
+
+import java.util.Iterator;
+import java.util.NoSuchElementException;
+
+public class EmptyIterator<E> implements Iterator<E> {
+ public boolean hasNext() {
+ return false;
+ }
+
+ public E next() {
+ throw new NoSuchElementException();
+ }
+
+ public void remove() {
+
+ }
+
+}
\ No newline at end of file
Added: trunk/P2Play/src/org/p2play/util/ListMap.java
===================================================================
--- trunk/P2Play/src/org/p2play/util/ListMap.java (rev 0)
+++ trunk/P2Play/src/org/p2play/util/ListMap.java 2006-12-26 22:59:39 UTC (rev 10)
@@ -0,0 +1,161 @@
+/*
+ * 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.util;
+
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import javolution.util.FastList;
+import javolution.util.FastMap;
+
+public class ListMap<K, V> implements Iterable<K> {
+ private Map<K, List<V>> map;
+
+ public ListMap() {
+ map = new FastMap<K, List<V>>();
+ }
+
+ public void add(K key, V value) {
+ synchronized (map) {
+ if (!getOrCreateList(key).contains(value)) {
+ getOrCreateList(key).add(value);
+ }
+ }
+ }
+
+ public void remove(K key, V value) {
+ synchronized (map) {
+ getOrCreateList(key).remove(value);
+ if (isEmpty(key)) {
+ map.remove(key);
+ }
+ }
+ }
+
+ public List<V> remove(K key) {
+ return map.remove(key);
+ }
+
+ public List<V> getList(K key) {
+ synchronized (map) {
+ return map.get(key);
+ }
+ }
+
+ private List<V> getOrCreateList(K key) {
+ synchronized (map) {
+ List<V> list = getList(key);
+ if (list == null) {
+ list = new FastList<V>();
+ map.put(key, list);
+ }
+
+ return list;
+ }
+ }
+
+ public boolean isEmpty(K key) {
+ synchronized (map) {
+ return getList(key) == null || getList(key).isEmpty();
+ }
+ }
+
+ public Set<K> keySet() {
+ synchronized (map) {
+ return map.keySet();
+ }
+ }
+
+ public void clear() {
+ synchronized (map) {
+ map.clear();
+ }
+ }
+
+ public boolean containsKey(K key) {
+ synchronized (map) {
+ return map.containsKey(key) && map.get(key) != null
+ && !((List) map.get(key)).isEmpty();
+ }
+ }
+
+ public boolean contains(K key, V value) {
+ synchronized (map) {
+ return getOrCreateList(key).contains(value);
+ }
+ }
+
+ /**
+ * Iterator of all values associated with the given key
+ *
+ * @param key
+ * @return
+ */
+ public Iterator<V> iterator(K key) {
+ synchronized (map) {
+ if (containsKey(key)) {
+ return getList(key).iterator();
+ } else {
+ return new EmptyIterator<V>();
+ }
+ }
+ }
+
+ /**
+ * Iterator of all values associated with the given key changes
+ *
+ * @param key
+ * @return
+ */
+ public Iterator<V> clonedIterator(K key) {
+ synchronized (map) {
+ if (containsKey(key)) {
+ return new FastList<V>(getList(key)).iterator();
+ } else {
+ return new EmptyIterator<V>();
+ }
+ }
+ }
+
+ /**
+ * cloned Iterator of the keys
+ *
+ * @return
+ */
+ public Iterator<K> clonedIterator() {
+ return new HashSet<K>(keySet()).iterator();
+ }
+
+ /**
+ * Iterator of the keys
+ *
+ * @return
+ */
+ public Iterator<K> iterator() {
+ return keySet().iterator();
+ }
+
+ @Override
+ public String toString() {
+ return map.toString();
+ }
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ti...@us...> - 2006-12-26 22:18:38
|
Revision: 9
http://p2play.svn.sourceforge.net/p2play/?rev=9&view=rev
Author: tisoft
Date: 2006-12-26 14:18:35 -0800 (Tue, 26 Dec 2006)
Log Message:
-----------
transfered from university cvs
added license header
changed package name to org.p2play.*
Added Paths:
-----------
trunk/P2Play/src/org/
trunk/P2Play/src/org/p2play/
trunk/P2Play/src/org/p2play/io/
trunk/P2Play/src/org/p2play/io/Serializer.java
trunk/P2Play/src/org/p2play/io/impl/
trunk/P2Play/src/org/p2play/io/impl/JavaSerializerImpl.java
trunk/P2Play/src/org/p2play/net/
trunk/P2Play/src/org/p2play/net/region/
trunk/P2Play/src/org/p2play/net/region/Client.java
trunk/P2Play/src/org/p2play/net/region/GameAction.java
trunk/P2Play/src/org/p2play/net/region/GameState.java
trunk/P2Play/src/org/p2play/net/region/Region.java
trunk/P2Play/src/org/p2play/net/region/RegionInstance.java
trunk/P2Play/src/org/p2play/net/region/RegionManager.java
trunk/P2Play/src/org/p2play/net/region/Server.java
trunk/P2Play/src/org/p2play/net/region/ServerFactory.java
trunk/P2Play/src/org/p2play/net/region/message/
trunk/P2Play/src/org/p2play/net/region/message/GameActionMessage.java
trunk/P2Play/src/org/p2play/net/region/message/GameStateHashMessage.java
trunk/P2Play/src/org/p2play/net/region/message/GameStateMessage.java
trunk/P2Play/src/org/p2play/net/region/message/JoinMessage.java
trunk/P2Play/src/org/p2play/net/region/message/MessageDeserializer.java
trunk/P2Play/src/org/p2play/net/region/message/RegionMessage.java
trunk/P2Play/src/org/p2play/scripted/
trunk/P2Play/src/org/p2play/util/
trunk/P2Play/src/org/p2play/util/Hashable.java
trunk/P2Play/src/org/p2play/util/Hasher.java
trunk/P2Play/src/org/p2play/util/NetRandom.java
Added: trunk/P2Play/src/org/p2play/io/Serializer.java
===================================================================
--- trunk/P2Play/src/org/p2play/io/Serializer.java (rev 0)
+++ trunk/P2Play/src/org/p2play/io/Serializer.java 2006-12-26 22:18:35 UTC (rev 9)
@@ -0,0 +1,48 @@
+/*
+ * 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.io;
+
+import java.io.IOException;
+
+import rice.p2p.commonapi.rawserialization.InputBuffer;
+import rice.p2p.commonapi.rawserialization.OutputBuffer;
+
+/**
+ * This interface is used to serialize/deserialize Objects.
+ *
+ * @author Markus Heberling <ma...@ti...>
+ *
+ */
+public interface Serializer {
+ /**
+ * This method takes an object and writes its contents into the given output buffer.
+ * @param object
+ * @param outputBuffer
+ * @throws IOException
+ */
+ public void serialize(Object object, OutputBuffer outputBuffer) throws IOException;
+
+ /**
+ * The method reads one object out of the biffer and returns it
+ * @param inputBuffer
+ * @return
+ * @throws IOException
+ */
+ public Object deserialize(InputBuffer inputBuffer) throws IOException;
+}
Added: trunk/P2Play/src/org/p2play/io/impl/JavaSerializerImpl.java
===================================================================
--- trunk/P2Play/src/org/p2play/io/impl/JavaSerializerImpl.java (rev 0)
+++ trunk/P2Play/src/org/p2play/io/impl/JavaSerializerImpl.java 2006-12-26 22:18:35 UTC (rev 9)
@@ -0,0 +1,61 @@
+/*
+ * 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.io.impl;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+
+import org.p2play.io.Serializer;
+
+import rice.p2p.commonapi.rawserialization.InputBuffer;
+import rice.p2p.commonapi.rawserialization.OutputBuffer;
+
+/**
+ * Serialize/deserialize objects with java serialization
+ *
+ * @author Markus Heberling <ma...@ti...>
+ *
+ */
+public class JavaSerializerImpl implements Serializer{
+ public Object deserialize(InputBuffer inputBuffer) throws IOException {
+ byte[] byteArray=new byte[inputBuffer.readInt()];
+ inputBuffer.read(byteArray);
+ ByteArrayInputStream byteArrayInputStream=new ByteArrayInputStream(byteArray);
+ ObjectInputStream objectInputStream=new ObjectInputStream(byteArrayInputStream);
+ try {
+ return objectInputStream.readObject();
+ } catch (ClassNotFoundException e) {
+ throw new IOException(e.getMessage());
+ }
+ }
+
+ public void serialize(Object object, OutputBuffer outputBuffer) throws IOException {
+ ByteArrayOutputStream byteArrayOutputStream=new ByteArrayOutputStream();
+ ObjectOutputStream objectOutputStream=new ObjectOutputStream(byteArrayOutputStream);
+
+ objectOutputStream.writeObject(object);
+
+ byte[] byteArray = byteArrayOutputStream.toByteArray();
+ outputBuffer.writeInt(byteArray.length);
+ outputBuffer.write(byteArray, 0, byteArray.length);
+ }
+}
Added: trunk/P2Play/src/org/p2play/net/region/Client.java
===================================================================
--- trunk/P2Play/src/org/p2play/net/region/Client.java (rev 0)
+++ trunk/P2Play/src/org/p2play/net/region/Client.java 2006-12-26 22:18:35 UTC (rev 9)
@@ -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.net.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);
+}
Added: trunk/P2Play/src/org/p2play/net/region/GameAction.java
===================================================================
--- trunk/P2Play/src/org/p2play/net/region/GameAction.java (rev 0)
+++ trunk/P2Play/src/org/p2play/net/region/GameAction.java 2006-12-26 22:18:35 UTC (rev 9)
@@ -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.net.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();
+}
Added: trunk/P2Play/src/org/p2play/net/region/GameState.java
===================================================================
--- trunk/P2Play/src/org/p2play/net/region/GameState.java (rev 0)
+++ trunk/P2Play/src/org/p2play/net/region/GameState.java 2006-12-26 22:18:35 UTC (rev 9)
@@ -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.net.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
Added: trunk/P2Play/src/org/p2play/net/region/Region.java
===================================================================
--- trunk/P2Play/src/org/p2play/net/region/Region.java (rev 0)
+++ trunk/P2Play/src/org/p2play/net/region/Region.java 2006-12-26 22:18:35 UTC (rev 9)
@@ -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.net.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();
+}
Added: trunk/P2Play/src/org/p2play/net/region/RegionInstance.java
===================================================================
--- trunk/P2Play/src/org/p2play/net/region/RegionInstance.java (rev 0)
+++ trunk/P2Play/src/org/p2play/net/region/RegionInstance.java 2006-12-26 22:18:35 UTC (rev 9)
@@ -0,0 +1,56 @@
+/*
+ * 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;
+
+import java.io.Serializable;
+
+import org.p2play.net.region.Region;
+
+
+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;
+ }
+}
Added: trunk/P2Play/src/org/p2play/net/region/RegionManager.java
===================================================================
--- trunk/P2Play/src/org/p2play/net/region/RegionManager.java (rev 0)
+++ trunk/P2Play/src/org/p2play/net/region/RegionManager.java 2006-12-26 22:18:35 UTC (rev 9)
@@ -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.net.region;
+
+import org.p2play.net.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
Added: trunk/P2Play/src/org/p2play/net/region/Server.java
===================================================================
--- trunk/P2Play/src/org/p2play/net/region/Server.java (rev 0)
+++ trunk/P2Play/src/org/p2play/net/region/Server.java 2006-12-26 22:18:35 UTC (rev 9)
@@ -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.net.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);
+}
Added: trunk/P2Play/src/org/p2play/net/region/ServerFactory.java
===================================================================
--- trunk/P2Play/src/org/p2play/net/region/ServerFactory.java (rev 0)
+++ trunk/P2Play/src/org/p2play/net/region/ServerFactory.java 2006-12-26 22:18:35 UTC (rev 9)
@@ -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.net.region;
+
+public interface ServerFactory{
+ public Server getServer(Region region);
+}
\ No newline at end of file
Added: trunk/P2Play/src/org/p2play/net/region/message/GameActionMessage.java
===================================================================
--- trunk/P2Play/src/org/p2play/net/region/message/GameActionMessage.java (rev 0)
+++ trunk/P2Play/src/org/p2play/net/region/message/GameActionMessage.java 2006-12-26 22:18:35 UTC (rev 9)
@@ -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.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
Added: trunk/P2Play/src/org/p2play/net/region/message/GameStateHashMessage.java
===================================================================
--- trunk/P2Play/src/org/p2play/net/region/message/GameStateHashMessage.java (rev 0)
+++ trunk/P2Play/src/org/p2play/net/region/message/GameStateHashMessage.java 2006-12-26 22:18:35 UTC (rev 9)
@@ -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.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 ;
+ }
+
+
+}
Added: trunk/P2Play/src/org/p2play/net/region/message/GameStateMessage.java
===================================================================
--- trunk/P2Play/src/org/p2play/net/region/message/GameStateMessage.java (rev 0)
+++ trunk/P2Play/src/org/p2play/net/region/message/GameStateMessage.java 2006-12-26 22:18:35 UTC (rev 9)
@@ -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.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
Added: trunk/P2Play/src/org/p2play/net/region/message/JoinMessage.java
===================================================================
--- trunk/P2Play/src/org/p2play/net/region/message/JoinMessage.java (rev 0)
+++ trunk/P2Play/src/org/p2play/net/region/message/JoinMessage.java 2006-12-26 22:18:35 UTC (rev 9)
@@ -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.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
Added: trunk/P2Play/src/org/p2play/net/region/message/MessageDeserializer.java
===================================================================
--- trunk/P2Play/src/org/p2play/net/region/message/MessageDeserializer.java (rev 0)
+++ trunk/P2Play/src/org/p2play/net/region/message/MessageDeserializer.java 2006-12-26 22:18:35 UTC (rev 9)
@@ -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.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;
+ }
+}
Added: trunk/P2Play/src/org/p2play/net/region/message/RegionMessage.java
===================================================================
--- trunk/P2Play/src/org/p2play/net/region/message/RegionMessage.java (rev 0)
+++ trunk/P2Play/src/org/p2play/net/region/message/RegionMessage.java 2006-12-26 22:18:35 UTC (rev 9)
@@ -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.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
Added: trunk/P2Play/src/org/p2play/util/Hashable.java
===================================================================
--- trunk/P2Play/src/org/p2play/util/Hashable.java (rev 0)
+++ trunk/P2Play/src/org/p2play/util/Hashable.java 2006-12-26 22:18:35 UTC (rev 9)
@@ -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.util;
+
+public interface Hashable {
+ public int hash();
+}
Added: trunk/P2Play/src/org/p2play/util/Hasher.java
===================================================================
--- trunk/P2Play/src/org/p2play/util/Hasher.java (rev 0)
+++ trunk/P2Play/src/org/p2play/util/Hasher.java 2006-12-26 22:18:35 UTC (rev 9)
@@ -0,0 +1,136 @@
+/*
+ * 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.util;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.UnsupportedEncodingException;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Random;
+
+
+public class Hasher {
+ @SuppressWarnings("unchecked")
+ public static int hash(Object object) {
+ //System.out.println("Hashing: " + object);
+ if (object == null) {
+ return 0;
+ } else if (object instanceof Hashable) {
+ return hash((Hashable) object);
+
+ }else if (object instanceof byte[]) {
+ return hash((byte[]) object);
+
+ } else if (object instanceof Map) {
+ return hash((Map) object);
+
+ }else if (object instanceof Collection) {
+ return hash((Collection<Object>) object);
+
+ }else if (object instanceof String) {
+ return hash((String) object);
+
+ } else if (object instanceof Boolean) {
+ return hash((Boolean) object);
+
+ } else if (object instanceof Integer) {
+ return hash((Integer) object);
+
+ } else if (object instanceof Float) {
+ return hash((Float) object);
+
+ }else if (object instanceof Random) {
+ return hash((Random) object);
+
+ } else {
+ System.out
+ .println("Hasher got called with invalid object of type: "
+ + object.getClass());
+ return 0;
+ }
+ }
+
+ private static int hash(String object) {
+ try {
+ return hash(object.getBytes("UTF-8"));
+ } catch (UnsupportedEncodingException e) {
+ e.printStackTrace();
+ }
+ return 0;
+ }
+ private static int hash(byte[] object) {
+ int hash=0;
+
+ for (byte element : object) {
+ hash=hash^element;
+ }
+
+ return 0;
+ }
+ private static int hash(Hashable object) {
+ return object.hash();
+ }
+ private static int hash(Random object) {
+ //clone the random object, so that it doesn't get changed during hashing and take the next int as hash
+ ByteArrayOutputStream bos=new ByteArrayOutputStream();
+ Random cloned;
+ try {
+ new ObjectOutputStream (bos).writeObject(object);
+ cloned = (Random) new ObjectInputStream(new ByteArrayInputStream(bos.toByteArray())).readObject();
+ } catch (IOException e) {
+ cloned=new Random(0);
+ }catch (ClassNotFoundException e) {
+ cloned=new Random(0);
+ }
+
+ return cloned.nextInt();
+ }
+
+ private static int hash(Integer object) {
+ return object.intValue();
+ }
+
+ private static int hash(Boolean object) {
+ return object==true ? 1 : 0;
+ }
+
+ private static int hash(Float object) {
+ return Float.floatToIntBits(object.floatValue());
+ }
+ private static int hash(Collection<Object> col) {
+ int hash = 0;
+ Iterator<Object> iterator = col.iterator();
+
+ while (iterator.hasNext()) {
+ Object object = iterator.next();
+
+ hash^=(Hasher.hash(object));
+ }
+ return hash;
+ }
+ @SuppressWarnings("unchecked")
+ private static int hash(Map map) {
+ return hash(map.values());
+ }
+}
Added: trunk/P2Play/src/org/p2play/util/NetRandom.java
===================================================================
--- trunk/P2Play/src/org/p2play/util/NetRandom.java (rev 0)
+++ trunk/P2Play/src/org/p2play/util/NetRandom.java 2006-12-26 22:18:35 UTC (rev 9)
@@ -0,0 +1,249 @@
+/*
+ * 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.util;
+
+import java.io.IOException;
+import java.io.ObjectOutputStream;
+import java.util.Random;
+
+import rice.p2p.commonapi.rawserialization.InputBuffer;
+import rice.p2p.commonapi.rawserialization.OutputBuffer;
+
+/**
+ * changed readObject and writeObject to use much less space
+ *
+ * @author Markus Heberling <ma...@ti...>
+ *
+ */
+
+public class NetRandom extends Random {
+
+ private long seed;
+
+ private final static long multiplier = 0x5DEECE66DL;
+ private final static long mask = (1L << 48) - 1;
+
+ /**
+ * Creates a new random number generator. This constructor sets the seed of
+ * the random number generator to a value very likely to be distinct from
+ * any other invocation of this constructor.
+ */
+ public NetRandom() {
+ super();
+ }
+
+ /**
+ * Creates a new random number generator using a single <code>long</code>
+ * seed: <blockquote>
+ *
+ * <pre>
+ * public Random(long seed) {
+ * setSeed(seed);
+ * }
+ * </pre>
+ *
+ * </blockquote> Used by method <tt>next</tt> to hold the state of the
+ * pseudorandom number generator.
+ *
+ * @param seed
+ * the initial seed.
+ * @see java.util.Random#setSeed(long)
+ */
+ public NetRandom(long seed) {
+ super(seed);
+ }
+
+ /**
+ * Sets the seed of this random number generator using a single
+ * <code>long</code> seed. The general contract of <tt>setSeed</tt> is
+ * that it alters the state of this random number generator object so as to
+ * be in exactly the same state as if it had just been created with the
+ * argument <tt>seed</tt> as a seed. The method <tt>setSeed</tt> is
+ * implemented by class Random as follows: <blockquote>
+ *
+ * <pre>
+ * synchronized public void setSeed(long seed) {
+ * this.seed = (seed ˆ 0x5DEECE66DL) & ((1L << 48) - 1);
+ * haveNextNextGaussian = false;
+ * }
+ * </pre>
+ *
+ * </blockquote> The implementation of <tt>setSeed</tt> by class
+ * <tt>Random</tt> happens to use only 48 bits of the given seed. In
+ * general, however, an overriding method may use all 64 bits of the long
+ * argument as a seed value.
+ *
+ * Note: Although the seed value is an AtomicLong, this method must still be
+ * synchronized to ensure correct semantics of haveNextNextGaussian.
+ *
+ * @param seed
+ * the initial seed.
+ */
+ @Override
+ synchronized public void setSeed(long seed) {
+ this.seed = (seed ^ multiplier) & mask;
+ haveNextNextGaussian = false;
+ }
+
+ /**
+ * Generates the next pseudorandom number. Subclass should override this, as
+ * this is used by all other methods.
+ * <p>
+ * The general contract of <tt>next</tt> is that it returns an
+ * <tt>int</tt> value and if the argument bits is between <tt>1</tt> and
+ * <tt>32</tt> (inclusive), then that many low-order bits of the returned
+ * value will be (approximately) independently chosen bit values, each of
+ * which is (approximately) equally likely to be <tt>0</tt> or <tt>1</tt>.
+ * The method <tt>next</tt> is implemented by class <tt>Random</tt> as
+ * follows: <blockquote>
+ *
+ * <pre>
+ * synchronized protected int next(int bits) {
+ * seed = (seed * 0x5DEECE66DL + 0xBL) & ((1L << 48) - 1);
+ * return (int) (seed >>> (48 - bits));
+ * }
+ * </pre>
+ *
+ * </blockquote> This is a linear congruential pseudorandom number
+ * generator, as defined by D. H. Lehmer and described by Donald E. Knuth in
+ * <i>The Art of Computer Programming,</i> Volume 2: <i>Seminumerical
+ * Algorithms</i>, section 3.2.1.
+ *
+ * @param bits
+ * random bits
+ * @return the next pseudorandom value from this random number generator's
+ * sequence.
+ * @since JDK1.1
+ */
+ @Override
+ protected int next(int bits) {
+ seed = (seed * 0x5DEECE66DL + 0xBL) & ((1L << 48) - 1);
+ return (int) (seed >>> (48 - bits));
+ }
+
+ private double nextNextGaussian;
+
+ private boolean haveNextNextGaussian = false;
+
+ /**
+ * Returns the next pseudorandom, Gaussian ("normally") distributed
+ * <code>double</code> value with mean <code>0.0</code> and standard
+ * deviation <code>1.0</code> from this random number generator's
+ * sequence.
+ * <p>
+ * The general contract of <tt>nextGaussian</tt> is that one
+ * <tt>double</tt> value, chosen from (approximately) the usual normal
+ * distribution with mean <tt>0.0</tt> and standard deviation <tt>1.0</tt>,
+ * is pseudorandomly generated and returned. The method
+ * <tt>nextGaussian</tt> is implemented by class <tt>Random</tt> as
+ * follows: <blockquote>
+ *
+ * <pre>
+ * synchronized public double nextGaussian() {
+ * if (haveNextNextGaussian) {
+ * haveNextNextGaussian = false;
+ * return nextNextGaussian;
+ * } else {
+ * double v1, v2, s;
+ * do {
+ * v1 = 2 * nextDouble() - 1; // between -1.0 and 1.0
+ * v2 = 2 * nextDouble() - 1; // between -1.0 and 1.0
+ * s = v1 * v1 + v2 * v2;
+ * } while (s >= 1 || s == 0);
+ * double multiplier = Math.sqrt(-2 * Math.log(s) / s);
+ * nextNextGaussian = v2 * multiplier;
+ * haveNextNextGaussian = true;
+ * return v1 * multiplier;
+ * }
+ * }
+ * </pre>
+ *
+ * </blockquote> This uses the <i>polar method</i> of G. E. P. Box, M. E.
+ * Muller, and G. Marsaglia, as described by Donald E. Knuth in <i>The Art
+ * of Computer Programming</i>, Volume 2: <i>Seminumerical Algorithms</i>,
+ * section 3.4.1, subsection C, algorithm P. Note that it generates two
+ * independent values at the cost of only one call to <tt>Math.log</tt>
+ * and one call to <tt>Math.sqrt</tt>.
+ *
+ * @return the next pseudorandom, Gaussian ("normally") distributed
+ * <code>double</code> value with mean <code>0.0</code> and
+ * standard deviation <code>1.0</code> from this random number
+ * generator's sequence.
+ */
+ @Override
+ synchronized public double nextGaussian() {
+ if (haveNextNextGaussian) {
+ haveNextNextGaussian = false;
+ return nextNextGaussian;
+ } else {
+ double v1, v2, s;
+ do {
+ v1 = 2 * nextDouble() - 1; // between -1 and 1
+ v2 = 2 * nextDouble() - 1; // between -1 and 1
+ s = v1 * v1 + v2 * v2;
+ } while (s >= 1 || s == 0);
+ double multiplier = Math.sqrt(-2 * Math.log(s) / s);
+ nextNextGaussian = v2 * multiplier;
+ haveNextNextGaussian = true;
+ return v1 * multiplier;
+ }
+ }
+
+ /**
+ * Reconstitute the <tt>Random</tt> instance from a stream (that is,
+ * deserialize it). The seed is read in as long for historical reasons, but
+ * it is converted to an AtomicLong.
+ */
+ private void readObject(java.io.ObjectInputStream s)
+ throws java.io.IOException, ClassNotFoundException {
+ seed = s.readLong();
+ haveNextNextGaussian = s.readBoolean();
+ if (haveNextNextGaussian)
+ nextNextGaussian = s.readDouble();
+ }
+
+ public NetRandom(InputBuffer buffer) throws IOException {
+ seed = buffer.readLong();
+ haveNextNextGaussian = buffer.readBoolean();
+ if (haveNextNextGaussian)
+ nextNextGaussian = buffer.readDouble();
+ }
+
+ /**
+ * Save the <tt>Random</tt> instance to a stream. The seed of a Random is
+ * serialized as a long for historical reasons.
+ *
+ */
+ synchronized private void writeObject(ObjectOutputStream s)
+ throws IOException {
+ s.writeLong(seed);
+ s.writeBoolean(haveNextNextGaussian);
+ if (haveNextNextGaussian)
+ s.writeDouble(nextNextGaussian);
+ }
+
+ synchronized public void doSerialize(OutputBuffer buffer)
+ throws IOException {
+ buffer.writeLong(seed);
+ buffer.writeBoolean(haveNextNextGaussian);
+ if (haveNextNextGaussian)
+ buffer.writeDouble(nextNextGaussian);
+ }
+
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ti...@us...> - 2006-12-26 22:14:23
|
Revision: 8
http://p2play.svn.sourceforge.net/p2play/?rev=8&view=rev
Author: tisoft
Date: 2006-12-26 14:14:24 -0800 (Tue, 26 Dec 2006)
Log Message:
-----------
added needed libs and sources for better IDE integration
Modified Paths:
--------------
trunk/P2Play/.classpath
Added Paths:
-----------
trunk/P2Play/lib/
trunk/P2Play/lib/FreePastry.jar
trunk/P2Play/lib/javolution.jar
trunk/P2Play/lib/jdom.jar
trunk/P2Play/lib/pnuts.jar
trunk/P2Play/lib/sources/
trunk/P2Play/lib/sources/FreePastry-source.zip
trunk/P2Play/lib/sources/javolution-4.1.0-src.zip
trunk/P2Play/lib/sources/jdom-1.0.zip
trunk/P2Play/lib/sources/pnuts-1.2-src.zip
trunk/P2Play/lib/xpp3-1.1.3.4d_b2.jar
trunk/P2Play/lib/xstream-1.1.3.jar
Modified: trunk/P2Play/.classpath
===================================================================
--- trunk/P2Play/.classpath 2006-12-26 16:09:00 UTC (rev 7)
+++ trunk/P2Play/.classpath 2006-12-26 22:14:24 UTC (rev 8)
@@ -2,5 +2,11 @@
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+ <classpathentry exported="true" kind="lib" path="lib/FreePastry.jar" sourcepath="lib/sources/FreePastry-source.zip"/>
+ <classpathentry exported="true" kind="lib" path="lib/javolution.jar" sourcepath="lib/sources/javolution-4.1.0-src.zip"/>
+ <classpathentry exported="true" kind="lib" path="lib/pnuts.jar" sourcepath="lib/sources/pnuts-1.2-src.zip"/>
+ <classpathentry exported="true" kind="lib" path="lib/jdom.jar" sourcepath="lib/sources/jdom-1.0.zip"/>
+ <classpathentry exported="true" kind="lib" path="lib/xstream-1.1.3.jar"/>
+ <classpathentry exported="true" kind="lib" path="lib/xpp3-1.1.3.4d_b2.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>
Added: trunk/P2Play/lib/FreePastry.jar
===================================================================
(Binary files differ)
Property changes on: trunk/P2Play/lib/FreePastry.jar
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: trunk/P2Play/lib/javolution.jar
===================================================================
(Binary files differ)
Property changes on: trunk/P2Play/lib/javolution.jar
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: trunk/P2Play/lib/jdom.jar
===================================================================
(Binary files differ)
Property changes on: trunk/P2Play/lib/jdom.jar
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: trunk/P2Play/lib/pnuts.jar
===================================================================
(Binary files differ)
Property changes on: trunk/P2Play/lib/pnuts.jar
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: trunk/P2Play/lib/sources/FreePastry-source.zip
===================================================================
(Binary files differ)
Property changes on: trunk/P2Play/lib/sources/FreePastry-source.zip
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: trunk/P2Play/lib/sources/javolution-4.1.0-src.zip
===================================================================
(Binary files differ)
Property changes on: trunk/P2Play/lib/sources/javolution-4.1.0-src.zip
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: trunk/P2Play/lib/sources/jdom-1.0.zip
===================================================================
(Binary files differ)
Property changes on: trunk/P2Play/lib/sources/jdom-1.0.zip
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: trunk/P2Play/lib/sources/pnuts-1.2-src.zip
===================================================================
(Binary files differ)
Property changes on: trunk/P2Play/lib/sources/pnuts-1.2-src.zip
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: trunk/P2Play/lib/xpp3-1.1.3.4d_b2.jar
===================================================================
(Binary files differ)
Property changes on: trunk/P2Play/lib/xpp3-1.1.3.4d_b2.jar
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: trunk/P2Play/lib/xstream-1.1.3.jar
===================================================================
(Binary files differ)
Property changes on: trunk/P2Play/lib/xstream-1.1.3.jar
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ti...@us...> - 2006-12-26 16:09:02
|
Revision: 7
http://p2play.svn.sourceforge.net/p2play/?rev=7&view=rev
Author: tisoft
Date: 2006-12-26 08:09:00 -0800 (Tue, 26 Dec 2006)
Log Message:
-----------
added lgpl license
Added Paths:
-----------
trunk/P2Play/.settings/org.eclipse.jdt.ui.prefs
trunk/P2Play/LICENSE.txt
Added: trunk/P2Play/.settings/org.eclipse.jdt.ui.prefs
===================================================================
--- trunk/P2Play/.settings/org.eclipse.jdt.ui.prefs (rev 0)
+++ trunk/P2Play/.settings/org.eclipse.jdt.ui.prefs 2006-12-26 16:09:00 UTC (rev 7)
@@ -0,0 +1,3 @@
+#Tue Dec 26 17:03:28 CET 2006
+eclipse.preferences.version=1
+org.eclipse.jdt.ui.text.custom_code_templates=<?xml version\="1.0" encoding\="UTF-8"?><templates><template autoinsert\="true" context\="gettercomment_context" deleted\="false" description\="Comment for getter method" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.gettercomment" name\="gettercomment">/**\n * @return the ${bare_field_name}\n */</template><template autoinsert\="true" context\="settercomment_context" deleted\="false" description\="Comment for setter method" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.settercomment" name\="settercomment">/**\n * @param ${param} the ${bare_field_name} to set\n */</template><template autoinsert\="true" context\="constructorcomment_context" deleted\="false" description\="Comment for created constructors" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.constructorcomment" name\="constructorcomment">/**\n * ${tags}\n */</template><template autoinsert\="false" context\="filecomment_context" deleted\="false" description\="Comment for created Java files" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.filecomment" name\="filecomment">/*\n * Copyright ${year} P2Play.org\n * All rights reserved.\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n * \n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * Lesser General Public License for more details.\n * \n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA\n */</template><template autoinsert\="true" context\="typecomment_context" deleted\="false" description\="Comment for created types" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.typecomment" name\="typecomment">/**\n * @author ${user}\n *\n * ${tags}\n */</template><template autoinsert\="true" context\="fieldcomment_context" deleted\="false" description\="Comment for fields" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.fieldcomment" name\="fieldcomment">/**\n * \n */</template><template autoinsert\="true" context\="methodcomment_context" deleted\="false" description\="Comment for non-overriding methods" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.methodcomment" name\="methodcomment">/**\n * ${tags}\n */</template><template autoinsert\="true" context\="overridecomment_context" deleted\="false" description\="Comment for overriding methods" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.overridecomment" name\="overridecomment">/* (non-Javadoc)\n * ${see_to_overridden}\n */</template><template autoinsert\="true" context\="delegatecomment_context" deleted\="false" description\="Comment for delegate methods" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.delegatecomment" name\="delegatecomment">/**\n * ${tags}\n * ${see_to_target}\n */</template><template autoinsert\="true" context\="newtype_context" deleted\="false" description\="Newly created files" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.newtype" name\="newtype">${filecomment}\n${package_declaration}\n\n${typecomment}\n${type_declaration}</template><template autoinsert\="true" context\="classbody_context" deleted\="false" description\="Code in new class type bodies" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.classbody" name\="classbody">\n</template><template autoinsert\="true" context\="interfacebody_context" deleted\="false" description\="Code in new interface type bodies" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.interfacebody" name\="interfacebody">\n</template><template autoinsert\="true" context\="enumbody_context" deleted\="false" description\="Code in new enum type bodies" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.enumbody" name\="enumbody">\n</template><template autoinsert\="true" context\="annotationbody_context" deleted\="false" description\="Code in new annotation type bodies" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.annotationbody" name\="annotationbody">\n</template><template autoinsert\="true" context\="catchblock_context" deleted\="false" description\="Code in new catch blocks" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.catchblock" name\="catchblock">// ${todo} Auto-generated catch block\n${exception_var}.printStackTrace();</template><template autoinsert\="true" context\="methodbody_context" deleted\="false" description\="Code in created method stubs" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.methodbody" name\="methodbody">// ${todo} Auto-generated method stub\n${body_statement}</template><template autoinsert\="true" context\="constructorbody_context" deleted\="false" description\="Code in created constructor stubs" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.constructorbody" name\="constructorbody">${body_statement}\n// ${todo} Auto-generated constructor stub</template><template autoinsert\="true" context\="getterbody_context" deleted\="false" description\="Code in created getters" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.getterbody" name\="getterbody">return ${field};</template><template autoinsert\="true" context\="setterbody_context" deleted\="false" description\="Code in created setters" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.setterbody" name\="setterbody">${field} \= ${param};</template></templates>
Added: trunk/P2Play/LICENSE.txt
===================================================================
--- trunk/P2Play/LICENSE.txt (rev 0)
+++ trunk/P2Play/LICENSE.txt 2006-12-26 16:09:00 UTC (rev 7)
@@ -0,0 +1,458 @@
+ GNU LESSER GENERAL PUBLIC LICENSE
+ Version 2.1, February 1999
+
+ Copyright (C) 1991, 1999 Free Software Foundation, Inc.
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+[This is the first released version of the Lesser GPL. It also counts
+ as the successor of the GNU Library Public License, version 2, hence
+ the version number 2.1.]
+
+ Preamble
+
+ The licenses for most software are designed to take away your
+freedom to share and change it. By contrast, the GNU General Public
+Licenses are intended to guarantee your freedom to share and change
+free software--to make sure the software is free for all its users.
+
+ This license, the Lesser General Public License, applies to some
+specially designated software packages--typically libraries--of the
+Free Software Foundation and other authors who decide to use it. You
+can use it too, but we suggest you first think carefully about whether
+this license or the ordinary General Public License is the better
+strategy to use in any particular case, based on the explanations below.
+
+ When we speak of free software, we are referring to freedom of use,
+not price. Our General Public Licenses are designed to make sure that
+you have the freedom to distribute copies of free software (and charge
+for this service if you wish); that you receive source code or can get
+it if you want it; that you can change the software and use pieces of
+it in new free programs; and that you are informed that you can do
+these things.
+
+ To protect your rights, we need to make restrictions that forbid
+distributors to deny you these rights or to ask you to surrender these
+rights. These restrictions translate to certain responsibilities for
+you if you distribute copies of the library or if you modify it.
+
+ For example, if you distribute copies of the library, whether gratis
+or for a fee, you must give the recipients all the rights that we gave
+you. You must make sure that they, too, receive or can get the source
+code. If you link other code with the library, you must provide
+complete object files to the recipients, so that they can relink them
+with the library after making changes to the library and recompiling
+it. And you must show them these terms so they know their rights.
+
+ We protect your rights with a two-step method: (1) we copyright the
+library, and (2) we offer you this license, which gives you legal
+permission to copy, distribute and/or modify the library.
+
+ To protect each distributor, we want to make it very clear that
+there is no warranty for the free library. Also, if the library is
+modified by someone else and passed on, the recipients should know
+that what they have is not the original version, so that the original
+author's reputation will not be affected by problems that might be
+introduced by others.
+
+ Finally, software patents pose a constant threat to the existence of
+any free program. We wish to make sure that a company cannot
+effectively restrict the users of a free program by obtaining a
+restrictive license from a patent holder. Therefore, we insist that
+any patent license obtained for a version of the library must be
+consistent with the full freedom of use specified in this license.
+
+ Most GNU software, including some libraries, is covered by the
+ordinary GNU General Public License. This license, the GNU Lesser
+General Public License, applies to certain designated libraries, and
+is quite different from the ordinary General Public License. We use
+this license for certain libraries in order to permit linking those
+libraries into non-free programs.
+
+ When a program is linked with a library, whether statically or using
+a shared library, the combination of the two is legally speaking a
+combined work, a derivative of the original library. The ordinary
+General Public License therefore permits such linking only if the
+entire combination fits its criteria of freedom. The Lesser General
+Public License permits more lax criteria for linking other code with
+the library.
+
+ We call this license the "Lesser" General Public License because it
+does Less to protect the user's freedom than the ordinary General
+Public License. It also provides other free software developers Less
+of an advantage over competing non-free programs. These disadvantages
+are the reason we use the ordinary General Public License for many
+libraries. However, the Lesser license provides advantages in certain
+special circumstances.
+
+ For example, on rare occasions, there may be a special need to
+encourage the widest possible use of a certain library, so that it becomes
+a de-facto standard. To achieve this, non-free programs must be
+allowed to use the library. A more frequent case is that a free
+library does the same job as widely used non-free libraries. In this
+case, there is little to gain by limiting the free library to free
+software only, so we use the Lesser General Public License.
+
+ In other cases, permission to use a particular library in non-free
+programs enables a greater number of people to use a large body of
+free software. For example, permission to use the GNU C Library in
+non-free programs enables many more people to use the whole GNU
+operating system, as well as its variant, the GNU/Linux operating
+system.
+
+ Although the Lesser General Public License is Less protective of the
+users' freedom, it does ensure that the user of a program that is
+linked with the Library has the freedom and the wherewithal to run
+that program using a modified version of the Library.
+
+ The precise terms and conditions for copying, distribution and
+modification follow. Pay close attention to the difference between a
+"work based on the library" and a "work that uses the library". The
+former contains code derived from the library, whereas the latter must
+be combined with the library in order to run.
+
+ GNU LESSER GENERAL PUBLIC LICENSE
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+
+ 0. This License Agreement applies to any software library or other
+program which contains a notice placed by the copyright holder or
+other authorized party saying it may be distributed under the terms of
+this Lesser General Public License (also called "this License").
+Each licensee is addressed as "you".
+
+ A "library" means a collection of software functions and/or data
+prepared so as to be conveniently linked with application programs
+(which use some of those functions and data) to form executables.
+
+ The "Library", below, refers to any such software library or work
+which has been distributed under these terms. A "work based on the
+Library" means either the Library or any derivative work under
+copyright law: that is to say, a work containing the Library or a
+portion of it, either verbatim or with modifications and/or translated
+straightforwardly into another language. (Hereinafter, translation is
+included without limitation in the term "modification".)
+
+ "Source code" for a work means the preferred form of the work for
+making modifications to it. For a library, complete source code means
+all the source code for all modules it contains, plus any associated
+interface definition files, plus the scripts used to control compilation
+and installation of the library.
+
+ Activities other than copying, distribution and modification are not
+covered by this License; they are outside its scope. The act of
+running a program using the Library is not restricted, and output from
+such a program is covered only if its contents constitute a work based
+on the Library (independent of the use of the Library in a tool for
+writing it). Whether that is true depends on what the Library does
+and what the program that uses the Library does.
+
+ 1. You may copy and distribute verbatim copies of the Library's
+complete source code as you receive it, in any medium, provided that
+you conspicuously and appropriately publish on each copy an
+appropriate copyright notice and disclaimer of warranty; keep intact
+all the notices that refer to this License and to the absence of any
+warranty; and distribute a copy of this License along with the
+Library.
+
+ You may charge a fee for the physical act of transferring a copy,
+and you may at your option offer warranty protection in exchange for a
+fee.
+
+ 2. You may modify your copy or copies of the Library or any portion
+of it, thus forming a work based on the Library, and copy and
+distribute such modifications or work under the terms of Section 1
+above, provided that you also meet all of these conditions:
+
+ a) The modified work must itself be a software library.
+
+ b) You must cause the files modified to carry prominent notices
+ stating that you changed the files and the date of any change.
+
+ c) You must cause the whole of the work to be licensed at no
+ charge to all third parties under the terms of this License.
+
+ d) If a facility in the modified Library refers to a function or a
+ table of data to be supplied by an application program that uses
+ the facility, other than as an argument passed when the facility
+ is invoked, then you must make a good faith effort to ensure that,
+ in the event an application does not supply such function or
+ table, the facility still operates, and performs whatever part of
+ its purpose remains meaningful.
+
+ (For example, a function in a library to compute square roots has
+ a purpose that is entirely well-defined independent of the
+ application. Therefore, Subsection 2d requires that any
+ application-supplied function or table used by this function must
+ be optional: if the application does not supply it, the square
+ root function must still compute square roots.)
+
+These requirements apply to the modified work as a whole. If
+identifiable sections of that work are not derived from the Library,
+and can be reasonably considered independent and separate works in
+themselves, then this License, and its terms, do not apply to those
+sections when you distribute them as separate works. But when you
+distribute the same sections as part of a whole which is a work based
+on the Library, the distribution of the whole must be on the terms of
+this License, whose permissions for other licensees extend to the
+entire whole, and thus to each and every part regardless of who wrote
+it.
+
+Thus, it is not the intent of this section to claim rights or contest
+your rights to work written entirely by you; rather, the intent is to
+exercise the right to control the distribution of derivative or
+collective works based on the Library.
+
+In addition, mere aggregation of another work not based on the Library
+with the Library (or with a work based on the Library) on a volume of
+a storage or distribution medium does not bring the other work under
+the scope of this License.
+
+ 3. You may opt to apply the terms of the ordinary GNU General Public
+License instead of this License to a given copy of the Library. To do
+this, you must alter all the notices that refer to this License, so
+that they refer to the ordinary GNU General Public License, version 2,
+instead of to this License. (If a newer version than version 2 of the
+ordinary GNU General Public License has appeared, then you can specify
+that version instead if you wish.) Do not make any other change in
+these notices.
+
+ Once this change is made in a given copy, it is irreversible for
+that copy, so the ordinary GNU General Public License applies to all
+subsequent copies and derivative works made from that copy.
+
+ This option is useful when you wish to copy part of the code of
+the Library into a program that is not a library.
+
+ 4. You may copy and distribute the Library (or a portion or
+derivative of it, under Section 2) in object code or executable form
+under the terms of Sections 1 and 2 above provided that you accompany
+it with the complete corresponding machine-readable source code, which
+must be distributed under the terms of Sections 1 and 2 above on a
+medium customarily used for software interchange.
+
+ If distribution of object code is made by offering access to copy
+from a designated place, then offering equivalent access to copy the
+source code from the same place satisfies the requirement to
+distribute the source code, even though third parties are not
+compelled to copy the source along with the object code.
+
+ 5. A program that contains no derivative of any portion of the
+Library, but is designed to work with the Library by being compiled or
+linked with it, is called a "work that uses the Library". Such a
+work, in isolation, is not a derivative work of the Library, and
+therefore falls outside the scope of this License.
+
+ However, linking a "work that uses the Library" with the Library
+creates an executable that is a derivative of the Library (because it
+contains portions of the Library), rather than a "work that uses the
+library". The executable is therefore covered by this License.
+Section 6 states terms for distribution of such executables.
+
+ When a "work that uses the Library" uses material from a header file
+that is part of the Library, the object code for the work may be a
+derivative work of the Library even though the source code is not.
+Whether this is true is especially significant if the work can be
+linked without the Library, or if the work is itself a library. The
+threshold for this to be true is not precisely defined by law.
+
+ If such an object file uses only numerical parameters, data
+structure layouts and accessors, and small macros and small inline
+functions (ten lines or less in length), then the use of the object
+file is unrestricted, regardless of whether it is legally a derivative
+work. (Executables containing this object code plus portions of the
+Library will still fall under Section 6.)
+
+ Otherwise, if the work is a derivative of the Library, you may
+distribute the object code for the work under the terms of Section 6.
+Any executables containing that work also fall under Section 6,
+whether or not they are linked directly with the Library itself.
+
+ 6. As an exception to the Sections above, you may also combine or
+link a "work that uses the Library" with the Library to produce a
+work containing portions of the Library, and distribute that work
+under terms of your choice, provided that the terms permit
+modification of the work for the customer's own use and reverse
+engineering for debugging such modifications.
+
+ You must give prominent notice with each copy of the work that the
+Library is used in it and that the Library and its use are covered by
+this License. You must supply a copy of this License. If the work
+during execution displays copyright notices, you must include the
+copyright notice for the Library among them, as well as a reference
+directing the user to the copy of this License. Also, you must do one
+of these things:
+
+ a) Accompany the work with the complete corresponding
+ machine-readable source code for the Library including whatever
+ changes were used in the work (which must be distributed under
+ Sections 1 and 2 above); and, if the work is an executable linked
+ with the Library, with the complete machine-readable "work that
+ uses the Library", as object code and/or source code, so that the
+ user can modify the Library and then relink to produce a modified
+ executable containing the modified Library. (It is understood
+ that the user who changes the contents of definitions files in the
+ Library will not necessarily be able to recompile the application
+ to use the modified definitions.)
+
+ b) Use a suitable shared library mechanism for linking with the
+ Library. A suitable mechanism is one that (1) uses at run time a
+ copy of the library already present on the user's computer system,
+ rather than copying library functions into the executable, and (2)
+ will operate properly with a modified version of the library, if
+ the user installs one, as long as the modified version is
+ interface-compatible with the version that the work was made with.
+
+ c) Accompany the work with a written offer, valid for at
+ least three years, to give the same user the materials
+ specified in Subsection 6a, above, for a charge no more
+ than the cost of performing this distribution.
+
+ d) If distribution of the work is made by offering access to copy
+ from a designated place, offer equivalent access to copy the above
+ specified materials from the same place.
+
+ e) Verify that the user has already received a copy of these
+ materials or that you have already sent this user a copy.
+
+ For an executable, the required form of the "work that uses the
+Library" must include any data and utility programs needed for
+reproducing the executable from it. However, as a special exception,
+the materials to be distributed need not include anything that is
+normally distributed (in either source or binary form) with the major
+components (compiler, kernel, and so on) of the operating system on
+which the executable runs, unless that component itself accompanies
+the executable.
+
+ It may happen that this requirement contradicts the license
+restrictions of other proprietary libraries that do not normally
+accompany the operating system. Such a contradiction means you cannot
+use both them and the Library together in an executable that you
+distribute.
+
+ 7. You may place library facilities that are a work based on the
+Library side-by-side in a single library together with other library
+facilities not covered by this License, and distribute such a combined
+library, provided that the separate distribution of the work based on
+the Library and of the other library facilities is otherwise
+permitted, and provided that you do these two things:
+
+ a) Accompany the combined library with a copy of the same work
+ based on the Library, uncombined with any other library
+ facilities. This must be distributed under the terms of the
+ Sections above.
+
+ b) Give prominent notice with the combined library of the fact
+ that part of it is a work based on the Library, and explaining
+ where to find the accompanying uncombined form of the same work.
+
+ 8. You may not copy, modify, sublicense, link with, or distribute
+the Library except as expressly provided under this License. Any
+attempt otherwise to copy, modify, sublicense, link with, or
+distribute the Library is void, and will automatically terminate your
+rights under this License. However, parties who have received copies,
+or rights, from you under this License will not have their licenses
+terminated so long as such parties remain in full compliance.
+
+ 9. You are not required to accept this License, since you have not
+signed it. However, nothing else grants you permission to modify or
+distribute the Library or its derivative works. These actions are
+prohibited by law if you do not accept this License. Therefore, by
+modifying or distributing the Library (or any work based on the
+Library), you indicate your acceptance of this License to do so, and
+all its terms and conditions for copying, distributing or modifying
+the Library or works based on it.
+
+ 10. Each time you redistribute the Library (or any work based on the
+Library), the recipient automatically receives a license from the
+original licensor to copy, distribute, link with or modify the Library
+subject to these terms and conditions. You may not impose any further
+restrictions on the recipients' exercise of the rights granted herein.
+You are not responsible for enforcing compliance by third parties with
+this License.
+
+ 11. If, as a consequence of a court judgment or allegation of patent
+infringement or for any other reason (not limited to patent issues),
+conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License. If you cannot
+distribute so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you
+may not distribute the Library at all. For example, if a patent
+license would not permit royalty-free redistribution of the Library by
+all those who receive copies directly or indirectly through you, then
+the only way you could satisfy both it and this License would be to
+refrain entirely from distribution of the Library.
+
+If any portion of this section is held invalid or unenforceable under any
+particular circumstance, the balance of the section is intended to apply,
+and the section as a whole is intended to apply in other circumstances.
+
+It is not the purpose of this section to induce you to infringe any
+patents or other property right claims or to contest validity of any
+such claims; this section has the sole purpose of protecting the
+integrity of the free software distribution system which is
+implemented by public license practices. Many people have made
+generous contributions to the wide range of software distributed
+through that system in reliance on consistent application of that
+system; it is up to the author/donor to decide if he or she is willing
+to distribute software through any other system and a licensee cannot
+impose that choice.
+
+This section is intended to make thoroughly clear what is believed to
+be a consequence of the rest of this License.
+
+ 12. If the distribution and/or use of the Library is restricted in
+certain countries either by patents or by copyrighted interfaces, the
+original copyright holder who places the Library under this License may add
+an explicit geographical distribution limitation excluding those countries,
+so that distribution is permitted only in or among countries not thus
+excluded. In such case, this License incorporates the limitation as if
+written in the body of this License.
+
+ 13. The Free Software Foundation may publish revised and/or new
+versions of the Lesser General Public License from time to time.
+Such new versions will be similar in spirit to the present version,
+but may differ in detail to address new problems or concerns.
+
+Each version is given a distinguishing version number. If the Library
+specifies a version number of this License which applies to it and
+"any later version", you have the option of following the terms and
+conditions either of that version or of any later version published by
+the Free Software Foundation. If the Library does not specify a
+license version number, you may choose any version ever published by
+the Free Software Foundation.
+
+ 14. If you wish to incorporate parts of the Library into other free
+programs whose distribution conditions are incompatible with these,
+write to the author to ask for permission. For software which is
+copyrighted by the Free Software Foundation, write to the Free
+Software Foundation; we sometimes make exceptions for this. Our
+decision will be guided by the two goals of preserving the free status
+of all derivatives of our free software and of promoting the sharing
+and reuse of software generally.
+
+ NO WARRANTY
+
+ 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
+WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
+EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
+OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY
+KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
+LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME
+THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
+
+ 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
+WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY
+AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU
+FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR
+CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
+LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
+RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
+FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
+SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
+DAMAGES.
+
+ END OF TERMS AND CONDITIONS
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|