Skip to content

Commit

Permalink
multikernel scan kernels bug fixed (sync method with get() method was…
Browse files Browse the repository at this point in the history
… interrupted)
  • Loading branch information
lb-actoron committed Feb 24, 2022
1 parent 49e64fa commit 137e09f
Show file tree
Hide file tree
Showing 7 changed files with 120 additions and 75 deletions.
2 changes: 2 additions & 0 deletions kernels/bdiv3/src/main/java/jadex/bdiv3/BDIAgentFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,8 @@ public IFuture<Boolean> isLoadable(String model, Object pojo, String[] imports,
{
Future<Boolean> ret = new Future<>();

//System.out.println("BDI isLoadable: "+model);

if(pojo!=null)
{
String pojotype = SComponentManagementService.getPojoComponentType(pojo);
Expand Down
1 change: 0 additions & 1 deletion kernels/bpmn/src/main/java/jadex/bpmn/BpmnFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import jadex.bridge.component.impl.ComponentFeatureFactory;
import jadex.bridge.modelinfo.IModelInfo;
import jadex.bridge.service.BasicService;
import jadex.bridge.service.annotation.Raw;
import jadex.bridge.service.component.IProvidedServicesFeature;
import jadex.bridge.service.component.IRequiredServicesFeature;
import jadex.bridge.service.search.ServiceQuery;
Expand Down
168 changes: 99 additions & 69 deletions kernels/micro/src/main/java/jadex/micro/KernelMultiAgent.java
Original file line number Diff line number Diff line change
Expand Up @@ -353,82 +353,98 @@ protected IFuture<IComponentFactory> getNewFactory(String model, Object pojo, St
public void exceptionOccurred(Exception exception)
{
// System.out.println("getKernelFiles: "+model);
Map<String, Collection<Tuple2<String, Set<String>>>> kernelfiles = getKernelFiles();
Set<Tuple2<String, Set<String>>> found = new HashSet<>();
for(Map.Entry<String, Collection<Tuple2<String, Set<String>>>> entry: kernelfiles.entrySet())
getKernelFiles().then(kernelfiles ->
{
if(model.endsWith(entry.getKey()))
Set<Tuple2<String, Set<String>>> found = new HashSet<>();
for(Map.Entry<String, Collection<Tuple2<String, Set<String>>>> entry: kernelfiles.entrySet())
{
found.addAll(entry.getValue());
if(model.endsWith(entry.getKey()))
{
found.addAll(entry.getValue());
}
}
}
final Iterator<Tuple2<String, Set<String>>> it = found.iterator();

check(it, model, pojo, imports, rid).addResultListener(new DelegationResultListener<IComponentFactory>(ret));
final Iterator<Tuple2<String, Set<String>>> it = found.iterator();
check(it, model, pojo, imports, rid).addResultListener(new DelegationResultListener<IComponentFactory>(ret));
}).catchEx(ret);
}
});

return ret;
}


