RMI Interface

I am working on chatting program using RMI. I have an Interface called "Chatter" as follows:
-- Note this is a part of the code:
package chat;
public interface Chatter extends java.rmi.Remote
public void receiveEnter(String name, Chatter chatter) throws java.rmi.RemoteException;
public void receiveExit(String name) throws java.rmi.RemoteException;
Now I have another interface that uses the "Chatter Interface" as follows:
package chat;
public interface ChatServer extends java.rmi.Remote {
     public void login(String name, Chatter chatter) throws java.rmi.RemoteException;
when I am trying to complie the second file, an error shows up :"cannot resolve symbol". the compiler could not recognize the "Chatter" interface. I am putting the files in the same folder.
Can anyone knows what I am missing here?

Crosspost...
http://forum.java.sun.com/thread.jsp?forum=54&thread=449429
Don't do this crossposting thing, k? If someone had answered you here ...meaning you would have never needed to ever return and read my post to your other thread, that would have made my response a big fat waste of my time. Then, I might decide to never post answers to your questions again ...meaning the overall quality of service to you has deminished somewhat. Just don't do it.
Get ahead.

Similar Messages

  • Rmi interface not loading when invoked from class in package

    Hi, It would be a great help if you could help me out with the following problem:
    The RMIClient fails to detect the remote object interface in the current directory when i place it within a package.
    1) I tried placing the remote object interface in the same package - this didn't change the error output.
    2) I tried to import the remote object by placing the parent's parent directory in the classpath - a new error popped up saying the file did not contain any class! Since its an RMI interface extending remote, it dosen't involve a class directly.
    The following is my client code:
    package java.util.logging;  // Without this line, this client works fine.
    import java.rmi.*;
    import java.rmi.server.*;
    import java.io.*;
    import java.util.logging.*;
    import logTest.RMIChannel;
    public class RMIChannelClient
       public static void main(String[] args)
          System.setProperty("java.security.policy", "client.policy");
          System.setSecurityManager(new RMISecurityManager());
          String url = "rmi://acrux.cis.ksu.edu/";
          LogRecord record= new LogRecord(Level.ALL,"");
          try
             RMIChannel rc = (RMIChannel)Naming.lookup(url + "RMI_Channel");
          rc.sendRecord(record);
          catch(Exception e)
             e.printStackTrace();
    }The following is my interface extending remote:
    //package java.util.logging;  // I tried adding and removing this line but to no avail
    import java.rmi.*;
    import java.util.logging.LogRecord;
    public interface RMIChannel extends Remote
      String getDescription() throws RemoteException;
      void sendRecord(LogRecord record) throws RemoteException;
    }Could anyone suggest a solution to this issue?
    Thanks.

    ok. i was hoping to write my own logging class (extending upon sun's classes). while doing this, i found that LogManager.getStringProperty() is not a public method and cannot be accessed outside the java.util.logging package and the compiler complained. So i tried placing my file in java.util.logging package and it compiled fine. Is there a way i can use a method thats not declared public without importing its package?

  • What relationship between RMI interface and stub?

    Hi:
    I think the stub is enough to remote call, why to use RMI interface? what relationship
    between RMI interface and stub?
    Regards!
    Stive

    Hi,
    Stub is merely a proxy for server , it doesn't contain any declarations of
    remote methods. to which it is being responsible for .
    where RMI interface is one which contains signature of the Remote methods which
    throws Remote Exception.
    Regards
    Karthikeyan Gangadharan
    SIP Technologies, Chennai
    E-mail-ID: [email protected]
    "Stive" <[email protected]> wrote:
    >
    Hi:
    I think the stub is enough to remote call, why to use RMI interface?
    what relationship
    between RMI interface and stub?
    Regards!
    Stive

  • RMI interface/packaging issue

    Hi
    I am new to RMI and almost new to Java, so bare with me.
    I am doing a project where I use RMI to access a database on a remote server from a client. As far as I understand the interface MUST be located at both the client pc and the server pc. Am I right?
    My interface must implement classes corresponding to the tables in the server database which the client is to access, since the interface methods return ArrayLists containing objects of these "table-classes".
    I do this, so that I can wrap each tuble/row into an object of a class corresponding to the table from which I queried the data.
    Example from one of my interface methods:
    public ArrayList<PatientData> getMedicineUsage(String patientID) throws RemoteException;There are eight such "table-classes", thus eight tables placed in a "database" package on the server.
    Do I really have to place a package containing these "table-classes" (eg. PatientData) on BOTH the server (package hierarchy program::server::database) and the client (package hierarchy program::client::database)?
    Am I doing it 'all wrong', or is the solution in fact to create a "database" package on the client as well?
    If you miss any information, please tell me, and I will write back right away.
    PS. I use the RMI because my clients are not allowed to access the database directly.

    But how do I do this practically?Nobody cares what exactly you call the package that contains the remote interface but it has to be the same at server and the client and it has to be deployed at the server and the client. It has to be the same code. Not a copy in a different package. Two classes in different packages are different regardless of their names or anything else.
    1. As I understand your answer, I should only have ONE package containing my "table"-classes located on the server, right?Yes.
    2. Am I right about the interface that it should be placed on both the client and the server, but only implemented by the server?Yes.
    3. How do I share the "table"-classes within my program::server::database package with the remote client as you proposed, so that the client "knows" the datatypes (eg.ArrayList<PatientData>) required by the interface?See above.

  • Accessing RMI Application through an Applet hosted on Apache web server

    Hi All,
    Just to let you know, I'm a complete novice at RMI. Ok, heres the story...I have an applet which is deployed on Apache Webserver (localhost), with the neccessary files needed for the RMI app in the same directory - htdocs(i.e. Applet class, RMI Interface, and Stub). I have the object server running on the same machine - which is in the directory C:/pumps. For the binding I'm using rmi://localhost/PumpService. I'm running the rmiregistry in the C directory. The problem is that when I access the applet through localhost(i.e. http://localhost/pumps.htm) it doesnt work, doesnt seem to access the remote object. However, if I directly load the html page from C:/Apache2/htdocs/pumps.htm - it works perfectly. Any ideas on the way I could get it working through the localhost?
    Thanks...

    The problem is that
    when I access the applet through localhost(i.e.
    http://localhost/pumps.htm) it doesnt work, doesnt
    seem to access the remote object.Are the exception and the line of code you get it on a secret?

  • Error in RMI simple code!

    i am using 4 files for rmi
    //Interface file
    public interface Calculator extends java.rmi.Remote{
    public long add(long a,long b)throws java.rmi.RemoteException;
    public long sub(long a,long b)throws java.rmi.RemoteException;
    public long mul(long a,long b)throws java.rmi.RemoteException;
    public long div(long a,long b)throws java.rmi.RemoteException;
    //Implementation file
    public class CalculatorImpl extends java.rmi.server.UnicastRemoteObject
    implements Calculator{
    public CalculatorImpl() throws java.rmi.RemoteException
    super();
    public long add(long a, long b) throws RemoteException {
    return(a+b);
    public long sub(long a, long b) throws RemoteException {
    return(a-b);
    public long mul(long a, long b) throws RemoteException {
    return(a*b);
    public long div(long a, long b) throws RemoteException {
    return(a/b);
    //Server File
    import java.rmi.Naming;
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    * @author Vedita
    public class CalculatorServer {
    public CalculatorServer(){
    try{
    Calculator c = (Calculator) new CalculatorImpl();
    Naming.rebind("rmi://localhost:1099/Calculator", c);
    catch (Exception e) {
    System.out.println("Trouble"+e);
    public static void main(String args[]){
    new CalculatorServer();
    //Client File
    import java.net.MalformedURLException;
    import java.rmi.Naming;
    import java.rmi.NotBoundException;
    import java.rmi.RemoteException;
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    * @author Vedita
    public class CalculatorClient {
    public static void main(String args[]) throws NotBoundException, MalformedURLException, RemoteException{
    try{
    Calculator c= (Calculator) Naming.lookup("rmi://remotehost:1099/Calculator");
    System.out.println(c.sub(4, 3));
    System.out.println(c.add(4, 5));
    System.out.println(c.mul(3, 6));
    System.out.println(c.div(9, 3));
    catch(MalformedURLException murle){
    System.out.println();
    System.out.println("MalformedURLException");
    System.out.println(murle);
    catch(RemoteException re){
    System.out.println();
    System.out.println("RemoteException");
    System.out.println(re);
    catch(NotBoundException nbe){
    System.out.println();
    System.out.println("NotBoundException");
    System.out.println(nbe);
    catch(java.lang.ArithmeticException ae){
    System.out.println();
    System.out.println("ArithmeticException");
    System.out.println(ae);
    i am executing the code as follows in command prompt
    in one cmd prompt
    javac *.java
    rmic CalculatorImpl
    rmiregistry
    in other cmd prompt
    javac *.java
    java CalculatorServer
    i am getting this error
    Error java.rmi.ServerException: RemoteException occurred in server thread; nested exception is:
    java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is:
    java.lang.ClassNotFoundException: CalculatorImpl_Stub
    Please Please help me because i have to submit the project in my college and this basic program is also not working in my pc. Please can anyone help me?

    //Implementation file
    public class CalculatorImpl extends java.rmi.server.UnicastRemoteObject
    implements Calculator{
    public CalculatorImpl() throws java.rmi.RemoteException
    super();super(0);

  • Trouble in storing and retrieving RMI object in Weblogic 7 JNDI tree.

    I have created a simple server (BankImpl), implementing a RMI interface
    called Bank. A stub class (BankImpl_Stub.class) is generated from BankImpl
    class using
    "rmic -v1.2". Then I bind an instance of the BankImpl class to the JNDI tree
    in Weblogic
    server 7 under the name of "PeopleBank".
    After the binding, I can see the stub class in the JNDI tree, but with a
    different name: BankImpl_WLStub.class). when a
    client program is trying to lookup the stub associated with "PeopleBank", it
    failed with a puzzling message:
    java.io.NotSerializableException: BankImpl_WLStub
    Why a stub of a RMI object is not serializable? Does Weblogic needs a
    different rmic to generate RMI stubs?
    Thanks,
    Lian

    I have created a simple server (BankImpl), implementing a RMI interface
    called Bank. A stub class (BankImpl_Stub.class) is generated from BankImpl
    class using
    "rmic -v1.2". Then I bind an instance of the BankImpl class to the JNDI tree
    in Weblogic
    server 7 under the name of "PeopleBank".
    After the binding, I can see the stub class in the JNDI tree, but with a
    different name: BankImpl_WLStub.class). when a
    client program is trying to lookup the stub associated with "PeopleBank", it
    failed with a puzzling message:
    java.io.NotSerializableException: BankImpl_WLStub
    Why a stub of a RMI object is not serializable? Does Weblogic needs a
    different rmic to generate RMI stubs?
    Thanks,
    Lian

  • Problem using CORBA clients with RMI/EJB servers..!!!???

    Hi,
    I have a question on using EJB / or RMI servers with CORBA clients using
    RMI-IIOP transport, which in theory should work, but in practice has few
    glitches.
    Basically, I have implemented a very simple server, StockTreader, which
    looks up for a symbol and returns a 'Stock' object. In the first example, I
    simplified the 'Stock' object to be a mere java.lang.String, so that lookup
    would simply return the 'synbol'.
    Then I have implemented the above, as an RMI-IIOP server (case 1) and a
    CORBA server (case 2) with respective clients, and the pair of
    client-servers work fine as long as they are CORBA-to-CORBA and RMI-to-RMI.
    But the problem arises when I tried using the RMI server (via IIOP) with the
    CORBA client, when the client tries to narrow the object ref obtained from
    the naming service into the CORBA idl defined type (StockTrader) it ends up
    with a class cast exception.
    This is what I did to achieve the above results:
    [1] Define an RMI interface StockTrader.java (extending java.rmi.Remote)
    with the method,
    public String lookup( String symbol) throws RMIException;
    [2] Implement the StorckTrader interface (on a PortableRemoteObject derived
    class, to make it IIOP compliant), and then the server to register the stock
    trader with COS Naming service as follows:
    String homeName =....
    StockTraderImpl trader =new StockTraderImpl();
    System.out.println("binding obj <" homeName ">...");
    java.util.Hashtable ht =new java.util.Hashtable();
    ht.put("java.naming.factory.initial", args[2]);
    ht.put("java.naming.provider.url", args[3]);
    Context ctx =new InitialContext(ht);
    ctx.rebind(homeName, trader);
    [3] Generate the RMI-IIOP skeletons for the Implementation class,
    rmic -iiop stock.StockTraderImpl
    [4] generate the IDL for the RMI interface,
    rmic -idl stock.StockTraderImpl
    [5] Generate IDL stubs for the CORBA client,
    idlj -v -fclient -emitAll StockTraderImpl.idl
    [6] Write the client to use the IDL-defined stock trader,
    String serverName =args[0];
    String symList =args[1];
    StockClient client =new StockClient();
    System.out.println("init orb...");
    ORB orb =ORB.init(args, null);
    System.out.println("resolve init name service...");
    org.omg.CORBA.Object objRef
    =orb.resolve_initial_references("NameService");
    NamingContext naming =NamingContextHelper.narrow(objRef);
    ... define a naming component etc...
    org.omg.CORBA.Object obj =naming.resolve(...);
    System.out.println("narrow objRef: " obj.getClass() ": " +obj);
    StockTrader trader =StockTraderHelper.narrow(obj);
    [7] Compile all the classes using Java 1.2.2
    [8] start tnameserv (naming service), then the server to register the RMI
    server obj
    [9] Run the CORBA client, passing it the COSNaming service ref name (with
    which the server obj is registered)
    The CORBA client successfully finds the server obj ref in the naming
    service, the operation StockTraderHelper.narrow() fails in the segment
    below, with a class cast exception:
    org.omg.CORBA.Object obj =naming.resolve(...);
    StockTrader trader =StockTraderHelper.narrow(obj);
    The <obj> returned by naming service turns out to be of the type;
    class com.sun.rmi.iiop.CDRInputStream$1
    This is of the same type when stock trader object is registered in a CORBA
    server (as opposed to an RMI server), but works correctly with no casting
    excpetions..
    Any ideas / hints very welcome.
    thanks in advance,
    -hari

    On the contrary... all that is being said is that we needed to provide clearer examples/documentation in the 5.1.0 release. There will be no difference between the product as found in the service pack and the product found in the 5.1.1. That is, the only substantive will be that 5.1.1 will also
    include the examples.
    "<=one way=>" wrote:
    With reference to your and other messages, it appears that one should not
    expect that WLS RMI-IIOP will work in a complex real-life system, at least
    not now. In other words, support for real-life CORBA clients is not an
    option in the current release of WLS.
    TIA
    "Eduardo Ceballos" <[email protected]> wrote in message
    news:[email protected]...
    We currently publish an IDL example, even though the IDL programmingmodel in Java is completely non-functional, in anticipation of the support
    needs for uses who need to use IDL to talk to the Weblogic server,
    generically. This example illustrates the simplest connectivity; it does not
    address how
    to integrate CORBA and EJB, a broad topic, fraught with peril, imo. I'llnote in passing that, to my knowledge, none of the other vendors attempt
    this topic either, a point which is telling if all the less happy to hear.
    For the record then, what is missing from our distribution wrt RMI-IIOPare a RMI-IIOP example, an EJB-IIOP example, an EJB-C++. In this you are
    correct; better examples are forth coming.
    Still, I would not call our RMI-IIOP implementation fragile. I would saythat customers have an understandably hard time accepting that the IDL
    programming model is busted; busted in the sense that there are no C++
    libraries to support the EJB model, and busted in the sense that there is
    simply no
    support in Java for an IDL interface to an EJB. Weblogic has nothing to doit being busted, although we are trying to help our customers deal with it
    in productive ways.
    For the moment, what there is is a RMI (over IIOP) programming model, aninherently Java to Java programming model, and true to that, we accept and
    dispatch IIOP request into RMI server objects. The way I look at it is this:
    it's just a protocol, like HTTP, or JRMP; it's not IDL and it has
    practically nothing to do with CORBA.
    ST wrote:
    Eduardo,
    Can you give us more details about the comment below:
    I fear that as soon as the call to narrow succeeds, the remainingapplication will fail to work correctly because it is too difficult ot
    use an idl client in java to work.It seems to me that Weblogic's RMI-IIOP is a very fragile
    implementation. We
    don't need a "HelloWorld" example, we need a concrete serious example(fully
    tested and seriously documented) that works so that we can get a betteridea
    on how to integrate CORBA and EJB.
    Thanks,
    Said
    "Eduardo Ceballos" <[email protected]> wrote in message
    news:[email protected]...
    Please post request to the news group...
    As I said, you must separate the idl related classes (class files and
    java
    files) from the rmi classes... in the rmic step, you must set a newtarget
    (as you did), emit the java files into that directory (it's not clearyou
    did this), then remove all the rmi class files from the class path... ifyou
    need to compile more classes at that point, copy the java files to theidl
    directly is you must, but you can not share the types in any way.
    I fear that as soon as the call to narrow succeeds, the remainingapplication will fail to work correctly because it is too difficult otuse
    an idl client in java to work.
    Harindra Rajapakshe wrote:
    Hi Eduardo,
    Thanks for the help. That is the way I compiled my CORBA client, by
    separating the IDL-generated stubs from the RMI ones, but still I
    get a
    CORBA.BAD_PARAM upon narrowing the client proxy to the interfacetype.
    Here's what I did;
    + Define the RMI interfaces, in this case a StockTrader interface.
    + Implement RMI interface by extendingjavax.rmi.PortableRemoteObject
    making
    it IIOP compliant
    + Implemnnt an RMI server, and compile using JDK1.2.2
    + use the RMI implementation to generate CORBA idl, using RMI-IIOPplugin
    utility rmic;
    rmic -idl -noValueMethods -always -d idl stock.StockTraderImpl
    + generate Java mappings to the IDL generated above, using RMI-IIOPplugin
    util,
    idlj -v -fclient -emitAll -tf src stocks\StockTrader.idl
    This creates source for the package stock and also
    org.omg.CORBA.*
    package, presumably IIOP type marshalling
    + compile all classes generated above using JDK1.2.2
    + Implement client (CORBA) using the classes generated above, NOTthe
    RMI
    proxies.
    + start RMI server, with stockTrader server obj
    + start tnameserv
    + start CORBA client
    Then the client errors when trying to narrow the obj ref from the
    naming
    service, into the CORBA IDL defined interface using,
    org.omg.CORBA.Object obj =naming.resolve(nn);
    StockTrader trader =StockTraderHelper.narrow(obj); // THIS
    ERRORS..!!!
    throwing a CORBA.BAD_PARAM exception.
    any ideas..?
    Thanks in advance,
    -hari
    ----- Original Message -----
    From: Eduardo Ceballos <[email protected]>
    Newsgroups: weblogic.developer.interest.rmi-iiop
    To: Hari Rajapakshe <[email protected]>
    Sent: Wednesday, July 26, 2000 4:38 AM
    Subject: Re: problem using CORBA clients with RMI/EJBservers..!!!???
    Please see the post on june 26, re Errors compiling... somewherein
    there,
    I suspect, you are referring to the rmi class file when you are
    obliged
    to
    completely segregate these from the idl class files.
    Hari Rajapakshe wrote:
    Hi,
    I have a question on using EJB / or RMI servers with CORBA
    clients
    using
    RMI-IIOP transport, which in theory should work, but in practice
    has
    few
    glitches.
    Basically, I have implemented a very simple server,
    StockTreader,
    which
    looks up for a symbol and returns a 'Stock' object. In the firstexample, I
    simplified the 'Stock' object to be a mere java.lang.String, so
    that
    lookup
    would simply return the 'synbol'.
    Then I have implemented the above, as an RMI-IIOP server (case
    1)
    and a
    CORBA server (case 2) with respective clients, and the pair of
    client-servers work fine as long as they are CORBA-to-CORBA andRMI-to-RMI.
    But the problem arises when I tried using the RMI server (via
    IIOP)
    with
    the
    CORBA client, when the client tries to narrow the object ref
    obtained
    from
    the naming service into the CORBA idl defined type (StockTrader)
    it
    ends
    up
    with a class cast exception.
    This is what I did to achieve the above results:
    [1] Define an RMI interface StockTrader.java (extending
    java.rmi.Remote)
    with the method,
    public String lookup( String symbol) throws RMIException;
    [2] Implement the StorckTrader interface (on a
    PortableRemoteObject
    derived
    class, to make it IIOP compliant), and then the server to
    register
    the
    stock
    trader with COS Naming service as follows:
    String homeName =....
    StockTraderImpl trader =new StockTraderImpl();
    System.out.println("binding obj <" homeName ">...");
    java.util.Hashtable ht =new java.util.Hashtable();
    ht.put("java.naming.factory.initial", args[2]);
    ht.put("java.naming.provider.url", args[3]);
    Context ctx =new InitialContext(ht);
    ctx.rebind(homeName, trader);
    [3] Generate the RMI-IIOP skeletons for the Implementation
    class,
    rmic -iiop stock.StockTraderImpl
    [4] generate the IDL for the RMI interface,
    rmic -idl stock.StockTraderImpl
    [5] Generate IDL stubs for the CORBA client,
    idlj -v -fclient -emitAll StockTraderImpl.idl
    [6] Write the client to use the IDL-defined stock trader,
    String serverName =args[0];
    String symList =args[1];
    StockClient client =new StockClient();
    System.out.println("init orb...");
    ORB orb =ORB.init(args, null);
    System.out.println("resolve init name service...");
    org.omg.CORBA.Object objRef
    =orb.resolve_initial_references("NameService");
    NamingContext naming=NamingContextHelper.narrow(objRef);
    ... define a naming component etc...
    org.omg.CORBA.Object obj =naming.resolve(...);
    System.out.println("narrow objRef: " obj.getClass() ":"
    +obj);
    StockTrader trader =StockTraderHelper.narrow(obj);
    [7] Compile all the classes using Java 1.2.2
    [8] start tnameserv (naming service), then the server to
    register
    the
    RMI
    server obj
    [9] Run the CORBA client, passing it the COSNaming service ref
    name
    (with
    which the server obj is registered)
    The CORBA client successfully finds the server obj ref in the
    naming
    service, the operation StockTraderHelper.narrow() fails in thesegment
    below, with a class cast exception:
    org.omg.CORBA.Object obj =naming.resolve(...);
    StockTrader trader =StockTraderHelper.narrow(obj);
    The <obj> returned by naming service turns out to be of the
    type;
    class com.sun.rmi.iiop.CDRInputStream$1
    This is of the same type when stock trader object is registeredin a
    CORBA
    server (as opposed to an RMI server), but works correctly with
    no
    casting
    excpetions..
    Any ideas / hints very welcome.
    thanks in advance,
    -hari

  • Help on running asynchronous RMI over a cluster

    I'm working in an asynchronous RMI interface over the Sun's RMI for cluster computing and I'm having some problems on the distribution and running of the applications slaves. Well, I'd like to know if somebody knows any efficient way of deploying these application over cluster's machines (I made some pearl scripts and they are not completely solving my requirements).

    Clustered computing (also referred to via the grid or utility computing buzzwords) is something I have been working on steadily for quite some time. I have developed a simple framework that has now become so powerful, in my opinion, that I decided to make it free. I want to see if others felt the same way, and also to be sure no that company could patent it. Also, as with any framework, the more people use it, the more useful it becomes.
    If you want to create a pool of Virtual Machines, ready to dynamically jump in to solve, or manage, complex problem domains, this framework can do it for you.
    If you want to design applications which can scale from one, to any number of Virtual Machines, with no source changes, again, this framework can do it for you.It it as good as I say? I urge you to see for yourself.
    You can find it all at:
    https://cajo.dev.java.net/index.html
    Happy clustering,
    John

  • "DEADLOCK" when showing dialog from RMI-callback.

    Hi!
    Today is the 10th day (full time) that I've been searching for a solution in Java Forums and Internet, but I couldn't find anything that helps me. Help is extremely appreciated, otherwise I'll go crazy! :-)
    The problem is that RMI-callback thread "somehow blocks" the Event Dispatch Thread.
    I want to do following:
    1) I push the button in the client (btDoSomething)
    (MOUSE_RELEASED,(39,14),button=1,modifiers=Button1,clickCount=1 is automatically pushed onto EventQueue)
    2) btDoSomethingActionPerformed is invoked
    3) inside of it I make a call to RMI-server (server.doSomething())
    4) from this server method I invoke RMI-callback back to the client (client.askUser())
    5) in the callback I want to display a question to the user (JOptionPane.showConfirmDialog)
    6) user should answers the question
    7) callback returns to server
    8) client call to the server returns
    9) btDoSomethingActionPerformed returns and everybody is happy :-)
    This works normally in normal Client, that means, while a button is pushed, you can show Dialogs, but with RMI callback I get problems.
    I just made a small client-server sample to simulate real project. What I want to achieve is that client invokes server method, server method does something, but if server method doesn't have enough information to make the decision it needs to do call back to the client and wait for input, so the user gets an JOptionPane.
    Here is my callback method:
        /** this is the remote callback method, which is invoked from the sevrer */
        public synchronized String askUser() throws java.rmi.RemoteException {
            System.out.println("askUser() thread group: " + Thread.currentThread().getThreadGroup());
            System.out.println("callback started...");
            try {
                SwingUtilities.invokeLater(new Runnable() {
                    public void run() {
                        System.out.println("My event started...");
                        JOptionPane.showConfirmDialog(parentFrame, "Are you OK?", "Question", JOptionPane.YES_NO_OPTION);
                        System.out.println("My event finished.");
            }catch (Exception e) {
                e.printStackTrace();
            try {
                Thread.currentThread().sleep(10000);
            }catch (Exception e) {
                e.printStackTrace();
            System.out.println("callback finished.");
            return "Yo!"; // just return anything
        }Here in this sample I let the callback thread sleep for 10 seconds, but in real project I let it sleep infinitely and I want to wake it up after the user has answered JOptionPane. But I have the DEADLOCK, because event queue is waiting for callback to finish and doesn't schedule the "showing dialog" event which contains the command for waking up the callback thread.
    I looked very precisely when the event queue starts again to process events: it is precisely then when btDoSomethingActionPerformed is finished.
    When I'm not accessing GUI inside of the callback, this callback mechanism works perfectly, but as soon as I want to show the dialog from inside of the RMI-callback method, the "AWT Event Dispatch Queue" is somehow frozen until RMI-callback thread is finished (and in turn btDoSomethingActionPerformed terminates) . I cannot explain this weird behaviour!!!
    If I don't use SwingUtilities.invokeLater (I know this shoudn't be done outside of Event Dispatch Thread), but access the GUI directy, my JOptionPane is shown, but is not painted (it is blank gray) until callback thread returns.
    Why showing (or painting) of dialog is not done until btDoSomethingActionPerformed is finished?
    I also tried to spawn a new Thread inside of main RMI-callback thread, but nothing changed.
    I also tried the workaround from some older posting to use myInvokeLater:
        private final static ThreadGroup _applicationThreadGroup = Thread.currentThread().getThreadGroup();
        public void myInvokeLater(final Runnable code) {
            (new Thread(_applicationThreadGroup, new Runnable() {
                public void run() { SwingUtilities.invokeLater(code); }
            ).start();
        }but this didn't help either.
    Then I tried to spawn a new Thread directly from the Client's constructor, so that I'm sure that it belongs to the main appplication thread group. I even started that thread there in the constructor and made it wait for the callback. When callback came in, it would wake up that sleeping thread which should then show the dialog. But this did't help either.
    Now I think that it is IMPOSSIBLE to solve this problem this way.
    Spawning a new Process could work I think, but I'm not really sure if I want do to that.
    I know I could make a solution where server method is invoked and if some information is missing I can raise custom exception, provide the input on client side and call the same server mathod again with this additional data, but for that I need to change server RMI interfaces, etc... to fit in this concept. I thought callback would much easier, but after almost 10 days of trying the callback...I almost regreted it :-(
    Is anyone able to help?
    Thank you very much!
    Please scroll down for the complete sample (with build and run batch files), in case someone wants to try it. Or for the time being for your convenience you can download the whole sample from
    http://www.onlineloop.com/~tornado/download/rmi_callback_blocks_gui.zip
    ######### BEGIN CODE ####################################
    package callbackdialog;
    public interface ICallback extends java.rmi.Remote {
        public String askUser() throws java.rmi.RemoteException;
    package callbackdialog;
    public interface IServer extends java.rmi.Remote {
        public void doSomething() throws java.rmi.RemoteException;
    package callbackdialog;
    import java.rmi.Naming;
    public class Server {
        public Server() {
            try {
                IServer s = new ServerImpl();
                Naming.rebind("rmi://localhost:1099/ServerService", s);
            } catch (Exception e) {
                System.out.println("Trouble: " + e);
        public static void main(String args[]) {
            new Server();
    package callbackdialog;
    import java.rmi.Naming;
    public class ServerImpl extends java.rmi.server.UnicastRemoteObject implements IServer {
        // Implementations must have an explicit constructor
        // in order to declare the RemoteException exception
        public ServerImpl() throws java.rmi.RemoteException {
            super();
        public void doSomething() throws java.rmi.RemoteException {
            System.out.println("doSomething started...");
            try {
                // ask the client for the "missing" value via RMI callback
                ICallback client = (ICallback)Naming.lookup("rmi://localhost/ICallback");
                String clientValue = client.askUser();
                System.out.println("Got value from callback: " + clientValue);
            }catch (Exception e) {
                e.printStackTrace();
            System.out.println("doSomething finished.");
    package callbackdialog;
    import java.rmi.server.RemoteStub;
    import java.rmi.server.UnicastRemoteObject;
    import java.rmi.registry.Registry;
    import java.rmi.registry.LocateRegistry;
    import java.rmi.Naming;
    import javax.swing.JOptionPane;
    import javax.swing.SwingUtilities;
    import javax.swing.JFrame;
    public class Client extends javax.swing.JFrame implements ICallback {
        private final JFrame parentFrame = this;
        private Registry mRegistry = null;
        private RemoteStub remoteStub = null;
        private IServer server = null;
        private final static ThreadGroup _applicationThreadGroup = Thread.currentThread().getThreadGroup();
        /** Creates new form Client */
        public Client() {
            initComponents();
            System.out.println("Client constructor thread group: " + Thread.currentThread().getThreadGroup());
            try {
                server = (IServer)Naming.lookup("rmi://localhost/ServerService");
                // register client to the registry, so the server can invoke callback on it
                mRegistry = LocateRegistry.getRegistry("localhost", 1099);
                remoteStub = (RemoteStub)UnicastRemoteObject.exportObject((ICallback)this);
                Registry mRegistry = LocateRegistry.getRegistry("localhost", 1099);
                mRegistry.bind("ICallback", remoteStub);
            }catch (java.rmi.AlreadyBoundException e) {
                try {
                    mRegistry.unbind("ICallback");
                    mRegistry.bind("ICallback", remoteStub);
                }catch (Exception ex) {
                    // ignore it
            }catch (Exception e) {
                e.printStackTrace();
        /** This method is called from within the constructor to
         * initialize the form.
         * WARNING: Do NOT modify this code. The content of this method is
         * always regenerated by the Form Editor.
        private void initComponents() {
            java.awt.GridBagConstraints gridBagConstraints;
            secondTestPanel = new javax.swing.JPanel();
            btDoSomething = new javax.swing.JButton();
            getContentPane().setLayout(new java.awt.GridBagLayout());
            setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
            setTitle("RMI-Callback-GUI-problem sample");
            addWindowListener(new java.awt.event.WindowAdapter() {
                public void windowClosing(java.awt.event.WindowEvent evt) {
                    formWindowClosing(evt);
            secondTestPanel.setLayout(new java.awt.GridBagLayout());
            btDoSomething.setText("show dialog");
            btDoSomething.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    btDoSomethingActionPerformed(evt);
            gridBagConstraints = new java.awt.GridBagConstraints();
            gridBagConstraints.gridx = 0;
            gridBagConstraints.gridy = 3;
            gridBagConstraints.insets = new java.awt.Insets(10, 0, 0, 0);
            secondTestPanel.add(btDoSomething, gridBagConstraints);
            gridBagConstraints = new java.awt.GridBagConstraints();
            gridBagConstraints.gridx = 0;
            gridBagConstraints.gridy = 1;
            gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
            gridBagConstraints.weightx = 1.0;
            gridBagConstraints.weighty = 1.0;
            getContentPane().add(secondTestPanel, gridBagConstraints);
            pack();
        private void btDoSomethingActionPerformed(java.awt.event.ActionEvent evt) {                                             
            System.out.println(java.awt.EventQueue.getCurrentEvent().paramString());
            try {
                server.doSomething(); // invoke server RMI method, which will do the client RMI-Callback
                                      // in order to show the dialog
            }catch (Exception e) {
                e.printStackTrace();
        private void formWindowClosing(java.awt.event.WindowEvent evt) {                                  
            try {
                mRegistry.unbind("ICallback");
            }catch (Exception e) {
                e.printStackTrace();
            setVisible(false);
            dispose();
            System.exit(0);
        /** this is the remote callback method, which is invoked from the sevrer */
        public synchronized String askUser() throws java.rmi.RemoteException {
            System.out.println("askUser() thread group: " + Thread.currentThread().getThreadGroup());
            System.out.println("callback started...");
            try {
                SwingUtilities.invokeLater(new Runnable() {
                    public void run() {
                        System.out.println("My event started...");
                        JOptionPane.showConfirmDialog(parentFrame, "Are you OK?", "Question", JOptionPane.YES_NO_OPTION);
                        System.out.println("My event finished.");
            }catch (Exception e) {
                e.printStackTrace();
            try {
                Thread.currentThread().sleep(10000);
            }catch (Exception e) {
                e.printStackTrace();
            System.out.println("callback finished.");
            return "Yo!"; // just return anything
         * @param args the command line arguments
        public static void main(String args[]) {
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                    Client client = new Client();
                    client.setSize(500,300);
                    client.setVisible(true);
        // Variables declaration - do not modify
        private javax.swing.JButton btDoSomething;
        private javax.swing.JPanel secondTestPanel;
        // End of variables declaration
    1_build.bat
    javac -cp . -d . *.java
    rmic callbackdialog.ServerImpl
    rmic callbackdialog.Client
    pause
    2_RunRmiRegistry.bat
    rmiregistry
    pause
    3_RunServer.bat
    rem java -classpath .\ Server
    java callbackdialog.Server
    pause
    4_RunClient.bat
    java callbackdialog.Client
    pause
    ######### END CODE ####################################

    I can understand that only partially, because SwingUtilities.invokeLater puts(redirects) my runnable object directly into AWT thread. The only conclusion I can draw from all things that I have tried until now , is that SwingUtilities.invokeLater(<showing the dialog>) invoked from a RMI thread somehow have lower "priority" than events coming directly from the AWT-thread and therefore it is held back until normal awt event completes (in this case BUTTON_RELEASED).
    But what I don't understand is the fact that the dialog is not shown even If I create and start a new thread from the client's constructor. This thread has nothing to do with RMI as it is in the main thread group:
        private BlockingObject dialogBlocker = new BlockingObject();
        private BlockingObject blocker = new BlockingObject();
        public Client() {
            initComponents();
            (new Thread() {
                public void run() {
                    try {
                        dialogBlocker.sleep(0);
                        System.out.println("My event started...");
                        JOptionPane.showConfirmDialog(parentFrame, "Are you OK?", "Question", JOptionPane.YES_NO_OPTION);
                        blocker.wake();
                        System.out.println("My event finished.");
                    }catch (Exception e) {
                        e.printStackTrace();
            }).start();
            ...Callback is then only used to wake up this thread which should display the dialog:
        public Object askUser() throws java.rmi.RemoteException {
            System.out.println("callback started...");
            dialogBlocker.wake();
            blocker.sleep(0);
            System.out.println("callback finished.");
            return userChoice; // return anything I don't care for now
    class BlockingObject {
        public void sleep(long timeout) {
            synchronized(this){
                try {
                    wait(timeout);
                }catch (InterruptedException e) {}
        public void wake() {
            synchronized(this){
                notifyAll();
        }In this case the dialog is shown, but it is NOT painted, so I have deadlock again. Why it is not painted?!?
    Haven't I uncouple it from RMI-Thread?
    But perhaps I'm looking at the wrong side of the whole thing.
    If I invoke server.doSomething (as ejp proposed) in a separate thread, then everything is fine (except that I cannot use this solution in my project :-( ).
    It seems that the whole problem is NOT AT ALL related to callback itself, but rather to the fact that if client invokes remote call, even dialogs can't be shown until the rmi call returns to the client.
    Thank you, Drindilica

  • How local interfaces work in EJBs

    How exactly local interfaces work in EJBs and how should I use them ?
    Thank you.

    They are simply non-RMI interface implementations that directly delgate to the EJB's implementation. They are called and in turn call the EJB just as you would call any normal class.
    As such, there is no RMI or serialization overhead and the interfaces can include methods that update their arguments, something not possible in remote interfaces.
    Generally speaking, you should define local interfaces for all entities as one seldom if ever would access entities remotely. You might even consider defining ONLY local interfaces for entities, but that is a tougher call.
    You would define local interfaces for session EJB's that are invoked by other session EJB's within the same container. I would normally always define both local and remote interfaces unless there is some reason why I can eliminate one or the other.
    Chuck

  • RMI with JMF - Pls help

    Hi all,
    I am trying to develop some program to allow user to activate video recording over the network. The basic idea of what I am doing is this: I have implement a Object to handle recording from a web cam. The recording work fine on a single JVM. The code follows
    // Get the processor's output, create a DataSink and connect the two.
    DataSource outputDS = processor.getDataOutput();
    try {
    MediaLocator m2 = new MediaLocator("file://c:"+fileName+"." +"avi");
    datasink = Manager.createDataSink(outputDS, m2);
    datasink.open();
    datasink.start();
    In order to achieve the remote invocation of the method, I expose the method as an RMI interface. However an exception : java.lang.RuntimeException: No permission to write files from applets is thrown when the program attempts to execute datasink.open().
    The policy file that was use is as follows
    grant {
    permission java.security.AllPermission;
    Any advise is appreciated. Thanks in advance
    Regards
    Sze Kong

    In the Sun Java control panel, in the runtime parameters box, type
    -Djava.security.policy=c:\mypolicy.policy
    where c:\mypolicy.policy is the policy file you are using.
    Warning : your setting of
    grant { permission java.security.AllPermission; };
    will allow all applets, even ones from the Internet, full access to your machine.
    At least put machine specific permissions in.
    regards,
    Owen

  • RMI: constructing the server side class (Compute Engine)

    I took the Sun RMI tutorial, which was very beneficial. However the understanding now of the RMI interface
    from the tutorial has me to come with two new questions. When building your ComputeEngine class (inheriting from Compute which inherits from Remote) do you need to encapsulate the static main function inside ? If not how does
    the ComputeEngine process continue without a run function ?
    Let say on of the overriding functions in ComputeEngine is:
    void doThis(Task t) throws IOExcpetion() {
    MyTask mytask = (MyTask) t;
    t.execute();
    MyTask is a subclass of Task that has been already preinstalled. When the remote client calls the doThis function
    how does mytask get the de-serialized data from the client ? Does this function need to do anything to retreive the serialized data ? Also when t.execute is implemented has the Task thread started already ? Do I have to call t.start() ? And how does the execute function survive without being in the run function ?
    Thanks Michael

    do you need to encapsulate the static main function inside ? If not how does
    the ComputeEngine process continue without a run function ?The main() function can be anywhere in your application.
    Does this function need to do anything to retreive the serialized data ?No. It just arrives in the method as a parameter.
    Also when t.execute is implemented has the Task thread started already?Probably not. It's in whatever state it is in when it's deserialized.
    Do I have to call t.start() ?See above.
    And how does the execute function survive without being in the run function ?I can't answer the question without knowing anything about the Task class you are using.

  • Interface problem!! PLZZZZ help!

    Hi,
    dis problem is probably gna make me look really stupid but i jus cnt seem to work it out. Basically, im tryin to implement my system to use rmi. I wrote my rmi interface class, and compiled it. No problem. Then i wrote my rmi server class which implements the interface. But when i try to compile the server, i get an error sayin "cannot resolve symbol" which is refering to my interface. Im totally clueless as to why this is happening. PLZZZZZZZ could some1 gimme some input.
    The interface is called GamesDB.java. The server class is GamesDBImpl.java. The error occurs on this line in my server class:
    public class GamesDBImpl extends UnicastRemoteObject implements GamesDB
    sayin that it cannot resolve the symbol GamesDB. Please help!! Thanks in advance!!

    Isn't there an issue (or more correctly something
    fixed) in the new 1.4 that means classes in the same
    package are no longer found without explicitly
    importing them?
    Barring that, is the interface in another package, in
    which case it definitely needs to be imported?
    Does your interface extend Remote?
    Is your classpath set up correctly?
    Just some quick thoughts.Have never used 1.4 yet but if apparently that seems to be the only problem. Try using import statement.

  • RMI totally broken on Websphere & AS/400

    I am trying to bind an object to a port using
    Websphere on the IBM AS/400 and it totally
    does not work. I developed on Win2K and
    it works fine, an exception
    ### ----------> Error initializing RMI interface.
    Exception Server RemoteException; nested exception is:
         java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is:
         java.lang.ClassNotFoundException: com.tamgroup.nexus.e2e.framework.NexusE2EServer_Stub
    I know that object is in the classpath, because it is in the jar and the jar works on Win2K.
    I think the problem may be the configuration of Websphere.
    Any ideas on configuring Websphere to enable RMI?
    Thanks
    -Steve

    Okay, I know it's 4 years later and it did not take me 4 years to figure out what the problem was (OMG) but I thought I'd post what I figured out.
    It turns out that the two java programs that were trying to communicate (via RMI) were running on different JRE versions. Now, I know that RMI is SUPPOSED to work between JRE versions, and it seems to on Windows but it does not on the AS/400. We got the program we were trying to communicate with going on the same JRE version and everything has been working fine for years!

Maybe you are looking for

  • Problem in converting smartform to PDF

    Hi Experts, I am facing the issue while converting the smartform to pdf form with the help of FM convert_otf_2_pdf . Problem is that CH3OH4OD7     3 , 4 and 7 are the subscipts in SMARTFORM like in a chemical formula ,but after conveting to PDF # is

  • White screen bug on preview app (iMac 5k)

    i have a problem with the preview app on a iMac 5K. When I try to open a picture taken with my Nikon D800 (36 Mpixels) for an half a second I can see the picture and after that time the window became white. The problem is solved if I try to open anot

  • IPOD Videos - Adding videos without wiping out all data

    I am sure a few of you have run into this problem. Your computer hard drive is too small to hold all the music and videos to fill up your IPOD. I have run out of space. How can I continue to load videos from this point on without deleting any of the

  • Can´t find faulty Power Source replacement via Apple Website.

    I can´t underestand this. My iMac G5 20" (RevB) has issues because the power source doesn´t work properly (now not at all). I follow the 'step by step' indications in Apple´s pages that makes me reach that diagnostic (internal diagnostic LED examinat

  • FlexBuilder3 Eclipse Plugin - Plans to support Eclipse 3.5?

    Are there any plans to support the FlexBuilder3 Plugin for Eclipse version 3.5? If so, is there any ETA? Thanks!