Skip to content

Commit

Permalink
Merge branch 'master' of ssh://git.actoron.com:20000/jadex/jadex
Browse files Browse the repository at this point in the history
  • Loading branch information
ap-actoron committed Mar 11, 2022
2 parents 35ebbd2 + 5645fa4 commit 4c069d9
Show file tree
Hide file tree
Showing 156 changed files with 11,205 additions and 7,525 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import jadex.bridge.service.ServiceScope;
import jadex.bridge.service.types.factory.IComponentFactory;
import jadex.commons.Boolean3;
import jadex.component.ComponentComponentFactory;
import jadex.micro.annotation.Agent;
import jadex.micro.annotation.Implementation;
import jadex.micro.annotation.Properties;
Expand All @@ -15,7 +16,8 @@
*/
@Properties({
@NameValue(name="system", value="true"),
@NameValue(name="kernel.types", value="new String[] {\"application.xml\"}")
@NameValue(name="kernel.types", value="new String[] {\"application.xml\"}"),
@NameValue(name="kernel.componenttypes", value="new String[]{\""+ApplicationComponentFactory.FILETYPE_APPLICATION+"\"}")
})
@ProvidedServices({
@ProvidedService(type=IComponentFactory.class, scope=ServiceScope.PLATFORM, implementation=@Implementation(expression="new jadex.application.ApplicationComponentFactory($component)"))
Expand Down
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
5 changes: 4 additions & 1 deletion kernels/bpmn/src/main/java/jadex/bpmn/KernelBpmnAgent.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@
*/
// Hack!!! allows starting bpmn kernel when micro kernel is available, but avoids dependency from bpmn to micro
// and vice versa.
@Properties({@NameValue(name="system", value="true"), @NameValue(name="kernel.types", value="new String[]{\".bpmn\", \".bpmn2\"}")})
@Properties({@NameValue(name="system", value="true"),
@NameValue(name="kernel.types", value="new String[]{\".bpmn\", \".bpmn2\"}"),
@NameValue(name="kernel.componenttypes", value="new String[]{\""+BpmnFactory.FILETYPE_BPMNPROCESS+"\","+"\""+BpmnFactory.FILETYPE_BPMNLEGACYPROCESS+"\"}")
})
@ProvidedServices({
@ProvidedService(type=IComponentFactory.class, scope=ServiceScope.PLATFORM, implementation=@Implementation(
expression="new jadex.bpmn.BpmnFactory($component, jadex.commons.SUtil.createHashMap("
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
*/
@Properties({
@NameValue(name="system", value="true"),
@NameValue(name="kernel.types", value="new String[] {\"component.xml\"}")
@NameValue(name="kernel.types", value="new String[] {\"component.xml\"}"),
@NameValue(name="kernel.componenttypes", value="new String[]{\""+ComponentComponentFactory.FILETYPE_COMPONENT+"\"}")
})
@ProvidedServices({
@ProvidedService(type=IComponentFactory.class, scope=ServiceScope.PLATFORM, implementation=@Implementation(expression="new jadex.component.ComponentComponentFactory($component)"))
Expand Down
177 changes: 106 additions & 71 deletions kernels/micro/src/main/java/jadex/micro/KernelMultiAgent.java
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ public IFuture<Void> execute(IInternalAccess ia)
*/
public IFuture<byte[]> getComponentTypeIcon(String type)
{
// System.out.println("multi factory icon: "+type+" "+iconcache.containsKey(type));
//System.out.println("multi factory icon: "+type+" "+iconcache.containsKey(type));

byte[] icon = iconcache.get(type);

Expand Down 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 @@ -714,6 +730,8 @@ protected void initKnownComponentTypes()
allcomponenttypes = new HashSet<String>();
allannotationtypes = new HashMap<String, String>();

// todo: use scanForKernels()

for(String kk: known_kernels)
{
// todo: use library loader (needs rid besides classname)
Expand Down Expand Up @@ -755,6 +773,9 @@ protected void initKnownComponentTypes()
agent.getLogger().info("Predefined Jadex kernel not available: "+kk+", "+e);
}
}

//System.out.println("comp types: "+allcomponenttypes);
//System.out.println("ann types: "+allannotationtypes);
}
}

Expand Down Expand Up @@ -882,12 +903,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 +983,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 Expand Up @@ -1054,7 +1089,7 @@ public String[] getComponentTypes()
//return (String[])componenttypes.toArray(new String[componenttypes.size()]);

initKnownComponentTypes();
System.out.println("allcomponenttypes: "+allcomponenttypes);
//System.out.println("allcomponenttypes: "+allcomponenttypes);
return allcomponenttypes.toArray(new String[0]);

//return (String[])getKnownKernels().keySet().toArray(new String[0]);
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
8 changes: 5 additions & 3 deletions platform/base/src/main/java/jadex/platform/PlatformAgent.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

import jadex.base.IPlatformConfiguration;
import jadex.base.Starter;
import jadex.bridge.IComponentIdentifier;
import jadex.bridge.IExternalAccess;
import jadex.bridge.IInternalAccess;
import jadex.bridge.VersionInfo;
Expand Down Expand Up @@ -535,13 +536,14 @@ public void intermediateResultAvailable(IExternalAccess result)
{
try
{
if(!agent.getId().getRoot().equals(result.getId().getRoot()))
IComponentIdentifier cid = result!=null && result.getId()!=null? result.getId(): null;
if(cid!=null && !agent.getId().getRoot().equals(cid.getRoot()))
{
//System.out.println("found platform: "+result.getId());//+" "+SComponentManagementService.containsComponent(result.getId()));
Map<String, Object> args = new HashMap<>();
args.put("component", result.getId());
args.put("component", cid);
agent.createComponent(new CreationInfo().setFilename("jadex.platform.service.remote.ProxyAgent.class")
.setArguments(args).setName(result.getId().toString()));
.setArguments(args).setName(cid.toString()));
}
}
catch(Exception e)
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

0 comments on commit 4c069d9

Please sign in to comment.