Imported GNU Classpath gcj-import-20051117.

* gnu/java/net/protocol/file/Connection.java: Removed, fully merged.
       * sources.am: Regenerated.
       * Makefile.in: Likewise.

From-SVN: r107153
This commit is contained in:
Mark Wielaard
2005-11-18 00:59:33 +00:00
parent fb3a09c214
commit ca9e049bc1
102 changed files with 6716 additions and 1722 deletions

View File

@@ -20,7 +20,7 @@ endif
endif
# All our example java source files
EXAMPLE_JAVA_FILES = $(srcdir)/gnu/classpath/examples/*/*.java
EXAMPLE_JAVA_FILES = $(srcdir)/gnu/classpath/examples/*/*.java $(srcdir)/gnu/classpath/examples/*/*/*.java $(srcdir)/gnu/classpath/examples/*/*/*/*.java
# The example C source files
EXAMPLE_C_FILES = $(srcdir)/gnu/classpath/examples/*/*.c
@@ -34,8 +34,11 @@ BUILT_SOURCES = $(EXAMPLE_ZIP)
# the png icons we use in some of the examples.
EXAMPLE_ICONS = $(srcdir)/gnu/classpath/examples/icons/*.png
# The example specific README files.
READMES = $(srcdir)/gnu/classpath/examples/CORBA/swing/README.html
# All the files we find "interesting"
ALL_EXAMPLE_FILES = $(EXAMPLE_JAVA_FILES) $(EXAMPLE_C_FILES) $(EXAMPLE_ICONS)
ALL_EXAMPLE_FILES = $(EXAMPLE_JAVA_FILES) $(EXAMPLE_C_FILES) $(EXAMPLE_ICONS) $(READMES)
# Some architecture independent data to be installed.
example_DATA = $(EXAMPLE_ZIP) README

View File

@@ -263,7 +263,7 @@ vm_classes = @vm_classes@
@FOUND_GCJ_TRUE@JCOMPILER = $(GCJ) --bootclasspath '$(top_builddir)/lib' --classpath . -C
# All our example java source files
EXAMPLE_JAVA_FILES = $(srcdir)/gnu/classpath/examples/*/*.java
EXAMPLE_JAVA_FILES = $(srcdir)/gnu/classpath/examples/*/*.java $(srcdir)/gnu/classpath/examples/*/*/*.java $(srcdir)/gnu/classpath/examples/*/*/*/*.java
# The example C source files
EXAMPLE_C_FILES = $(srcdir)/gnu/classpath/examples/*/*.c
@@ -277,8 +277,11 @@ BUILT_SOURCES = $(EXAMPLE_ZIP)
# the png icons we use in some of the examples.
EXAMPLE_ICONS = $(srcdir)/gnu/classpath/examples/icons/*.png
# The example specific README files.
READMES = $(srcdir)/gnu/classpath/examples/CORBA/swing/README.html
# All the files we find "interesting"
ALL_EXAMPLE_FILES = $(EXAMPLE_JAVA_FILES) $(EXAMPLE_C_FILES) $(EXAMPLE_ICONS)
ALL_EXAMPLE_FILES = $(EXAMPLE_JAVA_FILES) $(EXAMPLE_C_FILES) $(EXAMPLE_ICONS) $(READMES)
# Some architecture independent data to be installed.
example_DATA = $(EXAMPLE_ZIP) README

View File

@@ -0,0 +1,493 @@
<html>
<head>
<title>Five-in-a-row v 0.0</title>
</head>
<body LANG="en-US">
<h1>
<i>Five-in-a-row
</i> 0.0 supplementary documentation
</h1>
<h3>Introduction and rules
</h3>
<p>
<i>Five-in-a-row
</i> is a two player strategy game. The players
are connected via network using CORBA-based RMI/IIOP protocol and
make they moves with the help of the Swing-based
interface. While playing, the users can also chat.
</p>
<p>The system consists of the single server and any number of
interconnected players. The person, willing to play, starts the
client and connects the server. The server redirects call to the
partner that has previously connected the same server, also willing
to play.
</p>
<p>The game desk is a field where it is possible to set O's
and X'es, one per move. The goal is to get five O's in a row while
preventing your partner from getting five X's in a row. Vertical,
horizontal and diagonal rows are allowed. The system detects the
loss-victory situation on the desk, but currently does not serve as a
playing partner, requiring at least two human players for this game.
</p>
<p>Both players can at any time reset the game (restarting it with
the same player) or leave the game (disconnecting). The disconnected
player can contact the game manager again, requesting to find another
partner.
</p>
<p>Simple as it is, the application has some features of the typical
role playing game that frequently just has more states, actions,
possible moves and also provides far richer graphics environment. The
game manger serves as a World-Wide-Pub where you can always find a
partner to play.
The players can made both unsynchronized (chatting, game reset and
leaving) and synchronized (moves) actions. The game state changes
while playing, and the set of the available actions depends on the
current state. Finally, the mouse and canvas are involved. However
using RMI/IIOP machinery allowed to implement all this functionality
with just 13 classes (plus 4 generated), all of them being rather
simple.
This example refers to the standard classes only and must be buildable
from your IDE as long as it has any java 1.4 compiler.
</p>
<p>
The used IIOP protocol must ensure interoperability, allowing players
to use different java virtual machines and operating systems.
The processors may have the opposite byte order.
</p>
<h3>Configuration and run
</h3>
<p>The game manager server executable class is
<i>gnu.classpath.examples.CORBA.swing.x5.X5Server
</i>. After start,
it will print to console the Internet address that must be entered to
the client to reach the manager.
</p>
<p>The client executable class it
<i>gnu.classpath.examples.CORBA.swing.x5.Demo
</i>.
</p>
<p>The game should run with GNU Classpath
0.19 and Sun Microsystems java 1.5.0_04. Due later fixed bugs it will
not run with the older versions of these two implementations.
</p>
<p>The game manager HTTP server uses port
1500. Hence all firewalls between the server and the player must be
configured to allow HTTP on 1500. The ports, used by the RMI/IIOP are
not persistent. GNU Classpath is configured to take ports 1501, 1502
and 1503 (the firewalls must allow to use them for RMI/IIOP). The
CORBA implementation other than Classpath may use different port
values. Unfortunately, there is no standard method to configure the
used port range in a vendor-independent way.
</p>
<h3>The game server
</h3>
<p>The game manager is first reachable via http:// protocol (for
instance http://123.456.7.89:1500). The simple server at this port
always serves much longer string, representing the CORBA stringified
object reference (IOR). The
<i>Five-in-a-row&nbsp;
</i>client uses
this reference to find and access the remote game server object.
</p>
<p>If the server player queue is empty, it simply queues this player.
If the queue is not empty, the server introduces the arrived player
and queued player to each other as leaves the them alone. When
playing, the two clients communicate with each other directly, so the
server is just a &ldquo;meeting point&rdquo; where the players can
find each other. The game server is a console-only application.
</p>
<p>The initial server http:// address must be transferred to players
by some other means of communication (web chat, E-mail, link in a web
site and so on). The server writes this address to the specified
file, and the client can also take the default value from the same
file. This is convenient when all applications run on a single
machine, but also may be used to transfer the address via shared
filesystem.
</p>
<h3>The game client
</h3>
<p>The clients are Swing-based GUI applications, capable for remote
communication with each other and with the game manager. They have a
set of predefined states and switch between these states in
accordance to the preprogrammed logic. The client states are defined
in the
<i>State
</i> interface. They are displayed in the bottom left
corner of the window and are summarized in the following table:
</p>
<table BORDER=1 CELLPADDING=4 CELLSPACING=0 WIDTH="100%">
<thead>
<tr BGCOLOR="#ccccff">
<th BGCOLOR="#e6e6ff">
Our state
</th>
<th BGCOLOR="#e6e6ff">
Partner state
</th>
<th BGCOLOR="#e6e6ff">
Possible actions
</th>
<th BGCOLOR="#e6e6ff">
Comment
</th>
</tr>
</thead>
<tbody>
<tr>
<td>
Disconnected
</td>
<td>
Partner not accessible
</td>
<td>
Connect
</td>
<td>
Initial state.
</td>
</tr>
<tr>
<td>
Queued
</td>
<td>
Partner not accessible
</td>
<td>
Leave
</td>
<td>
Queued by the game manager.
</td>
</tr>
<tr>
<td>
I think.
</td>
<td>
I wait for your move
</td>
<td>
Make move, reset game, leave, chat.
</td>
<td>
The person who waited for another player to come starts
the game first.
</td>
</tr>
<tr>
<td>
I wait for your move
</td>
<td>
I think
</td>
<td>
Chat, reset game, leave.
</td>
<td>
After the partner makes the move, the state changes to
<i>I think
</i>, unless the end of game situation is detected by
the desk analyzer.
</td>
</tr>
<tr>
<td>
I have lost
</td>
<td>
I have won
</td>
<td>
Chat, reset game, leave.
</td>
<td>
Can be entered with the help of the desk analyzer only.
</td>
</tr>
<tr>
<td>
I have won
</td>
<td>
I have lost
</td>
<td>
Chat, reset game, leave
</td>
<td>
Can be entered with the help of the desk analyzer only.
</td>
</tr>
<tr>
<td>
Error
</td>
<td>
Any
</td>
<td>
Chat, leave
</td>
<td>
This should never happen under normal work, but the demo
program may be modified by the user.
</td>
</tr>
</tbody>
</table>
<br>
<br>
As it is seen, being in one of the states, the client expects to
be the partner client in a certain defined state, and both clients
change they states in a synchronized manner. Each state has its own
set of the available actions and each action either preserves the
current state (chat, reset) or changes it following the rules. For
this simple example, the state change rules are obvious.
<h3>The used RMI-IIOP architecture
</h3>
Both player and game manager servants are derived from the
<i>org.omg.PortableServer.Servant
</i> and, being servants, are simply
connected to the
<i>POA
</i>with
<i>POA.servant_to_reference
</i>. The
first remote object (game manager) is found using the stringified
object reference. No naming service is involved.
</p>
Where required, the CORBA objects are narrowed into required
player and game manager interfaces using method
<i>PortableRemoteObject.narrow(org.omg.CORBA.Object object, Class
interface_class)
</i>, passing the actual interface of the object as
the second parameter. After narrowing, the remote side obtains
possibility to invoke remote methods, defined in the interface of
this object. After the first remote object is found, other objects
can be simply passed as the method parameters. For instance, the game
manager introduces another player by passing its reference as a
parameter to the method
<i>Player.start_game.
</i>
<h3>Class and interface summary
</h3>
<table BORDER=1 CELLPADDING=3 CELLSPACING=0 WIDTH="100%">
<col>
<col>
<tr>
<th COLSPAN=2 BGCOLOR="#e6e6ff">
Executables classes
</th>
</tr>
<tr>
<td>
Demo
</td>
<td>
The main executable class of the game client.
</td>
</tr>
<tr>
<td>
X5Server
</td>
<td>
The main executable class of the game manager server.
</td>
</tr>
</table>
<p></p>
<table BORDER=1 CELLPADDING=3 CELLSPACING=0 WIDTH="100%">
<tr BGCOLOR="#ccccff">
<th COLSPAN=2 BGCOLOR="#e6e6ff">
Interface Summary
</th>
</tr>
<tr>
<td>
GameManager
</td>
<td>
The game manager interface.
</td>
</tr>
<tr>
<td>
Player
</td>
<td>
Defines remote methods that are invoked by another player or by
the challenge server.
</td>
</tr>
<tr>
<td>
State
</td>
<td>
Defines the states in that the player can be.
</td>
</tr>
</table>
&nbsp;
<table BORDER=1 CELLPADDING=3 CELLSPACING=0 WIDTH="100%">
<col>
<col>
<tr BGCOLOR="#ccccff">
<th COLSPAN=2 BGCOLOR="#e6e6ff">
Class Summary
</th>
</tr>
<tr>
<td>
_GameManager_Stub
</td>
<td>
Normally generated with rmic compiler, this class represents
the GameManager Stub on the client side.
</td>
</tr>
<tr>
<td>
_GameManagerImpl_Tie
</td>
<td>
Normally generated with rmic compiler, this class represents
the GameManager Tie on the client side.
</td>
</tr>
<tr>
<td>
_Player_Stub
</td>
<td>
Generate with rmic, command line rmic -iiop -poa -keep
gnu.classpath.examples.CORBA.swing.x5.PlayerImpl (the compiled
package must be present in the current folder).
</td>
</tr>
<tr>
<td>
_PlayerImpl_Tie
</td>
<td>
Generate with rmic, command line rmic -iiop -poa -keep
gnu.classpath.examples.CORBA.swing.x5.PlayerImpl (the compiled
package must be present in the current folder).
</td>
</tr>
<tr>
<td>
ChatConstants
</td>
<td>
The chat color code constants, used to indicate who is talking.
</td>
</tr>
<tr>
<td>
ClientFrame
</td>
<td>
The JFrame of the GUI client.
</td>
</tr>
<tr>
<td>
GameManagerImpl
</td>
<td>
The manager connects two players into the game.
</td>
</tr>
<tr>
<td>
IorReader
</td>
<td>
Reads the remote URL.
</td>
</tr>
<tr>
<td>
OrbStarter
</td>
<td>
Starts the ORBs, involved into this application.
</td>
</tr>
<tr>
<td>
PlayerImpl
</td>
<td>
The implementation of the PlayerCommunicator, providing the
local functionality.
</td>
</tr>
<tr>
<td>
PlayingDesk
</td>
<td>
Manages actions, related to the game rules and also does all
painting.
</td>
</tr>
</table>
<h3>See also
</h3>
<p>
<a HREF="http://www.javascripter.net/games/xo/xo.htm">http://www.javascripter.net/games/xo/xo.htm
</a>
</p>
<p>
<a HREF="http://www.leepoint.net/notes-java/45examples/55games/five/five.html">http://www.leepoint.net/notes-java/45examples/55games/five/five.html
</a>
</p>
<p>Copyright
</p>
<p>
<font COLOR="#b3b3b3">Copyright (C) 2005 Free Software Foundation,
Inc. This file is part of GNU Classpath. GNU Classpath is free
software; you can redistribute it and/or modify it under the terms of
the GNU General Public License as published by the Free Software
Foundation; either version 2, or (at your option) any later version.
GNU Classpath 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
General Public License for more details. You should have received a
copy of the GNU General Public License along with GNU Classpath; see
the file COPYING. If not, write to the Free Software Foundation,
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination. As a special exception, the copyright holders of this
library give you permission to link this library with independent
modules to produce an executable, regardless of the license terms of
these independent modules, and to copy and distribute the resulting
executable under terms of your choice, provided that you also meet,
for each linked independent module, the terms and conditions of the
license of that module. An independent module is a module which is
not derived from or based on this library. If you modify this
library, you may extend this exception to your version of the
library, but you are not obligated to do so. If you do not wish to do
so, delete this exception statement from your version.
</font>
</p>
<p>
<br>
<br>
</p>
<p>
First version written by <a href="http://savannah.gnu.org/users/audriusa">
Audrius Me&scaron;kauskas</a>
</p>
</body>
</html>

View File

@@ -0,0 +1,307 @@
/* CanvasWorld.java --
Copyright (C) 2005 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath 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
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
package gnu.classpath.examples.CORBA.swing.x5;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Point;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
/**
* The purpose of this simple example is to check if the mouse events are
* correctly received in a scrollable canvas and also if the canvas are
* correctly repainted. The similar canvas are used in various games and
* interactive demonstrations.
*
* The user can set one of the three possible figures with the different
* mouse buttons. The figure must be set where the user have clicked the
* mouse.
*
* @author Audrius Meskauskas (AudriusA@Bioinformatics.org)
*/
public class CanvasWorld
extends JComponent
implements MouseListener, State
{
/**
* Use serialVersionUID for interoperability.
*/
private static final long serialVersionUID = 1;
/**
* Red oval, set by the left mouse button.
*/
public static final int RED = 0;
/**
* Black cross, set by the right mouse button.
*/
public static final int BLACK = 1;
/**
* Blue and smaller oval, set by the middle mouse button.
*/
public static final int HINT = 2;
/**
* The message string is displayed at the top of the window.
*/
String message = "Click left, right or middle button in to set the figure";
/**
* The additinal message, related to the mouse events.
*/
String mouse = "No mouse event so far";
/**
* The grid spacing.
*/
static int W = 16;
/**
* The radius of the dots being painted.
*/
static int R = W / 3;
/**
* The collection of the red dots.
*/
ArrayList reds = new ArrayList();
/**
* The collection of the black crosses.
*/
ArrayList blacks = new ArrayList();
/**
* The collection of the smaller blue crosses.
*/
ArrayList hints = new ArrayList();
public CanvasWorld()
{
try
{
addMouseListener(this);
}
catch (Exception e)
{
throw new AssertionError(e);
}
}
/**
* Paint this component.
*/
public void paintComponent(Graphics g)
{
int w = getWidth();
int h = getHeight();
g.setColor(Color.white);
g.fillRect(0, 0, w, h);
drawGrid(w, h, g);
g.setColor(Color.black);
g.drawString(message, W, W);
g.drawString(mouse, W, 2*W);
drawFigures(g);
}
/**
* Check for the presence of the given point in the collection.
*/
public final boolean pointPresent(int x, int y, Collection in)
{
Iterator iter = in.iterator();
Point p;
while (iter.hasNext())
{
p = (Point) iter.next();
if (p.x == x && p.y == y)
return true;
}
return false;
}
public void drawGrid(int w, int h, Graphics g)
{
g.setColor(Color.lightGray);
int xs = 2*W+W/2;
// Draw vertical lines:
for (int x = 0; x < w; x += W)
{
g.drawLine(x, xs, x, h);
}
// Draw horizontal lines:
for (int y = 3*W; y < h; y += W)
{
g.drawLine(0, y, w, y);
}
g.setColor(Color.gray);
}
public void drawFigures(Graphics g)
{
g.setColor(Color.red);
drawDots(reds, g, RED);
g.setColor(Color.black);
drawDots(blacks, g, BLACK);
g.setColor(Color.blue);
drawDots(hints, g, HINT);
}
public Point makePoint(int x, int y)
{
return new Point(x / W, y / W);
}
/**
* Draw a collection of dots (the collor must be set before calling the
* method).
*/
public void drawDots(Collection dots, Graphics g, int mode)
{
Iterator iter = dots.iterator();
int x;
int y;
int hW = W / 2;
int RR = R * 2;
int hR = R / 2;
Point p;
while (iter.hasNext())
{
p = (Point) iter.next();
x = p.x * W + hW;
y = p.y * W + hW;
if (mode == RED)
g.drawOval(x - R, y - R, RR, RR);
else if (mode == BLACK)
{
g.drawLine(x - R, y - R, x + R, y + R);
g.drawLine(x - R, y + R, x + R, y - R);
}
else
{
// Hint.
g.drawOval(x - hR, y - hR, R, R);
}
}
}
public void mouseClicked(MouseEvent e)
{
int x = e.getX();
int y = e.getY();
Point p = makePoint(x, y);
// Ignore clicks on the occupied cells.
if (pointPresent(p.x, p.y, reds) || (pointPresent(p.x, p.y, blacks)))
{
message = "Clicked on the occupied cell.";
return;
}
else
message = "Figure set at ["+p.x+","+p.y+"]";
if (e.getButton() == MouseEvent.BUTTON1)
reds.add(p);
else if (e.getButton() == MouseEvent.BUTTON3)
blacks.add(p);
else if (e.getButton() == MouseEvent.BUTTON2)
hints.add(p);
repaint();
}
public void mouseEntered(MouseEvent m)
{
mouse = "Mouse entered.";
repaint();
}
public void mousePressed(MouseEvent m)
{
mouse = "Mouse pressed at "+m.getX()+","+m.getY();
repaint();
}
public void mouseReleased(MouseEvent m)
{
mouse = "Mouse released at "+m.getX()+","+m.getY();
repaint();
}
public void mouseExited(MouseEvent m)
{
mouse = "Mouse exited";
repaint();
}
public static void main(String[] args)
{
JFrame frame = new JFrame();
CanvasWorld world = new CanvasWorld();
world.setPreferredSize(new Dimension(1000,1000));
frame.add(new JScrollPane(world));
frame.setSize(400, 200);
frame.setVisible(true);
}
}

