1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-04 06:45:43 +02:00

tracing and support for getting class bytes via the file

This commit is contained in:
David McKnight 2011-10-13 15:21:51 +00:00
parent 1f7670e22a
commit 3823dcc6a4
3 changed files with 50 additions and 16 deletions

View file

@ -158,6 +158,9 @@ public class ClassByteStreamHandler implements IClassByteStreamHandler
*/ */
public void run() public void run()
{ {
_dataStore.trace("receiving class bytes"); //$NON-NLS-1$
_dataStore.trace("\tsize="+_size); //$NON-NLS-1$
_dataStore.trace("\tbuffer="+_buffer); //$NON-NLS-1$
try try
{ {
PipedInputStream ins = new PipedInputStream(); PipedInputStream ins = new PipedInputStream();
@ -168,7 +171,10 @@ public class ClassByteStreamHandler implements IClassByteStreamHandler
outStream.close(); outStream.close();
IRemoteClassInstance instance = loadInstance(ins); IRemoteClassInstance instance = loadInstance(ins);
runInstance(instance); if (instance != null){
_dataStore.trace("running class instance "+instance); //$NON-NLS-1$
runInstance(instance);
}
} }
catch (Exception e) catch (Exception e)
@ -204,7 +210,13 @@ public class ClassByteStreamHandler implements IClassByteStreamHandler
else else
{ {
// on server run and update client // on server run and update client
instance.arrivedOnServer(); _dataStore.trace("calling arrived on server"); //$NON-NLS-1$
try {
instance.arrivedOnServer();
}
catch (Exception e){
_dataStore.trace(e);
}
_dataStore.updateRemoteClassInstance(instance, getIdentifier()); _dataStore.updateRemoteClassInstance(instance, getIdentifier());
} }
} }

View file

