From: markspace on
Screamin Lord Byron wrote:

> What matters is that players can't just play any card they like (they
> must follow suit, etc.). The Player class has the hand field which
> contains 8 cards (that class is what the BarImpl represents in my example).
>
> The dealing part is done on the server. The idea is this. At the
> begining of the game, all clients (one for each player) must send the
> name of the player (and possibly some ID) by invoking some construction
> code (something like constructBar() in my example), and it receives a
> Player remote object from the server (which already contains his cards).
>
> When player chooses a card to play, the server must check if it's a
> valid move. Client uses a chooseCard(Card c) method of the Player class
> which marks the chosen card and enables the game logic on the server to
> check it and proceed if it's ok (remove it from hand). What I want to do
> is to call player.chooseCard(card) from the client. Of course, this
> means that the client's player object must not be a mere copy of the
> server's player object, but it must be a remote object.


The first thing that occurs to me is something like this:

interface BelotRmi {
Player getPlayer( String name );
void playCard( Card card );
}

where Player's chooseCard() method invokes the playCard method above,
which may or may not be a great idea. Let me think about this some more...
From: Esmond Pitt on
On 23/07/2010 4:22 AM, Screamin Lord Byron wrote:
> public interface Foo extends Remote {
> public Bar constructBar(String name);
> // other stuff
> }

This is a remote factory pattern, and Foo is the factory. You need to
register that in the Registry.

> public interface Bar extends Remote {
> public void mutate();
> }

You don't need to create *any* implementations of BarImpl until somebody
calls constructBar(), and you never need to bind them to the Registry.

Done.

@Tom, you only need to call UnicastRemoteObject.exportObject() if the
remote object doesn't extend UnicastRemoteObject or Activatable.
From: Michal Kleczek on
Screamin Lord Byron wrote:

> Hello,
>
> I am learning RMI and I ran into this difficulty.
>
> Let's say we have:
>
> import java.rmi.*;
>
> public interface Foo extends Remote {
> public Bar constructBar(String name);
> // other stuff
> }
>
> public interface Bar extends Remote {
> public void mutate();

add "throws RemoteException" here otherwise...

> java.lang.IllegalArgumentException: illegal remote method encountered:
> public abstract void Bar.mutate()
>

--
Michal
From: Screamin Lord Byron on
On 07/23/2010 03:41 AM, Esmond Pitt wrote:
> On 23/07/2010 4:22 AM, Screamin Lord Byron wrote:
>> public interface Foo extends Remote {
>> public Bar constructBar(String name);
>> // other stuff
>> }
>
> This is a remote factory pattern, and Foo is the factory. You need to
> register that in the Registry.


Yes. That's exactly what I need, but I haven't find a way how to do it
(register Foo as a factory). Is this done with some additional
parameters to the Context object?

For now I have something like:

Context initialContext = new InitialContext();
initialContext.bind("rmi:my_foo", myFoo);

I see that there is a constant InitialContext.INITIAL_CONTEXT_FACTORY.
Has that something to do with what I need to do? I suppose it hasn't, as
InitialContext() is just a factory for contexts.

Sorry if I'm asking dumb questions, but I only just started with RMI
yesterday, so there's still quite a mess inside my head.

Could you please give me some pointers on how to register Foo as a
factory in the Registry. I couldn't find any examples of it on Oracle's
site or my books (Core Java I and II - Horstmann/Cornell) either.

Some short example of the registration would be very helpful and
appreciated.

Thank you.



>
>> public interface Bar extends Remote {
>> public void mutate();
>> }
>
> You don't need to create *any* implementations of BarImpl until somebody
> calls constructBar(), and you never need to bind them to the Registry.

Good news. :)
Thanks.
From: Screamin Lord Byron on
On 07/23/2010 12:08 PM, Michal Kleczek wrote:
> Screamin Lord Byron wrote:
>
>> Hello,
>>
>> I am learning RMI and I ran into this difficulty.
>>
>> Let's say we have:
>>
>> import java.rmi.*;
>>
>> public interface Foo extends Remote {
>> public Bar constructBar(String name);
>> // other stuff
>> }
>>
>> public interface Bar extends Remote {
>> public void mutate();
>
> add "throws RemoteException" here otherwise...

:) Ha. It's the simple things. Thank you, Michal. That was in fact the
problem. I just didn't know how to read the exception I got.

Now it works. I get this for a newly constructed object on the client:

Proxy[RemotePlayer,RemoteObjectInvocationHandler[UnicastRef [liveRef:
[endpoint:[127.0.1.1:37325](remote),objID:[-9ab963d:129feecc4a1:-7ffc,
-7563478605164479550]]]]]

I suppose that is indeed a true remote object, and I didn't change
anything in the code apart from adding that throws clause.

Thanks once again.