View File

@@ -0,0 +1,80 @@
/* ChatConstants.java --
Copyright (C) 2005 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath 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
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
package gnu.classpath.examples.CORBA.swing.x5;
import java.awt.Color;
/**
* The chat color code constants, used to indicate who is talking.
* Additionally, the red color is reseved for the most important messages,
* related to the start and end of the game.
*
* @author Audrius Meskauskas (AudriusA@Bioinformatics.org)
*/
public class ChatConstants
{
/**
* Messages from the local system.
*/
public static byte SYSTEM = 0;
/**
* Mirrored messsages from the local player.
*/
public static byte SELF = 1;
/**
* Messages from the remote player.
*/
public static byte REMOTE_PLAYER = 2;
/**
* Messages from the game server/
*/
public static byte GAME_SERVER = 3;
/**
* The array of the used colors.
*/
public static Color[] colors =
new Color[]
{
Color.black, new Color(0, 80, 0), new Color(0, 0, 128), Color.blue
};
}

View File

@@ -0,0 +1,417 @@
/* ClientFrame.java --
Copyright (C) 2005 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath 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
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
package gnu.classpath.examples.CORBA.swing.x5;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.GridLayout;
import java.awt.event.*;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.rmi.RemoteException;
import javax.rmi.PortableRemoteObject;
import javax.swing.*;
import java.awt.Dimension;
/**
* The JFrame of the GUI client.
*
* @author Audrius Meskauskas (AudriusA@Bioinformatics.org)
*/
public class ClientFrame
extends JFrame
{
/**
* The size of the playing field.
*/
public final Dimension DESK_SIZE =
new Dimension(624, 352-PlayingDesk.W);
/**
* Use serialVersionUID for interoperability.
*/
private static final long serialVersionUID = 1;
// Define the application components:
/**
* Central panel where the main action takes place.
*/
PlayingDesk desk = new PlayingDesk();
/**
* The scroll pane for canvas.
*/
JScrollPane scroll = new JScrollPane();
/**
* Will remember the manager IOR.
*/
String mior = "";
// The bottom panel contains the area that is used both to enter URL and
// for chatting.
JPanel pnBottom = new JPanel();
BorderLayout layBottom = new BorderLayout();
JTextField taUrl = new JTextField();
// The top primitive chatting panel, composed from labels.
JPanel pnChat = new JPanel();
GridLayout layChat = new GridLayout();
JLabel lbC3 = new JLabel();
JLabel lbC2 = new JLabel();
JLabel lbC1 = new JLabel();
// The button panel.
JPanel pnButtons = new JPanel();
GridLayout layButtons = new GridLayout();
JButton bLeave = new JButton();
JButton bConnect = new JButton();
JButton bExit = new JButton();
JButton bReset = new JButton();
JLabel lbState = new JLabel();
JButton bChat = new JButton();
JButton bPaste = new JButton();
public ClientFrame()
{
try
{
jbInit();
}
catch (Exception e)
{
e.printStackTrace();
}
}
private void jbInit()
throws Exception
{
desk.frame = this;
pnBottom.setLayout(layBottom);
pnChat.setLayout(layChat);
layChat.setColumns(1);
layChat.setRows(3);
lbC1.setText("This program needs the game server (see README on how to start it).");
lbC2.setText("Enter the game server address (host:port)");
lbC3.setText("Pressing \'Connect\' with the empty address will start the server on "
+ "the local machine.");
bLeave.setEnabled(true);
bLeave.setToolTipText("Leave if either you have lost or do not want longer to play with "
+ "this partner.");
bLeave.setText("Leave game");
bLeave.addActionListener(new java.awt.event.ActionListener()
{
public void actionPerformed(ActionEvent e)
{
bLeave_actionPerformed(e);
}
});
bConnect.setToolTipText("Connect your playing partner");
bConnect.setText("Connect");
bConnect.addActionListener(new java.awt.event.ActionListener()
{
public void actionPerformed(ActionEvent e)
{
bConnect_actionPerformed(e);
}
});
pnButtons.setLayout(layButtons);
bExit.setToolTipText("Exit this program");
bExit.setText("Exit");
bExit.addActionListener(new java.awt.event.ActionListener()
{
public void actionPerformed(ActionEvent e)
{
bExit_actionPerformed(e);
}
});
layButtons.setHgap(2);
bReset.setToolTipText("Restart the game. The partner may choose to exit!");
bReset.setText("Reset game");
bReset.addActionListener(new java.awt.event.ActionListener()
{
public void actionPerformed(ActionEvent e)
{
bReset_actionPerformed(e);
}
});
lbState.setText("Disconnected");
bChat.setToolTipText("Send message to player. Reuse the address "+
"field to enter the message.");
bChat.setText("Chat");
bChat.addActionListener(new java.awt.event.ActionListener()
{
public void actionPerformed(ActionEvent e)
{
bChat_actionPerformed(e);
}
});
bPaste.setText("Paste");
bPaste.setToolTipText("Paste, same as Ctrl-V");
bPaste.addActionListener(new java.awt.event.ActionListener()
{
public void actionPerformed(ActionEvent e)
{
bPaste_actionPerformed(e);
}
});
desk.setMaximumSize(DESK_SIZE);
desk.setPreferredSize(DESK_SIZE);
scroll.getViewport().add(desk, null);
getContentPane().add(scroll, BorderLayout.CENTER);
getContentPane().add(pnBottom, BorderLayout.SOUTH);
pnBottom.add(taUrl, BorderLayout.CENTER);
pnBottom.add(pnChat, BorderLayout.NORTH);
pnChat.add(lbC1, null);
pnChat.add(lbC2, null);
pnChat.add(lbC3, null);
pnBottom.add(pnButtons, BorderLayout.SOUTH);
pnButtons.add(lbState, null);
pnButtons.add(bConnect, null);
pnButtons.add(bChat, null);
pnButtons.add(bLeave, null);
pnButtons.add(bReset, null);
pnButtons.add(bExit, null);
pnButtons.add(bPaste, null);
desk.player.set_current_state(State.DISCONNECTED);
}
/**
* Handles exit procedure.
*/
protected void processWindowEvent(WindowEvent e)
{
super.processWindowEvent(e);
if (e.getID() == WindowEvent.WINDOW_CLOSING)
{
bExit_actionPerformed(null);
}
}
/**
* Handles the connection procedure.
*/
void bConnect_actionPerformed(ActionEvent e)
{
try
{
int state = desk.player.get_current_state();
if (state == State.DISCONNECTED || state == State.ERROR)
{
talk(ChatConstants.colors[0], "Connecting...");
if (desk.manager == null)
{
mior = taUrl.getText().trim();
// Obtain the manager object:
org.omg.CORBA.Object object = null;
try
{
object = desk.orb.string_to_object(mior);
}
catch (Exception exc)
{
// Maybe CORBA 3.0.3 is not completely implemented?
if (mior.startsWith("http://") || mior.startsWith("ftp://")
|| mior.startsWith("file://"))
object = desk.orb.string_to_object(IorReader.readUrl(mior));
else
throw exc;
}
desk.manager = (GameManager) PortableRemoteObject.narrow(
object, GameManager.class);
// Export the desk.player as a remote object.
PortableRemoteObject.exportObject(desk.player);
}
desk.player.set_current_state(State.QUEUED);
desk.manager.requestTheGame(desk.player);
}
// Save the specified IOR for the future use:
File gmf = new File(OrbStarter.WRITE_URL_TO_FILE);
FileWriter f = new FileWriter(gmf);
BufferedWriter b = new BufferedWriter(f);
b.write(mior);
b.close();
}
catch (Exception ex)
{
talk(Color.red, "The manager is not reachable by this address.");
talk(Color.red, ex.getMessage());
desk.player.set_current_state(State.DISCONNECTED);
}
}
/**
* Display the new message with the given color. Shift the other messages over
* the labels.
*/
public void talk(Color color, String text)
{
lbC1.setText(lbC2.getText());
lbC1.setForeground(lbC2.getForeground());
lbC2.setText(lbC3.getText());
lbC2.setForeground(lbC3.getForeground());
lbC3.setText(text);
lbC3.setForeground(color);
}
/**
* Exit this program.
*/
void bExit_actionPerformed(ActionEvent e)
{
try
{
if (desk.player.get_current_state() != State.DISCONNECTED
&& desk.player.partner != null)
{
desk.player.partner.receive_chat(ChatConstants.REMOTE_PLAYER,
"I close the program!");
desk.player.partner.disconnect();
}
}
catch (RemoteException ex)
{
// We will print the exception because this is a demo application that
// may be modified for learning purposes.
ex.printStackTrace();
}
System.exit(0);
}
void bReset_actionPerformed(ActionEvent e)
{
if (desk.player.partner != null)
{
try
{
desk.player.partner.receive_chat(ChatConstants.REMOTE_PLAYER,
"Your partner restarted the game.");
desk.player.start_game(desk.player.partner, false);
desk.player.partner.start_game(desk.player, true);
}
catch (RemoteException ex)
{
// We will print the exception because this is a demo application
// that
// may be modified for learning purposes.
ex.printStackTrace();
}
}
else
talk(Color.black, "You have not started the game yet.");
}
void bLeave_actionPerformed(ActionEvent e)
{
desk.player.leave();
}
void bChat_actionPerformed(ActionEvent e)
{
try
{
if (desk.player.partner != null)
{
String message = taUrl.getText();
desk.player.partner.receive_chat(ChatConstants.REMOTE_PLAYER, message);
talk(ChatConstants.colors[ChatConstants.SELF], message);
taUrl.setText("");
}
else
{
talk(Color.black, "Sorry, not connected to anybody");
}
}
catch (RemoteException ex)
{
// We will print the exception because this is a demo application that
// may be modified for learning purposes.
ex.printStackTrace();
}
}
/**
* Work around our keyboard shortcut handling that is still not working
* properly.
*/
void bPaste_actionPerformed(ActionEvent e)
{
taUrl.paste();
}
}

