RMI How can a Client reconnect to a server after connection(any)-error

I have the following problem:
My RMI-Server runs for ever. In a batch-queue I have a procedure which looks periodly wether rmiregistry
and RMI-Server exists. On error both processes are killed and restarted.
My client as a simple example is displaying the server time. If any communication-problem with the
server exists, I need an automatic reconnect to the server. I accept that into the time distanz of the
error the display is frozen. Its unacceptable to restart the client !!.
The following example demonstates my test-example:
Server:
1. Start
2. waits for connecting (factory)
3. answer time-requests
Client:
1. Start
2. create a time class initially 1.jan.1970 00:00:00
3. Start a timer displaying the time class every second
4. start a timer connecting/reconnecting to the server and ask the servers actual time every second
PS. Is the server to stubil programmed, so that a hang can exists?
It would be nice, if anybody could answer me !!
The following sources work correctly without solving the problem of the reconnect:
////////////// Echo.java
package emi.server;
import java.rmi.*;
import java.util.*;
public interface Echo
extends Remote
public Date getTime() throws RemoteException;
////////////// EchoClient.java
package emi.server;
//import emi.utility.basics.*;
public class EchoClient
public static void main(String args[]) throws Exception
EchoClient echoclient1 = new EchoClient();
//Check the argument count
if (args.length != 1)
System.err.println("Usage: EchoClient <server> --> EXIT");
System.exit(0);
// all of time relevant things
Etim acttim = new Etim();
// displaying continous the time
EchoClientDisplay disp = new EchoClientDisplay(acttim);
disp.StartTimer();
// transfering continous the time from the server
EchoClientTransfer trans = new EchoClientTransfer(acttim, args[0]);
trans.StartTimer();
////////////// EchoClientDisplay.java
package emi.server;
import java.awt.event.*;
import javax.swing.*;
// displaying every 750 Milliseconds the value of the time
public class EchoClientDisplay implements ActionListener
private Timer tim;
private Etim tact;
public EchoClientDisplay(Etim tact)
tim = new Timer(750, this);
this.tact = tact;
public void StartTimer()
tim.setRepeats(true);
tim.setInitialDelay(5);
tim.start();
public void actionPerformed(ActionEvent e )
System.out.println(tact.toString());
////////////// EchoClientTransfer.java
package emi.server;
import java.rmi.Naming;
import java.rmi.RMISecurityManager;
import java.awt.event.*;
import javax.swing.Timer;
import java.util.Date;
// transferring the actual time from the server
public class EchoClientTransfer implements ActionListener
private Etim tact;
private String hostname;
private Timer tim;
private boolean init = false;
private Echo echoRef1 = null;
public EchoClientTransfer(Etim tact, String hostname)
this.tact = tact;
this.hostname = hostname;
this.tim = new Timer(500, this);
public void StartTimer()
tim.setRepeats(true);
tim.setInitialDelay(5);
tim.start();
public void actionPerformed(ActionEvent e )
//>>>>>>>>>>> this construction doesnt work correctly, its only good until the first
// network error
try
if( init == false )
// Create and install the security manager
System.setSecurityManager(new RMISecurityManager());
//get the remote factory object from the registry
String url = new String("rmi://"+ hostname +"/EchoFactory");
EchoFactory remoteFactory = (EchoFactory)Naming.lookup(url);
//get references to new EchoImpl instances
echoRef1 = remoteFactory.getEcho("User Meyer");
init = true;
if( init = true )
//make the remote calls
Date d = echoRef1.getTime();
tact.setDate(d);
catch(Exception ee)
System.out.println(ee.toString());
init = false;
//<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
////////////// EchoFactory.java
package emi.server;
import java.rmi.RemoteException;
import java.rmi.Remote;
public interface EchoFactory extends Remote
Echo getEcho(String userName) throws RemoteException;
////////////// EchoFactoryImpl.java
package emi.server;
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
public class EchoFactoryImpl extends UnicastRemoteObject implements EchoFactory
EchoFactoryImpl() throws RemoteException {};
public Echo getEcho(String userName) throws RemoteException
EchoImpl echoRef = new EchoImpl(userName);
return (Echo)echoRef;
////////////// EchoImpl.java
package emi.server;
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
import java.util.*;
public class EchoImpl extends UnicastRemoteObject implements Echo
private String userName;
public EchoImpl() throws RemoteException
public EchoImpl(String userName) throws RemoteException
this.userName = userName;
public Date getTime()
Etim e = new Etim();
e.setTimeAct();
return e.get();
////////////// EchoServer.java
package emi.server;
import java.rmi.Naming;
import java.rmi.RMISecurityManager;
public class EchoServer
public static void main(String args[]) throws Exception
// Create and install the security manager
System.setSecurityManager(new RMISecurityManager());
// Create the servant instance for registration
EchoFactory factoryRef = new EchoFactoryImpl();
// Bind the object to the rmiregistry
Naming.rebind("EchoFactory", factoryRef);
System.out.println("Echo object ready and bound to the name 'EchoFactory'!");
////////////// Etim.java
package emi.server;
import java.util.*;
import java.text.*;
// this is my central class working up all time problems .. many hundred lines of code
// I think, you must not look at this code ist setting and reading time
// this is only a subset of methods for this example
public class Etim
private Date dat;
private Calendar cal;
public Etim()
cal = Calendar.getInstance(); // Gregorianischer Kalender
dat = new Date(0L); // January 1, 1970, 00:00:00
cal.clear();
* Zeit lesen.
public Date get()
return dat;
// setting the time
public void setDate( Date d )
dat.setTime( d.getTime() );
cal.setTime(dat);
// gets my time-class to the current system-clock
public void setTimeAct()
long millis;
millis = System.currentTimeMillis();
setMilli(millis);
* Zeit setzen.
public void setMilli(long millis)
dat.setTime(millis);
cal.setTime(dat);
// time in german format: day.month.year hour:minute:second:millisecond
public String toString()
return toStringTagMoJahr() + " " + toStringStdMiSek() +
":" + cal.get(Calendar.MILLISECOND);
* Ausgabeformat Tag.Monat.Jahr (z.B. 01.01.2001).
public String toStringTagMoJahr()
SimpleDateFormat s = new SimpleDateFormat("dd.MM.yyyy");
return s.format(dat);
* Ausgabeformat Stunde:Minute:Sekunde (00:00:00 - 23:59:59).
public String toStringStdMiSek()
SimpleDateFormat s = new SimpleDateFormat("HH:mm:ss");
return s.format(dat);

