This discussion is archived
2 Replies Latest reply: Mar 31, 2013 10:57 PM by 1000102 RSS

Need help about reflexivity bidirectionnal

1000102 Newbie
Currently Being Moderated
Hello,
I try to make an application that could use plugin (with thread and sockets)
For this moment I could instantiate my jar at runtime and call method from mother class.

here is the part where I instantiate the jar

public static void load_Jars (){

          <blockquote>Server _server = new Server();
          JarFile jarFile = null;
     File file = new File("C:/Chemin d'accès du jar.jar");
URLClassLoader clazzLoader = null;
          <blockquote>try {
               clazzLoader = URLClassLoader.newInstance(new URL[]{file.toURI().toURL()});
          } catch (MalformedURLException e2) {
               e2.printStackTrace();
          }</blockquote>           <blockquote>try {
               jarFile = new JarFile(file);
          } catch (IOException e1) {
               // TODO Auto-generated catch block
               e1.printStackTrace();
          }</blockquote> Enumeration<JarEntry> entries = jarFile.entries();

while (entries.hasMoreElements()) {<blockquote>JarEntry element = entries.nextElement();
if (element.getName().endsWith(".class")) {
try {
Class c = clazzLoader.loadClass(element.getName().replaceAll(".class", "").replaceAll("/", "."));
if(c.getName().equals("FM_Automate")){

     Constructor constr = c.getConstructor(String.class);      
Server.o = constr.newInstance(_message, event);
Server.method = c.getMethod("Item_Action",String.class); </blockquote> }
} catch (Exception e) {
e.printStackTrace();
}
}
}</blockquote>      }

and there the class in the jar

public class FM_Automate{

     <blockquote>static String socketPort, message;
     private static ServerSocket socketserverB;
private static Socket socketB;
static Boolean etatsocket;
public static Class _server;</blockquote>   
public String getMessage () {
     <blockquote>return message;</blockquote> }
public FM_Automate (String _message){

     <blockquote>message = _message;     

          try {
                    <blockquote>socketB = new Socket("192.168.0.1",2010);
                    new ReceptionSrvFMAuto (socketB, this);
                    etatsocket = socketB.isConnected();</blockquote>               } catch (UnknownHostException e) {
                    <blockquote>// TODO Auto-generated catch block
                    e.printStackTrace();</blockquote>               } catch (IOException e) {
                    <blockquote>// TODO Auto-generated catch block
                    e.printStackTrace();</blockquote>               }</blockquote> }

     public void Item_Action (String _message){
     <blockquote>message = _message;
     try {

               <blockquote>PrintWriter out = new PrintWriter(
new BufferedWriter(
new OutputStreamWriter(socketB.getOutputStream())),
true);
               out.println(message);
               out.flush();</blockquote>
          } catch (UnknownHostException e) {
               <blockquote>// TODO Auto-generated catch block
               e.printStackTrace();</blockquote>          } catch (IOException e) {
               <blockquote>// TODO Auto-generated catch block
               e.printStackTrace();</blockquote>          }</blockquote>     }
synchronized public static void getReceivedData (String message){
     <blockquote>System.out.println("message: "+message);</blockquote> }


I would like to return value for the thread that receive data from socket to the mother class.
I try many thing like pass mother class inside the constructor etc but nothing work

Hope someone could help me

Thanks a lot
Max

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points