View File

@@ -0,0 +1,99 @@
/* Demo.java --
Copyright (C) 2005 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath 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
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
package gnu.classpath.examples.CORBA.swing.x5;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
/**
* The main executable class of the game client.
*
* @author Audrius Meskauskas (AudriusA@Bioinformatics.org)
*/
public class Demo
{
public static void main(String[] args)
{
ClientFrame frame = new ClientFrame();
frame.setSize(new Dimension(640, 480));
frame.setTitle("Make vertical, horizontal or diagonal line of 5 dots. "
+ "Click mouse to set the dot.");
frame.validate();
// Center the window
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
Dimension frameSize = frame.getSize();
if (frameSize.height > screenSize.height)
{
frameSize.height = screenSize.height;
}
if (frameSize.width > screenSize.width)
{
frameSize.width = screenSize.width;
}
frame.setLocation((screenSize.width - frameSize.width) / 2,
(screenSize.height - frameSize.height) / 2);
frame.setVisible(true);
// Set the ior.
try
{
if (OrbStarter.WRITE_URL_TO_FILE != null)
{
File saved_ior = new File(OrbStarter.WRITE_URL_TO_FILE);
if (saved_ior.exists())
{
FileReader f = new FileReader(saved_ior);
String s = new BufferedReader(f).readLine();
frame.taUrl.setText(s);
}
}
}
catch (Exception e)
{
// We will print the exception, because this is a demo program -
// expected to be modified by user.
e.printStackTrace();
}
}
}

