/* 
* ################################################################
* 
* ProActive: The Java(TM) library for Parallel, Distributed, 
*            Concurrent computing with Security and Mobility
* 
* Copyright (C) 1997-2002 INRIA/University of Nice-Sophia Antipolis
* Contact: proactive-support@inria.fr
* 
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or any later version.
*  
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
* Lesser General Public License for more details.
* 
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
* USA
*  
*  Initial developer(s):               The ProActive Team
*                        http://www.inria.fr/oasis/ProActive/contacts.html
*  Contributor(s): 
* 
* ################################################################
*/ 
package org.objectweb.proactive.core.body.jini;

import org.objectweb.proactive.Body;
import org.objectweb.proactive.core.UniqueID;
import org.objectweb.proactive.core.body.UniversalBody;
import org.objectweb.proactive.core.body.reply.Reply;
import org.objectweb.proactive.core.body.request.Request;
import org.objectweb.proactive.core.rmi.RandomPortSocketFactory;

import java.rmi.RemoteException;

/**
 *   An adapter for a LocalBody to be able to receive jini calls. This helps isolate JINI-specific
 *   code into a small set of specific classes, thus enabling reuse if we one day decide to switch
 *   to anothe jini objects library.
 */
public class JiniBodyImpl extends java.rmi.server.UnicastRemoteObject implements JiniBody, java.rmi.server.Unreferenced {


    /**
     * A custom socket Factory
     */
    protected static RandomPortSocketFactory factory = new RandomPortSocketFactory(37002, 5000);
  
    /**
     * The encapsulated local body
     * transient to deal with custom serialization of requests.
     */
    protected transient Body body;
  

    //
    // -- CONSTRUCTORS -----------------------------------------------
    //

    public JiniBodyImpl() throws RemoteException {
    }

  public JiniBodyImpl(Body body) throws RemoteException {
      // super(0, factory, factory);
    this.body = body;
  }


  //
  // -- PUBLIC METHODS -----------------------------------------------
  //

  
  //
  // -- implements JiniBody -----------------------------------------------
  //


  public void receiveRequest(Request r) throws java.io.IOException {
    //System.out.println("JiniBodyImpl: receiveRequest() for " + this.localBody);
    System.out.println("JiniBodyImpl: receiveRequest() request is " + r.getMethodName());
    body.receiveRequest(r);
  }

  public void receiveReply(Reply r) throws java.io.IOException {
    body.receiveReply(r);
  }


  public String getNodeURL() {
    return body.getNodeURL();
  }

  public UniqueID getID() {
    return body.getID();
  }

  public void updateLocation(UniqueID id, UniversalBody jiniBody) throws java.io.IOException {
    body.updateLocation(id, jiniBody);
  }

	public void enableAC() throws java.io.IOException {
		body.enableAC();
	}
	
	public void disableAC() throws java.io.IOException {
		body.disableAC();
	}
	
	public void setImmediateService (String methodName) throws java.io.IOException {
  		body.setImmediateService(methodName);
 	}

  public void unreferenced() {
    System.out.println("JiniBodyImpl: unreferenced()");      
    System.gc();
  }

    //
    // -- PRIVATE METHODS -----------------------------------------------
    //
  
    //
    // -- SERIALIZATION -----------------------------------------------
    //
  
    /*    
	  private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException {
	  long startTime=System.currentTimeMillis();
	  out.defaultWriteObject();
	  long endTime=System.currentTimeMillis();
	  System.out.println(" SERIALIZATION OF JINIBODYIMPL lasted " + (endTime - startTime));
	
	  }

    
	  private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, ClassNotFoundException {
	  in.defaultReadObject();
	  }
    */
}

@@ -1303,36 +1303,65 @@
 ort 
-org.objectweb.proactive.Body
+java.rmi.RemoteException;%0A%0Aimport org.apache.log4j.Logger
 ;%0Aim
@@ -1642,42 +1642,8 @@
 y;%0A%0A
-import java.rmi.RemoteException;%0A%0A
 /**%0A
@@ -2004,17 +2004,95 @@
 nced %7B%0A%0A
+%09%09%0A%09%09static Logger logger = Logger.getLogger(JiniBodyImpl.class.getName());%0A%09%09
 %0A
-
     /**%0A
@@ -2369,16 +2369,25 @@
 ansient 
+Universal
 Body bod
@@ -2559,16 +2559,25 @@
 odyImpl(
+Universal
 Body bod
@@ -2993,24 +2993,26 @@
 lBody);%0A    
+//
 System.out.p
@@ -3798,34 +3798,27 @@
 ) %7B%0A    
-System.out.println
+logger.info
 (%22JiniBo

add logger