Showing posts with label RMI. Show all posts
Showing posts with label RMI. Show all posts

Tuesday 13 August 2013

Top Most Can I pass a database connection using RMI


 We assume you mean: java.sql.Connection from java.sql.DriverManager.getConnection(). The answer is that you cannot. You cannot pass a reference to something other than a RemoteObject() with RMI, only copies, (serializable), of data.

 What you can pass are the data fields, (String, int, etc.), within the database after a Select.
So, in a GUI Client you can pass the parameters for a Select to the RMI Server. The Server can issue the SQL statements saving the fields in an object. The Server returns that object to the Client that displays the data.

Top Most Compare SOAP with RMI



 Soap (Simple Object Access Protocol) and RMI are entirely different technologies. RMI is Java-centric, whereas SOAP, which uses XML, is language independent. However there are some similarities. SOAP, like RMI, allows you to make an RPC on another machine over HTTP or SMTP. Soap works on the request/response model of making remote procedure calls. The client program forms a request which consists of a valid SOAP XML document and sends it over HTTP or SMTP to a server. The server picks up the SOAP request, parses and validates it, invokes the requested method with any supplied parameters, forms a valid SOAP XML response and sends it back over HTTP or SMTP. For a good paper comparing SOAP with RMI,

Top Most Is it possible for a client to send an event to an RMI object, and vice versa



Yes if your event extends EventObject which is serializable