View File

@@ -0,0 +1,68 @@
/* GameManager.java --
Copyright (C) 2005 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath 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
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
package gnu.classpath.examples.CORBA.swing.x5;
import java.rmi.Remote;
import java.rmi.RemoteException;
/**
* The game manager interface.
*
* Defines the operations of the game server that connects two players into
* the game. The game server does not participate in the game itself.
*
* @author Audrius Meskauskas (AudriusA@Bioinformatics.org)
*/
public interface GameManager extends Remote
{
/**
* Register the newPlayer as the person who is willing to play. When another
* player calls this method, the Manager connects them by calling
* {@link PlayerCommunicator#start_game}. The manager provides the partner
* and sets (randomly) the starting side.
*/
void requestTheGame(Player newPlayer) throws RemoteException;
/**
* Unregister the player that left and is no longer waiting for a playing
* partner to come.
* @throws RemoteException
*/
void unregister(Player player) throws RemoteException;
}

View File

@@ -0,0 +1,135 @@
/* GameManagerImpl.java --
Copyright (C) 2005 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath 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
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
package gnu.classpath.examples.CORBA.swing.x5;
import java.rmi.RemoteException;
import org.omg.CORBA.ORB;
import org.omg.CORBA.Object;
/**
* The manager connects two players into the game.
*
* @author Audrius Meskauskas (AudriusA@Bioinformatics.org)
*/
public class GameManagerImpl
implements GameManager
{
/**
* The game manager IOR.
*/
static String ior;
/**
* The game manager ORB.
*/
static ORB orb;
/**
* True if the manager started ok.
*/
static boolean ok;
/**
* Another player that is already waiting for the game.
*/
Player queuedPlayer = null;
public synchronized void requestTheGame(Player newPlayer)
throws RemoteException
{
System.out.println("Game requested");
if (queuedPlayer == null)
{
// No other player so far.
newPlayer.receive_chat(ChatConstants.GAME_SERVER,
"Request registered, waiting for the other player to come...");
System.out.println("Player queued.");
queuedPlayer = newPlayer;
}
else if (queuedPlayer.equals(newPlayer))
{
// The same player applies again.
newPlayer.receive_chat(ChatConstants.GAME_SERVER,
"No other player so far... Please wait.");
}
else
{
// As the queued player waited for the game, we allow him/her
// to start the game. This is a reward for waiting.
newPlayer.receive_chat(ChatConstants.GAME_SERVER,
"The other player is waiting. The game started, your "
+ "partner begins...");
queuedPlayer.receive_chat(ChatConstants.GAME_SERVER,
"The other player arrived. Lets play, you begin the game now...");
newPlayer.start_game(queuedPlayer, false);
queuedPlayer.start_game(newPlayer, true);
queuedPlayer = null;
System.out.println("Players connected.");
}
}
/**
* Unregister the player who left and is no longer waiting for another side.
*/
public void unregister(Player player)
throws RemoteException
{
if (queuedPlayer != null)
{
// We need to verify the identity of the player being unregistered.
// The stubs, being derived from the org.omg.CORBA.Object, have the
// method for this. This method compares the player host address,
// used port and the object key.
if (player instanceof Object && queuedPlayer instanceof Object)
{
Object a = (Object) player;
Object b = (Object) queuedPlayer;
if (a._is_equivalent(b))
queuedPlayer = null;
}
else
queuedPlayer = null;
}
System.out.println("Unregistering player");
}
}

View File

@@ -0,0 +1,124 @@
/* IorReader.java --
Copyright (C) 2005 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath 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
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
package gnu.classpath.examples.CORBA.swing.x5;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
import org.omg.CORBA.BAD_PARAM;
import org.omg.CORBA.DATA_CONVERSION;
/**
* Reads the remote URL. Following formal/04-03-12, CORBA should be able to do
* this without the help of this class. However some popular class libraries
* are written using the older CORBA specifications and may not handle
* functionality, require by this game. This class substitutes the functionality,
* ensuring that these implementations will also start and we will be able
* to test the interoperability.
*
* @author Audrius Meskauskas (AudriusA@Bioinformatics.org)
*/
public class IorReader
{
/**
* Read IOR from the remote URL.
*/
public static String readUrl(String url)
{
URL u;
try
{
u = new URL(url);
}
catch (MalformedURLException mex)
{
throw new BAD_PARAM("Malformed URL: '" + url + "'");
}
try
{
InputStreamReader r = new InputStreamReader(u.openStream());
StringBuffer b = new StringBuffer();
int c;
while ((c = r.read()) > 0)
b.append((char) c);
return b.toString().trim();
}
catch (Exception exc)
{
DATA_CONVERSION d = new DATA_CONVERSION("Reading " + url + " failed.");
throw d;
}
}
/**
* Read IOR from the file in the local file system.
*/
public static String readFile(String file)
{
File f = new File(file);
if (!f.exists())
{
DATA_CONVERSION err = new DATA_CONVERSION(f.getAbsolutePath()
+ " does not exist.");
throw err;
}
try
{
char[] c = new char[(int) f.length()];
FileReader fr = new FileReader(f);
fr.read(c);
fr.close();
return new String(c).trim();
}
catch (IOException ex)
{
DATA_CONVERSION d = new DATA_CONVERSION();
d.initCause(ex);
throw (d);
}
}
}

View File

@@ -0,0 +1,236 @@
/* OrbStarter.java --
Copyright (C) 2005 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath 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
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
package gnu.classpath.examples.CORBA.swing.x5;
import java.rmi.RemoteException;
import java.util.Properties;
import javax.rmi.PortableRemoteObject;
import javax.rmi.CORBA.Tie;
import org.omg.CORBA.ORB;
import org.omg.PortableServer.POA;
import org.omg.PortableServer.POAHelper;
import org.omg.PortableServer.Servant;
/**
* Starts the ORBs, involved into this application.
*
* @author Audrius Meskauskas (AudriusA@Bioinformatics.org)
*/
public class OrbStarter
{
/**
* The game manager name server port. This server allows to access the game
* manager by host (IP) and port rather than by the rather long IOR string.
*/
static int MANAGER_NAMER_PORT = 1500;
/**
* The used port range (understood and used by GNU Classpath only).
*/
static String USED_PORT_RANGE = "1501-1503";
/**
* Specify the file where under start the game manager writes its IOR.
* You may specify the path if the game manager and player clients have
* access to some share file system or if you prefer to write IOR to
* floppy and then read from the floppy on the client side. Both clients
* and server will use this constant. Set to null not to write the IOR.
*/
static String WRITE_URL_TO_FILE = "game_manager_ior.txt";
/**
* Start the manager ORB.
* @return the manager URL if it starts.
*/
public static String startManager(final String[] args)
{
GameManagerImpl.ior = null;
GameManagerImpl.ok = false;
final Properties p = new Properties();
p.put("gnu.CORBA.ListenerPort", USED_PORT_RANGE);
try
{
new Thread()
{
public void run()
{
try
{
GameManagerImpl.orb = ORB.init(args, p);
// Obtain the root poa:
POA rootPOA = POAHelper.narrow(GameManagerImpl.orb.resolve_initial_references("RootPOA"));
GameManagerImpl impl = new GameManagerImpl();
PortableRemoteObject.exportObject(impl);
// Construct the tie that is also the servant.
Tie tie = new _GameManagerImpl_Tie();
// Set the invocation target for this tie.
tie.setTarget(impl);
// Obtain the reference to the corresponding CORBA object:
org.omg.CORBA.Object object = rootPOA.servant_to_reference((Servant) tie);
GameManagerImpl.ok = true;
// Activate the root POA.
rootPOA.the_POAManager().activate();
// Get the IOR URL that must be passed to clients.
GameManagerImpl.ior = GameManagerImpl.orb.object_to_string(object);
GameManagerImpl.orb.run();
}
catch (Exception exc)
{
exc.printStackTrace();
GameManagerImpl.ior = "Unable to start the ORB: " + exc;
}
}
}.start();
// Wait the thread to enter orb.run.
long t = System.currentTimeMillis();
while (GameManagerImpl.ior == null
&& System.currentTimeMillis() - t < 20000)
{
Thread.sleep(100);
}
return GameManagerImpl.ior;
}
catch (Exception e)
{
e.printStackTrace();
return "Exception: " + e;
}
}
/**
* Start the client ORB.
*/
public static String startPlayer(final Player player, final PlayingDesk desk)
{
desk.ior = null;
desk.ok = false;
final Properties p = new Properties();
p.put("gnu.CORBA.ListenerPort", USED_PORT_RANGE);
try
{
new Thread()
{
public void run()
{
try
{
desk.orb = ORB.init(new String[0], p);
POA rootPOA = POAHelper.narrow(desk.orb.resolve_initial_references("RootPOA"));
rootPOA.the_POAManager().activate();
// Construct the tie.
Tie tie = new _PlayerImpl_Tie();
// Set the implementing class (invocation target).
tie.setTarget(new PlayerImpl());
// Connect the tie as POA servant.
org.omg.CORBA.Object object = rootPOA.servant_to_reference((Servant) tie);
// Get the stringified reference.
desk.ior = desk.orb.object_to_string(object);
// Mark that the object was created OK.
desk.ok = true;
desk.orb.run();
}
catch (Exception exc)
{
exc.printStackTrace();
desk.ior = "Unable to start the ORB: " + exc;
}
}
}.start();
long t = System.currentTimeMillis();
while (desk.ior == null && System.currentTimeMillis() - t < 20000)
{
Thread.sleep(100);
}
}
catch (Exception e)
{
e.printStackTrace();
return "Exception: " + e;
}
// Add shutdown hook to unregister from the manager.
Runtime.getRuntime().addShutdownHook(new Thread()
{
public void run()
{
if (desk.manager != null && player != null)
{
try
{
desk.manager.unregister(player);
}
catch (RemoteException ex)
{
// We will print the exception because this is a demo
// application that
// may be modified for learning purposes.
ex.printStackTrace();
}
desk.manager = null;
}
}
});
return desk.ior;
}
}