Hello willy51,
Thank you for answering.
I think, your comment of the design is true - its a problem when starting up in a new enviroment and
you have nobody who shows you the right direction at the beginning. Talking personally together only
10 minutes is better than writing a noval.
I thing the following model of a client works better:
concept:
- visualize a personal time class continously evgery second
- if there is a connection to a server set the time-class with the server time
- if you loss connection, try to reconnect
question:
in which situation hangs connectToServer() ?
(whithout the simple errors : no rmiregistry, no rmi-server)
public class EchoClient
private String hostname;
public static void main(String args[]) throws Exception
// my internal TIME-Class
Etim acttim = new Etim();
// Create and install the security manager
System.setSecurityManager(new RMISecurityManager());
// remote call
Echo echoRef1 = null;
String url = new String("rmi://"+ servername:port +"/EchoFactory");
// displaying continous the time, technic = swing.timer
EchoClientDisplay disp = new EchoClientDisplay(acttim);
disp.StartTimer();
// transfering continous the time from the server, technic = swing.timer
// The state of transfer from server = offline
EchoClientTransfer trans = new EchoClientTransfer(acttim);
trans.StartTimer();
// Connect to server
connectToServer(url, echoRef1, trans);
// wait for ever, if connection failed, try every 5 seconds a reconnect to server
while(true)
// test, if connection failed. The connections fails if the Object EchoClientTransfer
// get a error, when it asks the server for the time ( remote call )
if(trans.getStatus() == false ) // test, if connection failed
connectToServer(url, echoRef1, trans);
// try it again after 5 seconds
Thread.sleep(5000);
private static void connectToServer(String url, Echo echoRef1, EchoClientTransfer trans)
System.out.println("Retry connection");
// Connect to server
while( true )
try
//get the remote factory object from the registry
EchoFactory remoteFactory = (EchoFactory)Naming.lookup(url);
//get references to new EchoImpl instances
echoRef1 = remoteFactory.getEcho("User Meyer");
// reactivate Datatransfer because I have now a new connection to the server
trans.reactivateAfterConnectionError(echoRef1);
// end of initialisation
break;
catch( Exception e )
//>>>>>>> Error initialising connection to server. try again after 5 seconds"
Thread.sleep(5000); // retry after 5 seconds