protected Future<Map<String, Collection<Tuple2<String, Set<String>>>>> scanfuture;
/**
* Scan files for kernel components.
* @return (suffix -> classname)
*/
protected Map<String, Collection<Tuple2<String, Set<String>>>> scanForKernels()
protected IFuture<Map<String, Collection<Tuple2<String, Set<String>>>>> scanForKernels()
{
MultiCollection<String, Tuple2<String, Set<String>>> ret = new MultiCollection<>();

// System.out.println("MultiFactory scanning...");

// List<URL> urls = new ArrayList<URL>();
// ClassLoader basecl = MultiFactory.class.getClassLoader();
// for(URL url: SUtil.getClasspathURLs(basecl, true))
// {
// // Hack to avoid at least some Java junk.
// if(!url.toString().contains("jre/lib/ext"))
// {
// urls.add(url);
// }
// }
// System.out.println(urls.size());

ILibraryService ls = agent.getFeature(IRequiredServicesFeature.class).getLocalService(ILibraryService.class);
List<URL> urls2 = ls.getAllURLs().get();

// System.out.println("urls2: "+urls2.size());
// for(URL u: urls2)
// System.out.println(u);
for(Iterator<URL> it=urls2.iterator(); it.hasNext(); )
if(scanfuture==null)
{
String u = it.next().toString();
if(u.indexOf("jre/lib/ext")!=-1
// || u.indexOf("jadex")==-1
|| u.indexOf("SYSTEMCPRID")!=-1)
{
it.remove();
}
}

//System.out.println("scan: "+urls2.size());
scanfuture = new Future<>();

// System.out.println("urls: "+urls);
Set<ClassInfo> cis = SReflect.scanForClassInfos(urls2.toArray(new URL[urls2.size()]), ffilter, cfilter);

for(ClassInfo ci: cis)
{
String[] types = getKernelSuffixes(ci);
MultiCollection<String, Tuple2<String, Set<String>>> ret = new MultiCollection<>();

//System.out.println("MultiFactory scanning..."+Thread.currentThread()+" "+agent.isComponentThread());

// List<URL> urls = new ArrayList<URL>();
// ClassLoader basecl = MultiFactory.class.getClassLoader();
// for(URL url: SUtil.getClasspathURLs(basecl, true))
// {
// // Hack to avoid at least some Java junk.
// if(!url.toString().contains("jre/lib/ext"))
// {
// urls.add(url);
// }
// }
// System.out.println(urls.size());

if(types!=null)
ILibraryService ls = agent.getFeature(IRequiredServicesFeature.class).getLocalService(ILibraryService.class);
//List<URL> urls2 =
ls.getAllURLs().then(urls2 ->
{
for(String type: types)
//System.out.println("urls2: "+urls2.size());
// for(URL u: urls2)
// System.out.println(u);
for(Iterator<URL> it=urls2.iterator(); it.hasNext(); )
{
ret.add(type, new Tuple2<String, Set<String>>(ci.getClassName(), SUtil.arrayToSet(types)));
String u = it.next().toString();
if(u.indexOf("jre/lib/ext")!=-1
// || u.indexOf("jadex")==-1
|| u.indexOf("SYSTEMCPRID")!=-1)
{
it.remove();
}
}
}

//System.out.println("scan: "+urls2.size());

// System.out.println("urls: "+urls);
Set<ClassInfo> cis = SReflect.scanForClassInfos(urls2.toArray(new URL[urls2.size()]), ffilter, cfilter);
//System.out.println("scan end: "+cis);

for(ClassInfo ci: cis)
{
String[] types = getKernelSuffixes(ci);

if(types!=null)
{
for(String type: types)
{
ret.add(type, new Tuple2<String, Set<String>>(ci.getClassName(), SUtil.arrayToSet(types)));
}
}
}

scanfuture.setResult(ret);
scanfuture = null;

}).catchEx(scanfuture);
}

return ret;
return scanfuture;
}

/**
Expand Down Expand Up @@ -882,12 +898,24 @@ protected String[] getKernelAnnotationTypes(ClassInfo ci)
/**
* Get all kernel files, i.e. specs to start a kernel.
*/
protected Map<String, Collection<Tuple2<String, Set<String>>>> getKernelFiles()
protected Future<Map<String, Collection<Tuple2<String, Set<String>>>>> getKernelFiles()
{
Future<Map<String, Collection<Tuple2<String, Set<String>>>>> ret = new Future<>();
if(kernelfiles==null || dirty)
kernelfiles = scanForKernels();
dirty = false;
return kernelfiles;
{
scanForKernels().then(kfs ->
{
kernelfiles = kfs;
dirty = false;
ret.setResult(kernelfiles);
});
}
else if(kernelfiles!=null)
{
ret.setResult(kernelfiles);
}

return ret;
}