View File

@@ -0,0 +1,96 @@
/* Player.java --
Copyright (C) 2005 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath 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
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
package gnu.classpath.examples.CORBA.swing.x5;
import java.awt.Point;
import java.rmi.Remote;
import java.rmi.RemoteException;
/**
* Defines remote methods that are invoked by another player or by the
* challenge server.
*
* @author Audrius Meskauskas (AudriusA@Bioinformatics.org)
*/
public interface Player extends Remote
{
/**
* Receive the invitation to play from the patner or the game manager.
*
* @param address the address (host and port) of the remote partner.
* @param youStart if true, the game manager instructs to start
* the game first (another side is instructed to start the game second).
*
* @return true on success.
*/
boolean start_game(Player otherPlayer, boolean youStart)
throws RemoteException;
/**
* Get the state of the local player (one of the constants, defined
* in this interface).
*/
int get_current_state() throws RemoteException;
/**
* Receive the chat message from the friend or challenge server (remote).
* Possible at any state, always remote.
*
* @param color the color code, used to highlight the message.
* @param text the message text.
*/
void receive_chat(byte color, String test) throws RemoteException;
/**
* Indicated that the remote side leaves the game (capitulating).
*/
void disconnect() throws RemoteException;
/**
* Receive friends move (possible at I_WAIT_FOR_YOUR_MOVE).
*
* @param x grid position.
* @param y grid position.
*
* @param sessionId the session id, must match (otherwise the call is ignored).
* @param victory if not a null, the friend thinks that it has won, the parameter
* containing the ends of the builded line.
*/
void receive_move(int x, int y, Point[] victory) throws RemoteException;
}

View File

@@ -0,0 +1,275 @@
/* PlayerImpl.java --
Copyright (C) 2005 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath 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
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
package gnu.classpath.examples.CORBA.swing.x5;
import java.awt.Color;
import java.awt.Point;
import java.rmi.RemoteException;
/**
* The implementation of the PlayerCommunicator, providing the local
* functionality. Apart remote methods, the class also defines some local
* methods, needed for the co-ordinated work with the game user interface.
*
* @author Audrius Meskauskas (AudriusA@Bioinformatics.org)
*/
public class PlayerImpl
implements Player, State
{
/**
* The playing table.
*/
PlayingDesk desk;
/**
* The state of this player (one of the constants, defined in the player
* interface.
*/
private int state = DISCONNECTED;
/**
* The other player.
*/
Player partner;
/**
* Called when the local player refuses to continue the game.
*/
public void leave()
{
try
{
if (state == I_THINK || state == I_WAIT_FOR_YOUR_MOVE)
{
partner.receive_chat(ChatConstants.REMOTE_PLAYER,
"Your partner has left the game.");
partner.disconnect();
}
else if (state == State.QUEUED)
{
if (desk.manager != null)
desk.manager.unregister(desk.player);
receive_chat(ChatConstants.SYSTEM,
"Do not be so pessimistic, try to play first!");
}
set_current_state(State.DISCONNECTED);
desk.frame.bChat.setEnabled(false);
desk.frame.bLeave.setEnabled(false);
desk.frame.bConnect.setEnabled(true);
desk.frame.taUrl.setText(desk.frame.mior);
}
catch (RemoteException ex)
{
// We will print the exception because this is a demo application that
// may be modified for learning purposes.
ex.printStackTrace();
}
}
/**
* Called when we make the move. The PlayingTable is responsible for checking
* the correctness of the move and detecting the victory.
*
* @param x x position of the new dot.
* @param y y position of the new dot.
*
* @param victory array of two memebers, representing the endpoints of the
* drawn line (victory detected) or null if no such yet exists.
*/
public void we_move(int x, int y, Point[] victory)
{
try
{
set_current_state(I_WAIT_FOR_YOUR_MOVE);
partner.receive_move(x, y, victory);
}
catch (RemoteException ex)
{
// We will print the exception because this is a demo application that
// may be modified for learning purposes.
ex.printStackTrace();
state = ERROR;
}
}
/**
* Set the current state.
*/
public void set_current_state(int new_state)
{
state = new_state;
if (state == DISCONNECTED)
{
setStatus("Disconnected");
}
else if (state == I_THINK)
{
setStatus("Our move");
}
else if (state == I_WAIT_FOR_YOUR_MOVE)
{
setStatus("Partner's move");
}
else if (state == ERROR)
{
setStatus("Error.");
}
else if (state == I_HAVE_LOST)
{
setStatus("We lost");
}
else if (state == I_HAVE_WON)
{
setStatus("Victory");
}
else if (state == QUEUED)
{
setStatus("Queued");
}
else
{
setStatus("State " + state);
}
boolean connected = state != State.DISCONNECTED;
desk.frame.bConnect.setEnabled(!connected && state != State.QUEUED);
desk.frame.bReset.setEnabled(connected);
desk.frame.bLeave.setEnabled(connected);
desk.frame.bChat.setEnabled(connected);
}
/**
* Show the state in the status line.
*/
public void setStatus(String status)
{
desk.frame.lbState.setText(status);
}
/**
* Receive the invitation to play from the patner or the game manager.
*
* @param address the address (host and port) of the remote partner.
* @param youStart if true, the game manager instructs to start the game first
* (another side is instructed to start the game second).
*
* Game server may also chat a little bit with both players, saying that the
* game has started.
*
* @return true on success.
*/
public boolean start_game(Player otherPlayer, boolean youStart)
throws RemoteException
{
partner = otherPlayer;
desk.reset();
if (youStart)
{
set_current_state(I_THINK);
}
else
{
set_current_state(I_WAIT_FOR_YOUR_MOVE);
}
desk.frame.taUrl.setText("");
return true;
}
/**
* Get the state of the local player (one of the constants, defined in this
* interface).
*/
public int get_current_state()
throws RemoteException
{
return state;
}
/**
* Receive the chat message from the friend or challenge server (remote).
* Possible at any state, always remote.
*
* @param color the color code, used to highlight the message.
* @param text the message text.
*/
public void receive_chat(byte color, String text)
throws RemoteException
{
if (color >= ChatConstants.colors.length)
color = ChatConstants.REMOTE_PLAYER;
desk.frame.talk(ChatConstants.colors[color], text);
}
/**
* Indicated that the remote side leaves the game (capitulating).
*/
public void disconnect()
throws RemoteException
{
desk.frame.talk(Color.red, "The partner leaves the game.");
partner = null;
set_current_state(DISCONNECTED);
desk.frame.taUrl.setText(desk.frame.mior);
}
/**
* Receive friends move (possible at I_WAIT_FOR_YOUR_MOVE).
*
* @param x grid position.
* @param y grid position.
* @param victory if not a null, the friend thinks that it has won, the
* parameter containing the ends of the builded line.
*/
public void receive_move(int x, int y, Point[] victory)
throws RemoteException
{
// The state changes are handled by the PlayingTable
desk.friendsMove(x, y, victory);
}
}

View File