Similar Messages

  • How can I prevent my iPhone4 from starting after connecting to Power?

    How can I prevent my iPhone4 from starting (booting) after connecting to Power?

    You can't so far as I know. You can however, shut it down after it's connected to power and it should not power back on as long as it's connected. If the power is disconnected/reconnected, it will power back on.
    If you just want to avoid calls, etc. while it's plugged in, you could just put it in airplane mode.

  • How can I remove the first exchange server 2010 without any problems in DC

    Hi,
    our actually exchange is running on windows server 2008R2 with exchange 2010. I already install & configured a second Exchange 2010 server in the same domain. I also moved every mailbox to the new server. Now I have to deactivate the first server and
    I don't know, if I have to do something or can I deactivate the "old" server without any issues.
    If I can deactivate it, how can I do this? Is it enough to uninstall exchange 2010 on the server and after that I uninstall the windows server? Did I have to change something before?
    Thanks,
    Mesut Uygun
    btw. sorry for my bad english

    Hi MesutU,
    When you remove first Exchange Server 2010 in your organization, please confirm finish following steps:
    1. Move all mailboxes (including discovery and arbitration) to another server
    2. Move all Public Folder replicas
    3. Move OAB generation server
    4. Update SMTP flow from internet
    5. Update OWA/IMAP/POP/OA access from internet.
    6. Update any routing group connectors if 2003 is present
    7. Turn the old server offline for some days to check whether the new server works well.
    More information about How to Remove the First Exchange 2007 Server in a Coexistence Scenario (even if the version of Exchange server is different), for your conference:
    http://technet.microsoft.com/en-us/library/bb310767(v=exchg.80).aspx
    Best Regards,
    Allen Wang

  • I am using ios 4.2 gm how can i upgrade to ios 4.3.3 without any error?, i am using ios 4.2 gm how can i upgrade to ios 4.3.3 without any error?

    i am using ios 4.2 8c134, i can't upgrade to any ios.. but ios 5.xx above i not try yet.. any suggestion or ideas to make sure the upgrade will work?
    sorry for my bad english.. 

    It is not possible to update the iOS to any version besides the most recent version. You can only update to iOS 5.1 at the time.
    Start iTunes on your computer and use its menu to check for updates. If there is an update download and install the latest version of iTunes for your computer. Then restart your computer and start iTunes. Connect your iPad to your computer and in iTunes on your computer select your iPad in the left column. In the right column select General and click on Check for Updates. Follow the prompts to complete the update process.
    The iOS update is a large file. A good Internet connection is required. Many users have discovered that they need to turn off virus protection and their firewall to get the update to proceed to completion. If you have problems updating turn off these items and try again

  • How can i get my computer to prompt after connecting my digital camera. I use windows vista premium

    Medium
    This question was solved.
    View Solution.

    Let's try it this way.
    While in Control Panel in the top right hand corner should be a search box.
    In the search box type "Auto Play" and then the options you are presented with should include "Change default setting for media or devices"
    If I have helped you in any way click the Kudos button to say Thanks.
    The community works together, click Accept as Solution on the post that solves your issue for other members of the community to benefit from the solution.
    - Friendship is magical.

  • How can a client know the ip of the server?

    How can a client locate a rmi - server without
    have the ip of the server.
    Is there a methode that can check if there's a
    server in a L.a.n?

    We have used 2 different solutions.
    1. Our servers use UDP multicast and send out empty packets every second. The client listens on the multicast address:port, and once it sees a packet, it bootstraps the RMI object by contacting the registry on the server that sent the multicast.
    2. In another case we use JNLP/ Webstart to launch the client. With JNLP you can pass a parameter through to the app's System.properties via -D option on the command line using the jnlp property tag. If you change the ip address of the server you just update the *.jnlp file's particular <property> tag with the new value. The next time everyone launches the app, webstart will see that the *.jnlp has changed, will download the latest version of the jnlp file, decide it has all the correct jars etc, then launch the app with the new property value.
    This is a great way to centrally manage the configuration of multiple clients when the configuration is the same on all clients but might change over time.
    Bruce

  • How can the client know if the SSL certificate specified in the service-config.xml file is invalid/u

    Hi,
    How can the client know if the SSL certificate specified in the service-config.xml file is invalid/untrusted/expired? For example using iOS client, the trusted certificate will not work and the client has no way to know that the certificate is untrusted. Can the lcds server return any specific exceptions for SSL errors?
    Thanks,
    Swathi.

    We use a standard Java keystore and certificate validation can be handled as per standard best practices. At present we do not provide a hook point to validate the server certificate. However, you can register a bootstrap service which validates the certificate on system startup: http://help.adobe.com/en_US/dataservicesjee/4.6/Developing/WSc3ff6d0ea77859461172e0811f00f 6fe7f-7ffeUpdate.html This would require you to pass another copy of the keystore configuration to you Bootstrap service and then you can inspect the certificate in the keystore and validate it.

  • How can my client program call program located at server?

    Hi All,
    I have a client-server application. How can my client program call program located at server?
    At the beginning my program works as long as RSA Agentinstalled at client. So my program only call rsa library and communicate with RSA Agentby passing userid and passcode. Once RSA Agent receive it will send to RSA Managers to validate.
    But now my user want the RSA Agent installed in my Server. I wondering how to do that as the library given will only detect local RSA Agent. So I'm thinking to separte the library and create new project. Then in this project as a medium to pass userid and passcode. This project I will compile and allocate to server. Then my programs will call the new program i created by passing userid and passcode. I wondering can I do that?
    Thanks in advance.
    Regards,
    Azli

    Why not take the tutorial first? [http://java.sun.com/javaee/5/docs/tutorial/doc/JavaEETutorial.pdf]

  • How can a client lie about its IP address to the server (HTTP)

    I'm trying to set the user agent property to other than Java/1.4.2_02, and also send requests to the server that should appear coming from ip specified by me. In another words i am trying that I could hit the server with variety of different setting of user-agent and ip address. I have this piece of code that works fine for the user-agent. But how can I send request to the server mimicking different ip addresses. Any ideas?thanks
    I don't to download the page. I just have to send the requests.
    Here is the code that sends different user-agent configurations to the server:
    import java.io.BufferedReader;
    import java.io.IOException;
    import java.io.InputStreamReader;
    import java.net.HttpURLConnection;
    import java.net.MalformedURLException;
    import java.net.URL;
    import javax.swing.text.html.HTMLDocument;
    public class teste {
    private static HttpURLConnection conn = null;
    private static URL url = null;
    private static HTMLDocument html = new HTMLDocument();
    public static void main(String args[]) {
    BufferedReader in = null;
    String str = "";
    try {
    url = new URL("http://www.google.com/search?hl=de&ie=ISO-8859-1&q=test");
    } catch(MalformedURLException e) {
    System.out.println(e);
    System.exit(-1);
    try {
    conn = (HttpURLConnection) url.openConnection();
    conn.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows; U; Win98; en-US; rv:1.7.2) Gecko/20040803");
    conn.connect();
    in = new BufferedReader(new InputStreamReader(url.openStream()));
    } catch(IOException e) {
    System.out.println(e);
    System.exit(-1);
    }

    There is bad news, and their is worse news.
    You need raw sockets. Java doesn't do raw sockets.
    Windows doesn't eithier (XP SP2), though there ARE ways arround it, the problem is you will need to be administrator and it will be throttled (read SLOW) by the OS itself (no way arround this) and it will refuse to send Spoofed IPs (no sensible way arround this).
    Linux you need to be root.
    You need to write a JNI that will drop your requests onto the network.
    It's horrible, and you need to consider whether java is the right language for this. Sounds like you are just doing some NATting or proxying or such, which would be much easier to do in pure c. Unfortunately I have to have raw packets from java so pain and suffering for me.

  • How can i send a big file as pararameter of any method in a Web Service???

    Hello,
    i have a problem,,,,, i want to send a file of 2mb as parameter of a web service method.
    When i send this file as a vector of bytes i have the error out of memory...
    If the file is 200kb or smaller works fine....
    How can i send a big file as pararameter of any method in a Web Service???
    thanks in advance and excuse me for my bad english

    you can think about streams.
    in our case, what we did is, we will place a file in a common ftp server and return the url to the client.
    regards,
    mukunt

  • How can we update data in LDAP server using PL/SQL.

    Hi,
    How can we update data in LDAP server using PL/SQL program.
    Is there any sample code for refrence.
    Thanks,
    Tarun

    Hi Justin,
    Thanks for your help. You got my correct requirements.
    Tim's example returning all the attributes of current user which is admin user. Please correct me if I am wrong.
    I have the following information:
    the admin user and password,server info , port and ldap_base for admin.
    I have uid and password for regular user, I am trying find the ldap_base for regular user, which may be different from adminuser.
    Please help me.
    Thanks,
    Edited by: james. on Jan 12, 2009 5:39 PM

  • I have an Apple MacBook Pro with 2 USB ports and a MiniDisplay Port. I also have an HDTV with a HDMI port. How can I use the TV as a display without any tethering wires between my computer and the TV?

    I have an Apple MacBook Pro with 2 USB ports and a MiniDisplay Port. I also have an HDTV with a HDMI port. How can I use the TV as a display without any tethering wires between my computer and the TV? I have a MiniDisplay Port to VGA adapter, but there are two issues with it: The new display doesn't have a VGA port, and even if it did, I wouldn't want to have my mac constantly attached to the display by a cable. I was looking for a way to use the TV as a display without any wires. Is there some type of bluetooth setup I could use? Please let me know if you have any suggestions.

    As I wrote above, I think you should look into the Apple TV yourself. The best place to find information about what it can and can't do and to ask your own specific questions is probably in the Apple TV forum, here:
    https://discussions.apple.com/community/appletv/appletv

  • Hi,how can i transport objects from one server to other like (Dev To Qty)

    Hi Sir/madam,
       Can u explain how can i transport objects from one server to other like (Development To Quality To Production).
    Regards,
    Vishali.

    Hi Vishali,
    Step 1: Collect all Transports(with Packages) in Transports Tab(RSA1)- CTO
    Step 2: Release the subrequests first and then the main request by pressing Truck button
    Step 3: STMS or Customized transactions
    Object Collection In Transports:
    The respective Transports should have the following objects:
    1. Base Objects -
    a. Info Area
    b. Info object catalogs
    c. Info Objects
    2. Info Providers u2013
    a. Info Cubes
    b. Multi Providers
    c. Info Sets
    d. Data Store Objects
    e. Info Cube Aggregates
    3. Transfer Rules u2013
    a. Application Components
    b. Communication Structure
    c. Data Source replica
    d. Info Packages
    e. Transfer Rules
    f. Transformations
    g. Info Source Transaction data
    h. Transfer Structure
    i. Data sources (Active version)
    j. Routines & BW Formulas used in the Transfer routines
    k. Extract Structures
    l. (Note) If the transfer structures and related objects are being transferred without preceding
    Base Objects transport (e.g. while fixing an error) it is safer to transport the related Info
    Objects as well.
    4. Update Rules u2013
    a. Update rules
    b. Routines and formulas used in Update rules
    c. DTPs
    5. Process Chains u2013
    a. Process Chains
    b. Process Chain Starter
    c. Process Variants
    d. Event u2013 Administration Chains
    6. Report Objects u2013
    a. Reports
    b. Report Objects
    c. Web Templates
    Regards,
    Suman

  • How can I display images that are not included in any collection?

    How can I display images that are not included in any collection (some filter or smart collection)? A smart collection with parameters "Collection - contains - empty field" does not work. Lightroom 5.

    Thank you! Good idea! I ordered letters of the alphabet (space separated), and it works.

  • How can I find out the mail server from email address?

    Hi:
    How can I find out the mail server from email address?
    for example: If I know the email address is [email protected],
    how to find the pop3 and smtp mail server?
    THANK YOU

    You can't tell by the email address since you can pretty much put whatever you want in there (especially if the SMTP server is not filtering anything).
    The header may be able to tell you something. There is a Received header value which looks like it has the routing information although I am not sure if this is a complete trace or just the last hop the message took.
    Sean

Maybe you are looking for