@ -171,8 +171,9 @@ public class RemoteClassLoader extends ClassLoader
*/ */
protected Class findClass(String className) throws ClassNotFoundException protected Class findClass(String className) throws ClassNotFoundException
{ {
// first try using the datastore's local classloaders _dataStore.trace("findClass "+className); //$NON-NLS-1$
// first try using the datastore's local classloaders
ArrayList localLoaders = _dataStore.getLocalClassLoaders(); ArrayList localLoaders = _dataStore.getLocalClassLoaders();
if (localLoaders != null) if (localLoaders != null)
{ {
@ -186,7 +187,7 @@ public class RemoteClassLoader extends ClassLoader
} }
catch (Exception e) catch (Exception e)
{ {
e.printStackTrace(); //e.printStackTrace();
} }
} }
} }
@ -197,7 +198,6 @@ public class RemoteClassLoader extends ClassLoader
Class theClass = super.findClass(className); Class theClass = super.findClass(className);
if (theClass != null) if (theClass != null)
{ {
//System.out.println("Using super's: " + className);
return theClass; return theClass;
} }
} }
@ -219,6 +219,7 @@ public class RemoteClassLoader extends ClassLoader
// search the class request repository to see if the class has been requested // search the class request repository to see if the class has been requested
// already // already
ClassRequest request; ClassRequest request;
_dataStore.trace("checking class repository..."); //$NON-NLS-1$
request = (ClassRequest) _dataStore.getClassRequestRepository().get(className); request = (ClassRequest) _dataStore.getClassRequestRepository().get(className);
if (request == null) if (request == null)
@ -229,7 +230,7 @@ public class RemoteClassLoader extends ClassLoader
{ {
try try
{ {
_dataStore.trace("checking cache"); //$NON-NLS-1$
Class theClass = _urlClassLoader.findCachedClass(className); Class theClass = _urlClassLoader.findCachedClass(className);
//System.out.println("Using cached: " + className); //System.out.println("Using cached: " + className);
@ -280,7 +281,7 @@ public class RemoteClassLoader extends ClassLoader
*/ */
public synchronized void receiveClass(String className, byte[] bytes, int size) public synchronized void receiveClass(String className, byte[] bytes, int size)
{ {
// System.out.println("receiving "+className); _dataStore.trace("receiving "+className); //$NON-NLS-1$
// check the class request repository to see if the class is there // check the class request repository to see if the class is there
ClassRequest request = (ClassRequest) _dataStore.getClassRequestRepository().get(className); ClassRequest request = (ClassRequest) _dataStore.getClassRequestRepository().get(className);
if (request != null) if (request != null)
@ -299,14 +300,21 @@ public class RemoteClassLoader extends ClassLoader
Class receivedClass = null; Class receivedClass = null;
try try
{ {
// System.out.println("defining "+className+"..."); _dataStore.trace("defining "+className+"..."); //$NON-NLS-2$
// try to define the class. If any dependent classes cannot be // try to define the class. If any dependent classes cannot be
// found the JRE implementation will call findClass to look for them. // found the JRE implementation will call findClass to look for them.
// Thus we could end up with a stack of requests all waiting until the // Thus we could end up with a stack of requests all waiting until the
// classes with no dependent classes load. // classes with no dependent classes load.
receivedClass = defineClass(className, bytes, 0, size); receivedClass = defineClass(className, bytes, 0, size);
if (receivedClass == null){
try {
receivedClass = findClass(className);
}
catch (Exception e){
}
}
// System.out.println("...finished defining "+className); _dataStore.trace("...finished defining "+className); //$NON-NLS-1$
} }
catch (NoClassDefFoundError e) catch (NoClassDefFoundError e)
{ {
@ -369,7 +377,7 @@ public class RemoteClassLoader extends ClassLoader
// SUCCESS! The class has been received, and defined, so just // SUCCESS! The class has been received, and defined, so just
// load it into the class request object. This action will // load it into the class request object. This action will
// also notify threads waiting for the class // also notify threads waiting for the class
// System.out.println("notifying requesters"); _dataStore.trace("notifying requesters");
request.setLoadedClass(receivedClass); request.setLoadedClass(receivedClass);
if (useCaching()) if (useCaching())
{ {
@ -385,7 +393,7 @@ public class RemoteClassLoader extends ClassLoader
*/ */
protected void requestClassInThread(String className) protected void requestClassInThread(String className)
{ {
// System.out.println("requesting (in thread)"+className); _dataStore.trace("requesting (in thread)"+className);
LoadClassThread thread = new LoadClassThread(className); LoadClassThread thread = new LoadClassThread(className);
thread.start(); thread.start();
} }
@ -413,9 +421,9 @@ public class RemoteClassLoader extends ClassLoader
_dataStore.requestClass(className); _dataStore.requestClass(className);
// wait for a response // wait for a response
// System.out.println("thread to wait: "+Thread.currentThread().getName()); _dataStore.trace("thread to wait: "+Thread.currentThread().getName());
if (!request.isLoaded()) request.waitForResponse(); if (!request.isLoaded()) request.waitForResponse();
// System.out.println("thread finished waiting: "+Thread.currentThread().getName()); _dataStore.trace("thread finished waiting: "+Thread.currentThread().getName());
if (request.isLoaded()) return request.getLoadedClass(); if (request.isLoaded()) return request.getLoadedClass();
else { else {
// remove the request so that if another one comes in for the // remove the request so that if another one comes in for the
@ -428,9 +436,9 @@ public class RemoteClassLoader extends ClassLoader
else if (!request.isLoaded()) else if (!request.isLoaded())
{ {
// class has already been requested, wait for it to load // class has already been requested, wait for it to load
// System.out.println("requested elsewhere, thread to wait: "+Thread.currentThread().getName()); _dataStore.trace("requested elsewhere, thread to wait: "+Thread.currentThread().getName());
if (!request.isLoaded()) request.waitForResponse(); if (!request.isLoaded()) request.waitForResponse();
// System.out.println("requested elsewhere, thread finished waiting: "+Thread.currentThread().getName()); _dataStore.trace("requested elsewhere, thread finished waiting: "+Thread.currentThread().getName());
if (request.isLoaded()) return request.getLoadedClass(); if (request.isLoaded()) return request.getLoadedClass();
else throw new ClassNotFoundException(className); else throw new ClassNotFoundException(className);
} }

View file

@ -24,6 +24,8 @@ package org.eclipse.dstore.internal.core.util;
import java.io.BufferedInputStream; import java.io.BufferedInputStream;
import java.io.BufferedWriter; import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.OutputStreamWriter; import java.io.OutputStreamWriter;
@ -200,6 +202,18 @@ public class Sender implements ISender
classInStream = loader.getResourceAsStream(className); classInStream = loader.getResourceAsStream(className);
classLocation = loader.getResource(className); classLocation = loader.getResource(className);
if (classInStream == null && classLocation != null){
try {
String file = classLocation.getFile();
File f = new File(file);
if (f.exists()){
classInStream = new FileInputStream(f);
}
} catch (Exception e) {
_dataStore.trace(e);
}
}
if (classInStream != null && classLocation != null) break; if (classInStream != null && classLocation != null) break;
} }
if (classLocation == null || classInStream == null) if (classLocation == null || classInStream == null)