@@ -0,0 +1,512 @@
/* PlayingDesk.java --
Copyright (C) 2005 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath 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
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
package gnu.classpath.examples.CORBA.swing.x5;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Point;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.rmi.RemoteException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import javax.swing.JComponent;
import org.omg.CORBA.ORB;
/**
* Manages actions, related to the game rules and also does all painting.
*
* @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org)
*/
public class PlayingDesk
extends JComponent
implements MouseListener, State
{
/**
* Use serialVersionUID for interoperability.
*/
private static final long serialVersionUID = 1;
/**
* Indicates that the field point state is the red oval.
*/
public static final int RED = 0;
/**
* Indicates that the field point state is the black cross.
*/
public static final int BLACK = 1;
/**
* Indicates that the field point state is the hint, suggested by the fan.
*/
public static final int HINT = 2;
/**
* The access to the main frame methods.
*/
ClientFrame frame;
/**
* The access to the player communicator.
*/
PlayerImpl player;
/**
* The game manager.
*/
GameManager manager;
/**
* The player ORB.
*/
ORB orb;
/**
* The player IOR.
*/
String ior;
/**
* True if the player ORB started ok.
*/
boolean ok;
/**
* The grid spacing.
*/
static int W = 16;
/**
* The radius of the dots being painted.
*/
static int R = W / 3;
/**
* The collection of the red dots.
*/
ArrayList reds = new ArrayList();
/**
* The collection of the black dots.
*/
ArrayList blacks = new ArrayList();
/**
* The array of hints.
*/
ArrayList hints = new ArrayList();
/**
* When the game is completed, obtains the value of the two end points of the
* created line.
*/
Point[] endOfGame;
public PlayingDesk()
{
try
{
player = new PlayerImpl();
player.desk = this;
OrbStarter.startPlayer(player, this);
jbInit();
}
catch (Exception e)
{
e.printStackTrace();
}
}
/**
* Paint this component.
*/
public void paintComponent(Graphics g)
{
int w = getWidth();
int h = getHeight();
g.setColor(Color.white);
g.fillRect(0, 0, w, h);
drawGrid(w, h, g);
drawFigures(g);
}
/**
* Check maybe a game is finished after setting the point N
*/
public Point[] checkFinished(Collection x, Point N)
{
Iterator iter = x.iterator();
Point p;
// The victory, if happens, must occur inside these boundaries:
int ax = N.x - 5;
int bx = N.x + 5;
int ay = N.y - 5;
int by = N.y + 5;
while (iter.hasNext())
{
p = (Point) iter.next();
if (p.x > ax && p.x < bx && p.y > ay && p.y < by)
{
// Check the vertical line down
if (pointPresent(p.x, p.y + 1, x))
if (pointPresent(p.x, p.y + 2, x))
if (pointPresent(p.x, p.y + 3, x))
if (pointPresent(p.x, p.y + 4, x))
return new Point[] { p, new Point(p.x, p.y + 4) };
// Check the horizontal line left
if (pointPresent(p.x + 1, p.y, x))
if (pointPresent(p.x + 2, p.y, x))
if (pointPresent(p.x + 3, p.y, x))
if (pointPresent(p.x + 4, p.y, x))
return new Point[] { p, new Point(p.x + 4, p.y) };
// Check the diagonal line right down.
if (pointPresent(p.x + 1, p.y + 1, x))
if (pointPresent(p.x + 2, p.y + 2, x))
if (pointPresent(p.x + 3, p.y + 3, x))
if (pointPresent(p.x + 4, p.y + 4, x))
return new Point[] { p, new Point(p.x + 4, p.y + 4) };
// Check the diagonal line left down.
if (pointPresent(p.x - 1, p.y + 1, x))
if (pointPresent(p.x - 2, p.y + 2, x))
if (pointPresent(p.x - 3, p.y + 3, x))
if (pointPresent(p.x - 4, p.y + 4, x))
return new Point[] { p, new Point(p.x - 4, p.y + 4) };
}
}
return null;
}
/**
* Called when the "end of the game" situation is detected.
*/
public void drawFinishLine(int xa, int ya, int xb, int yb, Graphics g)
{
g.setColor(Color.blue);
int hW = W / 2;
g.drawLine(xa * W + hW, ya * W + hW, xb * W + hW, yb * W + hW);
}
/**
* Check for the presence of the given point in the collection.
*/
public final boolean pointPresent(int x, int y, Collection in)
{
Iterator iter = in.iterator();
Point p;
while (iter.hasNext())
{
p = (Point) iter.next();
if (p.x == x && p.y == y)
return true;
}
return false;
}
public void drawGrid(int w, int h, Graphics g)
{
g.setColor(Color.lightGray);
// Draw vertical lines:
for (int x = 0; x < w; x += W)
{
g.drawLine(x, 0, x, h);
}
// Draw horizontal lines:
for (int y = 0; y < h; y += W)
{
g.drawLine(0, y, w, y);
}
g.setColor(Color.gray);
g.drawRect(0,0, frame.DESK_SIZE.width, frame.DESK_SIZE.height);
g.drawRect(0,0, frame.DESK_SIZE.width+3, frame.DESK_SIZE.height+3);
}
public void drawFigures(Graphics g)
{
g.setColor(Color.red);
drawDots(reds, g, RED);
g.setColor(Color.black);
drawDots(blacks, g, BLACK);
g.setColor(Color.lightGray);
drawDots(hints, g, HINT);
if (endOfGame != null)
drawFinishLine(endOfGame[0].x, endOfGame[0].y, endOfGame[1].x,
endOfGame[1].y, g);
}
public Point makePoint(int x, int y)
{
return new Point(x / W, y / W);
}
/**
* Draw a collection of dots (the collor must be set before calling the
* method).
*/
public void drawDots(Collection dots, Graphics g, int mode)
{
Iterator iter = dots.iterator();
int x;
int y;
int hW = W / 2;
int RR = R * 2;
int hR = R / 2;
Point p;
while (iter.hasNext())
{
p = (Point) iter.next();
x = p.x * W + hW;
y = p.y * W + hW;
if (mode == RED)
g.drawOval(x - R, y - R, RR, RR);
else if (mode == BLACK)
{
g.drawLine(x - R, y - R, x + R, y + R);
g.drawLine(x - R, y + R, x + R, y - R);
}
else
{
// Hint.
g.drawOval(x - hR, y - hR, R, R);
}
}
}
private void jbInit()
throws Exception
{
addMouseListener(this);
}
public void mouseClicked(MouseEvent e)
{
try
{
int state = player.get_current_state();
// Check if the state is correct.
if (state == I_WAIT_FOR_YOUR_MOVE)
{
frame.talk(Color.black,
"It is now time for our partner's move, not ours. Please wait.");
}
else if (state == DISCONNECTED)
{
frame.talk(Color.black,
"We are not connected to the playing partner yet.");
}
else if (state == I_HAVE_LOST)
{
frame.talk(Color.black,
"We have already lost this battle, but why not to try again?");
}
else if (state == I_HAVE_WON)
{
frame.talk(Color.black,
"The victory is ours, nothing more to do here.");
}
else if (player.partner == null)
frame.talk(Color.black, "No other player so far.");
else
{
int x = e.getX();
int y = e.getY();
if (x>frame.DESK_SIZE.width ||
y>frame.DESK_SIZE.height)
{
frame.talk(Color.black,"Outside the game area.");
return;
}
Point p = makePoint(x, y);
// Ignore clicks on the occupied cells.
if (pointPresent(p.x, p.y, reds)
|| (pointPresent(p.x, p.y, blacks)))
{
frame.talk(Color.black,
"This is against the rules, select the unoccupied cell.");
return;
}
reds.add(p);
endOfGame = checkFinished(reds, p);
repaint();
if (endOfGame != null)
{
frame.talk(Color.red, "Our move " + p.x + "-" + p.y
+ " and we win!");
player.set_current_state(I_HAVE_WON);
}
else
{
frame.talk(Color.black, "Our move " + p.x + "-" + p.y
+ ". Waiting for the other side move...");
player.set_current_state(I_WAIT_FOR_YOUR_MOVE);
}
player.partner.receive_move(p.x, p.y, endOfGame);
}
}
catch (RemoteException ex)
{
// We will print the exception because this is a demo application
// that may be modified for learning purposes.
ex.printStackTrace();
}
}
/**
* Handle the move of the other playing side.
*/
public void friendsMove(int x, int y, Point[] victory)
{
try
{
int state = player.get_current_state();
if (state != I_WAIT_FOR_YOUR_MOVE || pointPresent(x, y, blacks))
{
stateFailed("Move " + x + "-" + y);
}
else
{
blacks.add(new Point(x, y));
repaint();
if (victory != null)
{
frame.talk(Color.red,
" We have lost this time, unfortunately..");
player.set_current_state(I_HAVE_LOST);
endOfGame = victory;
}
else
{
frame.talk(Color.black, "Partner goes " + x + "-" + y
+ ". Your move?");
player.set_current_state(I_THINK);
}
}
}
catch (RemoteException rex)
{
rex.printStackTrace();
}
}
/**
* Prepare for the new game.
*/
public void reset()
{
blacks.clear();
reds.clear();
hints.clear();
endOfGame = null;
repaint();
}
public void mouseEntered(MouseEvent m)
{
// Nothing to do.
}
public void mousePressed(MouseEvent m)
{
// Nothing to do.
}
public void mouseReleased(MouseEvent m)
{
// Nothing to do.
}
public void mouseExited(MouseEvent m)
{
// Nothing to do.
}
/**
* The systems detected the error conditions. The game cannot continue (the
* chat is still possible).
*/
public void stateFailed(String reason)
{
try
{
player.receive_chat(ChatConstants.REMOTE_PLAYER,
"Wrong move, game cannot continue (our state was "
+ player.get_current_state() + ")");
frame.talk(Color.red, "The remote side violates communicating rules.");
player.set_current_state(State.ERROR);
}
catch (RemoteException ex)
{
// We will print the exception because this is a demo application
// that may be modified for learning purposes.
ex.printStackTrace();
}
}
}

View File

@@ -0,0 +1,82 @@
/* State.java --
Copyright (C) 2005 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath 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
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
package gnu.classpath.examples.CORBA.swing.x5;
/**
* Defines the states in that the player can be.
*
* @author Audrius Meskauskas (AudriusA@Bioinformatics.org)
*/
public interface State {
/**
* The initial ("disconnected") state.
*/
int DISCONNECTED = 0;
/**
* The state, indicating that the player has been queued for the game and
* waiting for the partner to come.
*/
int QUEUED = 1;
/**
* The "my move" state.
*/
int I_THINK = 2;
/**
* The "friend's move" state.
*/
int I_WAIT_FOR_YOUR_MOVE = 3;
/**
* States that we have won.
*/
int I_HAVE_WON = 4;
/**
* States that we have lost.
*/
int I_HAVE_LOST = 5;
/**
* The "inconsistent" state when it is not possible to continue the game.
*/
int ERROR = -1;
}

View File

@@ -0,0 +1,175 @@
/* GameManagerAddressServer.java --
Copyright (C) 2005 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath 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
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
package gnu.classpath.examples.CORBA.swing.x5;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.OutputStream;
import java.net.InetAddress;
import java.net.ServerSocket;
import java.net.Socket;
/**
* The main executable class of the game manager server.
*
* The manager address server returns the IOR address string of the game
* manager. Hence the user does not need to enter the rather long IOR address
* string and only needs to specify the host and port of the machine where the
* game manager is running.
*
* The manager address server starts the main game manager as well.
*
* This server acts as a HTTP server that always returns the same response. This
* primitive functionality is sufficient for its task.
*
* The more complex CORBA applications should use the name service instead. We
* do not use the name service as this would require to start additional
* external application, specific for the different java platforms.
*
* @author Audrius Meskauskas (AudriusA@Bioinformatics.org)
*/
public class X5Server
{
/**
* Start the game manager.
*/
public static void main(String[] args)
{
// Start the game manager, write the IOR to the agreed location.
OrbStarter.startManager(args);
if (!GameManagerImpl.ok)
{
System.out.println("Unable to start the game manager:");
System.exit(1);
}
// Print the IOR.
System.out.println(GameManagerImpl.ior);
String manager_address = null;
// Start the game manager server.
ServerSocket nameServer = null;
try
{
nameServer = new ServerSocket(OrbStarter.MANAGER_NAMER_PORT);
System.out.println("The game manager is listening at:");
manager_address = "http://"
+ InetAddress.getLocalHost().getHostAddress() + ":"
+ nameServer.getLocalPort();
System.out.println(manager_address);
System.out.println("Enter this address to the "
+ "input field of the game client.");
System.out.println("Use ^C to stop the manager.");
}
catch (Exception ex)
{
System.out.println("The port " + OrbStarter.MANAGER_NAMER_PORT
+ " is not available. The game manager namer will not start.");
System.exit(1);
}
// Write the IOR to the local file system.
if (OrbStarter.WRITE_URL_TO_FILE != null)
{
try
{
File gmf = new File(OrbStarter.WRITE_URL_TO_FILE);
FileWriter f = new FileWriter(gmf);
BufferedWriter b = new BufferedWriter(f);
b.write(manager_address);
b.close();
}
catch (IOException e)
{
System.out.println("Local filesystem not accessible."
+ "Read IOR from console.");
}
}
// Do forever.
while (true)
{
try
{
Socket socket = nameServer.accept();
System.out.println("Connected.");
// Set the two minutes timeout.
socket.setSoTimeout(1000 * 120);
OutputStream out = socket.getOutputStream();
int length = GameManagerImpl.ior.length();
StringBuffer b = new StringBuffer();
b.append("HTTP/1.0 200 OK\r\n");
b.append("Content-Length: " + length + "\r\n");
b.append("Connection: close\r\n");
b.append("Content-Type: text/plain; charset=UTF-8\r\n");
b.append("\r\n");
b.append(GameManagerImpl.ior);
out.write(b.toString().getBytes("UTF-8"));
socket.shutdownOutput();
if (!socket.isClosed())
socket.close();
System.out.println("Completed.");
}
catch (Exception exc)
{
exc.printStackTrace();
System.out.println("Network problem.");
}
}
}
}