Be sure to define non-serializable properties of your new event as transient (note that doing so you won't be able to send them thru RMI)

You can also include remote references in your event (ie references to UnicastRemoteObjects) 

Top Most Difference between JRMP (Java Remote Method Protocol) and RMI



 Java RMI is just a set of APIs and a model for remote objects for building distributed applications. The original version of RMI uses a combination of Java serialization and the Java Remote Method Protocol (JRMP) to turn local method invocations into remote method invocations.

 JRMP is one transport protocol that is used by RMI to transfer data across the network. Another example of a transport protocol used by RMI is IIOP (Internet Inter-ORB Protocol). 

Top Most What are smart proxies



 A smart proxy is a class, instantiated in the client VM, that holds onto a remote object reference. It implements the object's remote interface and typically forwards most of the calls on the interface to the remote object, just like an RMI stub. However, a smart proxy is more useful than the RMI stub in that you can change the behavior of the remote interface to do more than forward calls to the remote object. For instance, a smart proxy can locally cache state from the remote object to avoid the network overhead on every method call.

Top Most Can I send Data greater than 64K between an RMI Client and Server


Yes, that's true only with RMI systems prior to JDK 1.3, where you cannot serialize a string greater than 64k. You would have a java.io.UTFDataFormatException thrown if you tried. However, since the serialization protocol has been enhanced with JDK 1.3, you should now be able to serialize strings greater than 64K.

However, do keep mind that for this to work, both the client and server JVMs need to be JDK 1.3 compliant. Otherwise, if your, say, JDK 1.2-compliant RMI server tried to read serialized data greater than 64K sent by a JDK 1.3-compliant RMI client, the server would throw a java.io.StreamCorruptedException. 

Top Most Can I log the Client-side remote calls of an RMI Client



 Yes, with J2SE 1.4, you can now log client-side remote calls and exceptions of an RMI client by setting the system property sun.rmi.client.logCalls=truewhen starting up your client. You can also now control the granularity of the logging mechanism through additional properties.

Top Most Can I use Swing components within RMI



 Do you mean to pass Swing Components as parameters to remote objects using RMI? If so, you are probably out of luck as most if not all of them are not directly Serializable.

 For some Swing & AWT related classes, there are workarounds such as [implementations of] ListModel which can be "disconnected" from any reference to a JList and then passed to Remote objects. 

Top Most What is the meaning of Marshalling and UnMarshalling



 In few words, "marshalling" refers to the process of converting the data or the objects inbto a byte-stream, and "unmarshalling" is the reverse process of converting the byte-stream beack to their original data or object. The conversion is achieved through "serialization".

The purpose of the "marshalling/unmarshalling" process is to transfer data between the RMI system. 

Top Most How to return ResultSets VIA RMI back to the Client


I Have a server that access a database via JDBC, and want to return ResultSets VIA RMI back to the Client. I have read that this can't be done (But it can be got you could go through your ResultSet and Return a Vector). I would be grateful if somebody could give me an example of this. Better yet if there is some way of passing the ResultSet Back. I tried making the ResultSet serializable but that didn't work.

Answer 

Look, as far as I understand it, a resultset really doesn't make ANY sense once serialized out of the JVM it was created in.
You are right, going through your resultset and adding it to a Vector is a decent way of doing it. As in
Connection con;
Statement st;
ResultSet rs = st.executeQuery("query here");
Vector v = new Vector();
while(rs.next) {
    v.add(rs.getXXXXX);
} 
then close your resultset and serialize the vector.

Top Most java.rmi.UnmarshalException: error unmarshalling arguments


I made some changes to my remote interface and recompiled the server. Now, I am getting an :
"java.rmi.UnmarshalException: error unmarshalling arguments; " Why?

Answer 

You need to run rmic and recompile those stubs and skeletons every time you add/delete/modify a method within your remote interface.

StockMarketImpl Market = new StockMarketImpl( "NASDAQ");
java.rmi.RemoteException: java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is:

May be errors core in the settings of CLASSPATH?

Top Most How to improve RMI performance


Can I use compression to improve RMI performance when transferring large datasets between the client and server?

Answer 

Yes, you should be able to use the ZipInputStream and ZipOutputStream classes within a custom socket factory to give you a new socket type that transparently compresses data.
When you construct your ServerImpl, don't use the constructor that takes the port number, use the default constructor.
so use
      ServerImpl server = new ServerImpl();
      Registry r = LocateRegistry.createRegistry(1090);
      Naming.rebind("//localhost:1090/ZipServer",server);
NOT
      ServerImpl server = new ServerImpl(SOME_PORT);
      Registry r = LocateRegistry.createRegistry(1090);
      Naming.rebind("//localhost:1090/ZipServer",server);

Top Most What is PortableRemoteObject.narrow() method in Java


What is PortableRemoteObject.narrow() method and what is used for?
I found somewhere that it is "CORBA compliant". Why?
Answer 

When you execute a lookup to get the home interface of your bean, you normally use the lookup()method of the javax.naming.Context interface.

This method will return you an Object that needs to be casted to the home interface you've asked for. Unfortunately, this cannot be done using the normal/explicit casting [MyHome myHome = (MyHome)returnedObject].

As you have already found out, the reason is connected to CORBA. Why?


For EJB, the communication between the server and the client is based on RMI (both remote and local interfaces, in fact, do implements the java.rmi.Remoteinterface).


 The underlying protocol that it is used for the communication is IIOP (I think 1.2), that is part of CORBA standards. It is normally used to describe this communication system using the Java RMI over IIOP.

 IIOP has not been designed for Java, but for generic languages, and this means that there are some limitations. Some languages, in fact, do not have the concept of casting.


 Java RMI-IIOP provides a mechanism to narrow the the Object you have received from from your lookup, to the appropriate type. This is done through the javax.rmi.PortableRemoteObjectclass and, more specifically, using the narrow() method.

Just a note: when you are using the new EJB 2.0 Local Client API, you should be able to do a direct/explicit cast from the looked up Object, to the interface you need. 

Top Most How do I transfer a text file from server to client in Java


I am trying to transfer a text file from server to client using File objects. but i am not getting success. so how can we transfer a text file without going into the Socket programming and streams.

Answer

In Java, a File Object simply represents a possibly existing file on the file system.
If you create a file object like this:
File f = new File ( "c:\\test.txt" );
and the file "c:\test.txt" doesn't exist, this will throw no exception (but f.exists ( ) will tell you so).


If you want to work with a file's content, you'll ask an InputStream for it, and only then you'll really access the file.

What you can do to solve your problem, is to read the file on the server side, store it's content (in a String, byte array, or whatever ...) and pass the content to the client.

This has to be done, because the remote machine can't access the local machine's file system.

This can be implemented by putting a method in you remote interface like this:
byte[] getFileContents ( String fileName ) throws RemoteException;
if you then implement this method on the serverside and return a byte array, you can write a new file on the client side, or keep the data in memory, according to your needs ...

Top Most Why should my remote object extend UnicastRemoteObject


 If you extends this class, your object will be automatically exported for RMI access. If your class is already extending another class, or you just don't like extending from UnicastRemoteObject, you can also do the following:

 UnicastRemoteObject.exportObject ( this );

Top Most Why we use home interface in EJB


In RMI we dont have any concept like home interface.why we particularly go for Home Interface Both RMI and EJB are distributed applications. In EJB we use Home interface which is not avaliable in RMI. There must be several reasons for using Home Interface of EJB. can any one give reason for this? 

Answer By posing this question, you seem to be comparing RMI and EJB as if they were the same type of technology and they are definately not. RMI is a lower level technology that allows java objects to be distributed across multiple JVMs. Essentially, RMI abstracts sockets and inter-JVM communications.

 EJB, on the other hand, is a technology built atop of RMI but does so much more than allow java objects to be distributed. It is a framework that allows you to build enterprise applications by (among other things) abstracting transactions, database access and concurent processing. 

 Having said this, the answer to your question is the following. The home interface is EJB's way of creating an object. Home interfaces act as factories to create session beans and entity beans. These factories are provided by the application container and take care of many low level details. Since RMI is a lower level technology, it does not offer the home interface. You would have to create it yourself. 

Ans:2. Although EJB originally started as a technology for remoting, and therefore made use of RMI for containers implementations, the technology has now outgrown its original intent. The introduction of local interfaces geve EJBs a boost for situations where remoting was not necessary, leading to faster intra-VM calls. 

 In view of this departure form the remoting nature of EJBs, I do believe that the real defining feature of EJBs is the life cycle management provided by the application server. In recent years, the JVM itself has received many improvements in the area of memory management and garbage collection. Sun and IBM have both studied carefully the usage patterns on the servers and built agressive optimization strategies. 

 Marc Fleury (the vibrant voice behind JBoss) recently published an interesting white paper about the optimizations built into modern EJB containers, as well as an interesting view (I happen to share it) that with the flexibility introduced by CMP 2.0, EJB containers are rapidly becoming elaborate caches. These caches keep the raw database data in a format directly usable by Java code, taking care of synchronizing memory and database when necessary. 

Top Most What is RMI



    RMI stands for Remote Method Invocation and is a Network Layer to let a client application to invoke methods of objects located on a remote server. The word "RMI" is not specific to the Java language: the RMI concept is not recent and has been implemented in many other languages. RMI can be considered the object orientation counterpart of Remote Procedure Call (RPC). Speaking in a Java context we should specify Java RMI is a protocol that enables a remote object to be used just as it would on a local machine.

LinkWithin

Related Posts Plugin for WordPress, Blogger...

Labels

Core Java programming core java interview question Core Java Faq's Servlets coding database jsp-servlet spring Java linux unix interview questions java investment bank Web Services Interview investment bank mysql Senior java developer interviews best practices java collection tutorial RMI SQL Eclipse FIX protocol tutorial tibco J2EE groovy java questions SCJP grails java 5 tutorial jdbc beginner error and exception Design Patterns Java Programming Tutorials fundamentals general object oriented programming xml Java Programs Hibernate Examples Flex JAMon Java xml tutorial logging Jsp Struts 2.0 Sybase and SQL Server debugging java interviews performance FIX Protocol interview questions JUnit testing WebSphere date and time tutorial experienced java IO tutorial java concurrency thread Ejb Freshers Papers IT Management Java Exapmle Java Script SQL and database tutorial examples Scwcd ant tutorials concurrency example and tutorial future state homework java changes java threading tricky Agile Business of IT Development JSTL Java JSON tutorial Java multithreading Tutorials PM Scrum data structure and algorithm java puzzles java tips testing tips windows 8 5 way to create Singleton Object Architect Interview Questions and Answers Architecture Architecure Bluetooth server as swing application that searches bluetooth device in 10 meter circle and show all devices. You can send file to any bluetooth device. C Programming CIO Callable Statement in Java Circular dependency of Objects in Java Comparable Example in Collection Custom annotation in Java Developer Interview Divide and rule example in java Drupal Example of Singleton Pattern FIX protocol ForkJoin Example in Java 7 Get data from dynamic table with Java Script Git HTML and JavaScript Health Hello World TCP Client Server Networking Program Hibernate Basics Hibernate Interview Question Answer J2EE Interview Question And Answers J2ME GUI Program JEE Interview QA JMS interview question Java J2EE Hibernate Spring Struts Interview Question Java System Property Java Threads Manager Portlets Provident Fund Read data from any file in same location and give the required result. Reading Properties File in Java Redpoint Rest WebService Client Rest Webservice Test SAL join with ven diagram SCP UNIX COMMAND SSL Singleton Pattern in Java Spring Bean Initialization methods and their order Spring Interview Questions Struts Struts 2.0 Basics Struts 2.0 Design Pattern Submit Html Form With Java Script On The Fly Unix executable For Java Program XOM DOM SAX XP books computers core java; core java; object oriented programming data structure; java investment bank; design pattern dtd duplicate rows in table get browser name with jquery grails podcast inner class java beginners tutorial java cache java networking tutorial java spring java util; java collections; java questions java.java1.5 linked list mailto function with all browser oracle database oracle duplicate rows orm schema social spring mvc questions struts transaction tricks tweet windows xslt