/**
Expand Down Expand Up @@ -950,35 +978,37 @@ public IFuture<Boolean> isLoadable(String model, Object pojo, String[] imports,
if(!isLoadable(model))
return IFuture.FALSE;

final int fcnt = cnt++;
//if(model.indexOf("HelplineAgent")!=-1)
// System.out.println("isLoadable: "+model+" "+fcnt);

Future<Boolean> ret = new Future<>();

final int fcnt = cnt++;
//if(model.indexOf("ANDL")!=-1)
//{
//System.out.println("isLoadable: "+model+" "+fcnt);
//ret.then(x -> System.out.println("isLoadableFin: "+model)).catchEx(ex ->System.out.println("isLoadableFin (ex): "+model));
//}

getFactoryForModel(model, pojo, imports, rid).addResultListener(new IResultListener<IComponentFactory>()
{
public void resultAvailable(IComponentFactory fac)
{
//if(model.indexOf("HelplineAgent")!=-1)
// System.out.println("is Loadable middle: "+model+" "+fac+" "+fcnt);
//if(model.indexOf("ANDL")!=-1)
//System.out.println("is Loadable middle: "+model+" "+fac+" "+fcnt);

fac.isLoadable(model, pojo, imports, rid).addResultListener(new DelegationResultListener<Boolean>(ret)
{
public void customResultAvailable(Boolean result)
{
super.customResultAvailable(result);
//// if(model.indexOf("Block")!=-1)
//if(model.indexOf("HelplineAgent")!=-1)
// System.out.println("is Loadable end: "+model+" "+result+" "+fcnt);
//if(model.indexOf("ANDL")!=-1)
//System.out.println("is Loadable end: "+model+" "+result+" "+fcnt);
}
});
}

public void exceptionOccurred(Exception exception)
{
//if(model.indexOf("HelplineAgent")!=-1)
// System.out.println("is Loadable ex: "+exception+" "+model+" "+fcnt);
//if(model.indexOf("ANDL")!=-1)
//System.out.println("is Loadable ex: "+exception+" "+model+" "+fcnt);
ret.setResult(false);
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ public IFuture<Boolean> isLoadable(String model, Object pojo, String[] imports,
{
Future<Boolean> ret = new Future<Boolean>();

// System.out.println("isLoadable (micro): "+model+" "+rid);
//System.out.println("Micro isLoadable (micro): "+model+" "+rid);

if(pojo!=null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ public IFuture<Boolean> isLoadable(String model, Object pojo, String[] imports,
{
Future<Boolean> ret = new Future<Boolean>();

// System.out.println("isLoadable (micro): "+model+" "+rid);
//System.out.println("isLoadable (microservice): "+model+" "+rid);

if(model.toLowerCase().endsWith(".class"))
{
Expand Down
11 changes: 9 additions & 2 deletions platform/bridge/src/main/java/jadex/bridge/FactoryFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public IFuture<Boolean> filter(IComponentFactory obj)

IComponentFactory fac = (IComponentFactory)obj;

//if(model.indexOf("Buyer")!=-1)
//if(model.indexOf("bpmn")!=-1)
// System.out.println("filter");

if(type!=null)
Expand All @@ -96,7 +96,14 @@ else if(anntype!=null)
}
else
{
fac.isLoadable(model, null, imports, rid).addResultListener(new DelegationResultListener<Boolean>(ret));
//long start = System.currentTimeMillis();
fac.isLoadable(model, null, imports, rid)
/*.then(l->
{
if(System.currentTimeMillis()-start>5000)
System.out.println("SLOWWWWW: "+model);
})*/
.delegate((Future)ret);
}

return ret;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2863,7 +2863,14 @@ protected void complete(HttpServletRequest request, HttpServletResponse response

if(request.isAsyncStarted() && request.getAsyncContext() != null && !isComplete(request, response))
{
request.getAsyncContext().complete();
try
{
request.getAsyncContext().complete();
}
catch(Exception e)
{
System.out.println("Exception in context complete(): "+e);
}
}
}

Expand Down

0 comments on commit 137e09f

Please sign in to comment.