View File

@@ -0,0 +1,214 @@
/* _GameManagerImpl_Tie.java --
Copyright (C) 2005 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath 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
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
package gnu.classpath.examples.CORBA.swing.x5;
import java.rmi.Remote;
import javax.rmi.PortableRemoteObject;
import javax.rmi.CORBA.Tie;
import org.omg.CORBA.BAD_OPERATION;
import org.omg.CORBA.ORB;
import org.omg.CORBA.SystemException;
import org.omg.CORBA.portable.InputStream;
import org.omg.CORBA.portable.OutputStream;
import org.omg.CORBA.portable.ResponseHandler;
import org.omg.CORBA.portable.UnknownException;
import org.omg.PortableServer.Servant;
/**
* Normally generated with rmic compiler, this class represents the GameManager
* Tie on the client side. The Game Manager methods contain the code for remote
* invocation.
*
* This class is normally generated with rmic from the {@link GameManagerImpl}:
*
* <pre>
* rmic -iiop -poa -keep gnu.classpath.examples.CORBA.swing.x5.GameManagerImpl
* </pre>
*
* (the compiled package must be present in the current folder).
*
* In this example the class was manually edited and commented for better
* understanding of functionality.
*
* @author Audrius Meskauskas (AudriusA@Bioinformatics.org)
*/
public class _GameManagerImpl_Tie
extends Servant
implements Tie
{
/**
* The target, where remote invocations are forwarded.
*/
private GameManagerImpl target = null;
/**
* The GameManager repository Id.
*/
private static final String[] _type_ids =
{ "RMI:gnu.classpath.examples.CORBA.swing.x5.GameManager:0000000000000000" };
/**
* Set the target where the remote invocations are forwarded.
*/
public void setTarget(Remote a_target)
{
this.target = (GameManagerImpl) a_target;
}
/**
* Get the target where the remote invocations are forwarded.
*/
public Remote getTarget()
{
return target;
}
/**
* Get the CORBA object for that this Tie is currently serving the request.
* The same tie may serve multiple requests for the different objects in
* parallel threads.
*/
public org.omg.CORBA.Object thisObject()
{
return _this_object();
}
/**
* Deactivate this object.
*/
public void deactivate()
{
try
{
_poa().deactivate_object(_poa().servant_to_id(this));
}
catch (org.omg.PortableServer.POAPackage.WrongPolicy exception)
{
}
catch (org.omg.PortableServer.POAPackage.ObjectNotActive exception)
{
}
catch (org.omg.PortableServer.POAPackage.ServantNotActive exception)
{
}
}
/**
* Get the ORB for this tie.
*/
public ORB orb()
{
return _orb();
}
/**
* Set the ORB for this tie.
*/
public void orb(ORB orb)
{
try
{
((org.omg.CORBA_2_3.ORB) orb).set_delegate(this);
}
catch (ClassCastException e)
{
throw new org.omg.CORBA.BAD_PARAM(
"POA Servant requires an instance of org.omg.CORBA_2_3.ORB");
}
}
/**
* Return all interfaces, supported by this method.
*/
public String[] _all_interfaces(org.omg.PortableServer.POA poa,
byte[] objectId)
{
return _type_ids;
}
/**
* This method is invoked by CORBA system to handle the remote invocation.
*
* @param method the name of the method being invoked.
* @param _in the stream to read the method parameters.
* @param reply the responsed handler that can create the output stream to
* write the parameters being returned.
*/
public OutputStream _invoke(String method, InputStream _in,
ResponseHandler reply)
throws SystemException
{
try
{
org.omg.CORBA_2_3.portable.InputStream in =
(org.omg.CORBA_2_3.portable.InputStream) _in;
if (method.equals("requestTheGame"))
{
Player p = (Player) PortableRemoteObject.narrow(
in.read_Object(), Player.class);
target.requestTheGame(p);
OutputStream out = reply.createReply();
return out;
}
else if (method.equals("unregister"))
{
Player p = (Player) PortableRemoteObject.narrow(
in.read_Object(), Player.class);
target.unregister(p);
OutputStream out = reply.createReply();
return out;
}
else
throw new BAD_OPERATION();
}
catch (SystemException ex)
{
throw ex;
}
catch (Throwable ex)
{
ex.printStackTrace();
throw new UnknownException(ex);
}
}
}

View File

@@ -0,0 +1,207 @@
/* _GameManager_Stub.java --
Copyright (C) 2005 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath 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
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
package gnu.classpath.examples.CORBA.swing.x5;
import java.rmi.RemoteException;
import java.rmi.UnexpectedException;
import javax.rmi.CORBA.Stub;
import javax.rmi.CORBA.Util;
import org.omg.CORBA.SystemException;
import org.omg.CORBA.portable.ApplicationException;
import org.omg.CORBA.portable.OutputStream;
import org.omg.CORBA.portable.RemarshalException;
import org.omg.CORBA.portable.ServantObject;
/**
* Normally generated with rmic compiler, this class represents the GameManager
* Stub on the client side. The Game Manager methods contain the code for
* remote invocation.
*
* This class is normally generated with rmic from the {@link GameManagerImpl}:
* <pre>
* rmic -iiop -poa -keep gnu.classpath.examples.CORBA.swing.x5.GameManagerImpl
* </pre>
* (the compiled package must be present in the current folder).
*
* @author Audrius Meskauskas (AudriusA@Bioinformatics.org)
*/
public class _GameManager_Stub extends Stub implements GameManager
{
/**
* Use serialVersionUID for interoperability.
*/
private static final long serialVersionUID = 1;
private static final String[] _type_ids =
{ "RMI:gnu.classpath.examples.CORBA.swing.x5.GameManager:0000000000000000" };
public String[] _ids()
{
return _type_ids;
}
/**
* Notify the manager that the player is no longer willing to play and
* should be removed from the queue.
*/
public void unregister(Player p)
throws RemoteException
{
if (!Util.isLocal(this))
{
try
{
org.omg.CORBA.portable.InputStream in = null;
try
{
OutputStream out = _request("unregister", true);
Util.writeRemoteObject(out, p);
_invoke(out);
}
catch (ApplicationException ex)
{
in = ex.getInputStream();
String id = in.read_string();
throw new UnexpectedException(id);
}
catch (RemarshalException ex)
{
unregister(p);
}
finally
{
_releaseReply(in);
}
}
catch (SystemException ex)
{
throw Util.mapSystemException(ex);
}
}
else
{
ServantObject so =
_servant_preinvoke("requestTheGame", GameManager.class);
if (so == null)
{
unregister(p);
return;
}
try
{
((GameManager) so.servant).unregister(p);
}
catch (Throwable ex)
{
Throwable exCopy = (Throwable) Util.copyObject(ex, _orb());
throw Util.wrapException(exCopy);
}
finally
{
_servant_postinvoke(so);
}
}
}
/**
* The method that the user should invoke.
*/
public void requestTheGame(Player arg0) throws RemoteException
{
if (!Util.isLocal(this))
{
try
{
org.omg.CORBA.portable.InputStream in = null;
try
{
OutputStream out = _request("requestTheGame", true);
Util.writeRemoteObject(out, arg0);
_invoke(out);
}
catch (ApplicationException ex)
{
in = ex.getInputStream();
String id = in.read_string();
throw new UnexpectedException(id);
}
catch (RemarshalException ex)
{
requestTheGame(arg0);
}
finally
{
_releaseReply(in);
}
}
catch (SystemException ex)
{
throw Util.mapSystemException(ex);
}
}
else
{
ServantObject so =
_servant_preinvoke("requestTheGame", GameManager.class);
if (so == null)
{
requestTheGame(arg0);
return;
}
try
{
Player arg0Copy = (Player) Util.copyObject(arg0, _orb());
((GameManager) so.servant).requestTheGame(arg0Copy);
}
catch (Throwable ex)
{
Throwable exCopy = (Throwable) Util.copyObject(ex, _orb());
throw Util.wrapException(exCopy);
}
finally
{
_servant_postinvoke(so);
}
}
}
}

View File

@@ -0,0 +1,212 @@
/* _PlayerImpl_Tie.java --
Copyright (C) 2005 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath 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
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
package gnu.classpath.examples.CORBA.swing.x5;
import java.awt.Point;
import java.rmi.Remote;
import javax.rmi.PortableRemoteObject;
import javax.rmi.CORBA.Tie;
import org.omg.CORBA.BAD_OPERATION;
import org.omg.CORBA.ORB;
import org.omg.CORBA.SystemException;
import org.omg.CORBA.portable.InputStream;
import org.omg.CORBA.portable.OutputStream;
import org.omg.CORBA.portable.ResponseHandler;
import org.omg.CORBA.portable.UnknownException;
import org.omg.PortableServer.Servant;
/**
* Generate with rmic, command line
* rmic -iiop -poa -keep gnu.classpath.examples.CORBA.swing.x5.PlayerImpl
* (the compiled package must be present in the current folder).
*
* This class is normally generated with rmic from the {@link PlayerImpl}:
* <pre>
* rmic -iiop -poa -keep gnu.classpath.examples.CORBA.swing.x5.PlayerImpl
* </pre>
* (the compiled package must be present in the current folder).
*
* In this example the class was manually edited and commented for better
* understanding of functionality.
*
* @author Audrius Meskauskas (AudriusA@Bioinformatics.org)
*/
public class _PlayerImpl_Tie extends Servant implements Tie
{
private PlayerImpl target = null;
private static final String[] _type_ids =
{ "RMI:gnu.classpath.examples.CORBA.swing.x5.Player:0000000000000000" };
public void setTarget(Remote a_target)
{
this.target = (PlayerImpl) a_target;
}
public Remote getTarget()
{
return target;
}
public org.omg.CORBA.Object thisObject()
{
return _this_object();
}
public void deactivate()
{
try
{
_poa().deactivate_object(_poa().servant_to_id(this));
}
catch (org.omg.PortableServer.POAPackage.WrongPolicy exception)
{
}
catch (org.omg.PortableServer.POAPackage.ObjectNotActive exception)
{
}
catch (org.omg.PortableServer.POAPackage.ServantNotActive exception)
{
}
}
public ORB orb()
{
return _orb();
}
public void orb(ORB orb)
{
try
{
((org.omg.CORBA_2_3.ORB) orb).set_delegate(this);
}
catch (ClassCastException e)
{
throw new org.omg.CORBA.BAD_PARAM(
"POA Servant requires an instance of org.omg.CORBA_2_3.ORB"
);
}
}
public String[] _all_interfaces(org.omg.PortableServer.POA poa,
byte[] objectId
)
{
return _type_ids;
}
public OutputStream _invoke(String method, InputStream _in,
ResponseHandler reply
) throws SystemException
{
try
{
org.omg.CORBA_2_3.portable.InputStream in =
(org.omg.CORBA_2_3.portable.InputStream) _in;
switch (method.charAt(9))
{
case 101 :
if (method.equals("start_game"))
{
Player arg0 =
(Player) PortableRemoteObject.narrow(in.read_Object(),
Player.class
);
boolean arg1 = in.read_boolean();
boolean result = target.start_game(arg0, arg1);
OutputStream out = reply.createReply();
out.write_boolean(result);
return out;
}
case 104 :
if (method.equals("receive_chat"))
{
byte arg0 = in.read_octet();
String arg1 = (String) in.read_value(String.class);
target.receive_chat(arg0, arg1);
OutputStream out = reply.createReply();
return out;
}
case 111 :
if (method.equals("receive_move"))
{
int arg0 = in.read_long();
int arg1 = in.read_long();
Point[] arg2 = (Point[]) in.read_value(Point[].class);
target.receive_move(arg0, arg1, arg2);
OutputStream out = reply.createReply();
return out;
}
case 114 :
if (method.equals("_get_J_current_state"))
{
int result = target.get_current_state();
OutputStream out = reply.createReply();
out.write_long(result);
return out;
}
case 116 :
if (method.equals("disconnect"))
{
target.disconnect();
OutputStream out = reply.createReply();
return out;
}
}
throw new BAD_OPERATION("No such method: '"+method+"'");
}
catch (SystemException ex)
{
throw ex;
}
catch (Throwable ex)
{
throw new UnknownException(ex);
}
}
}

View File

@@ -0,0 +1,397 @@
/* _Player_Stub.java --
Copyright (C) 2005 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath 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
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
package gnu.classpath.examples.CORBA.swing.x5;
import java.awt.Point;
import java.io.Serializable;
import java.rmi.RemoteException;
import java.rmi.UnexpectedException;
import javax.rmi.CORBA.Stub;
import javax.rmi.CORBA.Util;
import org.omg.CORBA.SystemException;
import org.omg.CORBA.portable.ApplicationException;
import org.omg.CORBA.portable.OutputStream;
import org.omg.CORBA.portable.RemarshalException;
import org.omg.CORBA.portable.ServantObject;
/**
* Generate with rmic, command line
* rmic -iiop -poa -keep gnu.classpath.examples.CORBA.swing.x5.PlayerImpl
* (the compiled package must be present in the current folder).
*
* This class is normally generated with rmic from the {@link GameManagerImpl}:
* <pre>
* rmic -iiop -poa -keep gnu.classpath.examples.CORBA.swing.x5.GameManagerImpl
* </pre>
* (the compiled package must be present in the current folder).
*
* In this example the class was manually edited and commented for better
* understanding of functionality.
*
* @author Audrius Meskauskas (AudriusA@Bioinformatics.org)
*/
public class _Player_Stub extends Stub implements Player
{
/**
* Use serialVersionUID for interoperability.
*/
private static final long serialVersionUID = 1;
private static final String[] _type_ids =
{ "RMI:gnu.classpath.examples.CORBA.swing.x5.Player:0000000000000000" };
public String[] _ids()
{
return _type_ids;
}
public boolean start_game(Player arg0, boolean arg1)
throws RemoteException
{
if (!Util.isLocal(this))
{
try
{
org.omg.CORBA.portable.InputStream in = null;
try
{
OutputStream out = _request("start_game", true);
Util.writeRemoteObject(out, arg0);
out.write_boolean(arg1);
in = _invoke(out);
return in.read_boolean();
}
catch (ApplicationException ex)
{
in = ex.getInputStream();
String id = in.read_string();
throw new UnexpectedException(id);
}
catch (RemarshalException ex)
{
return start_game(arg0, arg1);
}
finally
{
_releaseReply(in);
}
}
catch (SystemException ex)
{
throw Util.mapSystemException(ex);
}
}
else
{
ServantObject so = _servant_preinvoke("start_game", Player.class);
if (so == null)
{
return start_game(arg0, arg1);
}
try
{
Player arg0Copy = (Player) Util.copyObject(arg0, _orb());
return ((Player) so.servant).start_game(arg0Copy, arg1);
}
catch (Throwable ex)
{
Throwable exCopy = (Throwable) Util.copyObject(ex, _orb());
throw Util.wrapException(exCopy);
}
finally
{
_servant_postinvoke(so);
}
}
}
public int get_current_state() throws RemoteException
{
if (!Util.isLocal(this))
{
try
{
org.omg.CORBA.portable.InputStream in = null;
try
{
OutputStream out = _request("_get_J_current_state", true);
in = _invoke(out);
return in.read_long();
}
catch (ApplicationException ex)
{
in = ex.getInputStream();
String id = in.read_string();
throw new UnexpectedException(id);
}
catch (RemarshalException ex)
{
return get_current_state();
}
finally
{
_releaseReply(in);
}
}
catch (SystemException ex)
{
throw Util.mapSystemException(ex);
}
}
else
{
ServantObject so =
_servant_preinvoke("_get_J_current_state", Player.class);
if (so == null)
{
return get_current_state();
}
try
{
return ((Player) so.servant).get_current_state();
}
catch (Throwable ex)
{
Throwable exCopy = (Throwable) Util.copyObject(ex, _orb());
throw Util.wrapException(exCopy);
}
finally
{
_servant_postinvoke(so);
}
}
}
public void receive_chat(byte arg0, String arg1) throws RemoteException
{
if (!Util.isLocal(this))
{
try
{
org.omg.CORBA_2_3.portable.InputStream in = null;
try
{
org.omg.CORBA_2_3.portable.OutputStream out =
(org.omg.CORBA_2_3.portable.OutputStream) _request("receive_chat",
true
);
out.write_octet(arg0);
out.write_value(arg1, String.class);
_invoke(out);
}
catch (ApplicationException ex)
{
in =
(org.omg.CORBA_2_3.portable.InputStream) ex.getInputStream();
String id = in.read_string();
throw new UnexpectedException(id);
}
catch (RemarshalException ex)
{
receive_chat(arg0, arg1);
}
finally
{
_releaseReply(in);
}
}
catch (SystemException ex)
{
throw Util.mapSystemException(ex);
}
}
else
{
ServantObject so = _servant_preinvoke("receive_chat", Player.class);
if (so == null)
{
receive_chat(arg0, arg1);
return;
}
try
{
((Player) so.servant).receive_chat(arg0, arg1);
}
catch (Throwable ex)
{
Throwable exCopy = (Throwable) Util.copyObject(ex, _orb());
throw Util.wrapException(exCopy);
}
finally
{
_servant_postinvoke(so);
}
}
}
public void disconnect() throws RemoteException
{
if (!Util.isLocal(this))
{
try
{
org.omg.CORBA.portable.InputStream in = null;
try
{
OutputStream out = _request("disconnect", true);
_invoke(out);
}
catch (ApplicationException ex)
{
in = ex.getInputStream();
String id = in.read_string();
throw new UnexpectedException(id);
}
catch (RemarshalException ex)
{
disconnect();
}
finally
{
_releaseReply(in);
}
}
catch (SystemException ex)
{
throw Util.mapSystemException(ex);
}
}
else
{
ServantObject so = _servant_preinvoke("disconnect", Player.class);
if (so == null)
{
disconnect();
return;
}
try
{
((Player) so.servant).disconnect();
}
catch (Throwable ex)
{
Throwable exCopy = (Throwable) Util.copyObject(ex, _orb());
throw Util.wrapException(exCopy);
}
finally
{
_servant_postinvoke(so);
}
}
}
public void receive_move(int arg0, int arg1, Point[] arg2)
throws RemoteException
{
if (!Util.isLocal(this))
{
try
{
org.omg.CORBA_2_3.portable.InputStream in = null;
try
{
org.omg.CORBA_2_3.portable.OutputStream out =
(org.omg.CORBA_2_3.portable.OutputStream) _request("receive_move",
true
);
out.write_long(arg0);
out.write_long(arg1);
out.write_value(cast_array(arg2), Point[].class);
_invoke(out);
}
catch (ApplicationException ex)
{
in =
(org.omg.CORBA_2_3.portable.InputStream) ex.getInputStream();
String id = in.read_string();
throw new UnexpectedException(id);
}
catch (RemarshalException ex)
{
receive_move(arg0, arg1, arg2);
}
finally
{
_releaseReply(in);
}
}
catch (SystemException ex)
{
throw Util.mapSystemException(ex);
}
}
else
{
ServantObject so = _servant_preinvoke("receive_move", Player.class);
if (so == null)
{
receive_move(arg0, arg1, arg2);
return;
}
try
{
Point[] arg2Copy = (Point[]) Util.copyObject(arg2, _orb());
((Player) so.servant).receive_move(arg0, arg1, arg2Copy);
}
catch (Throwable ex)
{
Throwable exCopy = (Throwable) Util.copyObject(ex, _orb());
throw Util.wrapException(exCopy);
}
finally
{
_servant_postinvoke(so);
}
}
}
// This method is required as a work-around for
// a bug in the JDK 1.1.6 verifier.
private Serializable cast_array(Object obj)
{
return (Serializable) obj;
}
}