@Nullable @Override public FlexyClassLoader installTypeDefinition(Instance instance) { TypeDefinition td = instance.getTypeDefinition(); List<KMFContainer> filters = td.select("deployUnits[]/filters[name=platform,value=java]"); if (filters.size() > 1) { String filtersStr = ""; for (int i=0; i < filters.size(); i++) { filtersStr += filters.get(i).eContainer().path(); if (i < filters.size() - 1) { filtersStr += ", "; } } throw new RuntimeException("Instance " + instance.path() + " has " + filters.size() + " deployUnits ("+filtersStr+") that matches platform \"java\" (must only be one)"); } DeployUnit du = (DeployUnit) filters.get(0).eContainer(); return installDeployUnit(du); }
public boolean execute() { try { Object ref = registry.lookup(c); if (ref instanceof KInstanceWrapper) { ((KInstanceWrapper) ref).destroy(); } registry.drop(c); Log.info("Remove instance {}", c.path()); return true; } catch (Exception e) { return false; } }
private String searchMainClassName(final Instance instance) { TypeDefinition td = instance.getTypeDefinition(); List<KMFContainer> filters = td.select("deployUnits[]/filters[name=platform,value=java]"); if (filters.size() > 1) { String filtersStr = ""; for (int i=0; i < filters.size(); i++) { filtersStr += filters.get(i).eContainer().path(); if (i < filters.size() - 1) { filtersStr += ", "; } } throw new RuntimeException("Instance " + instance.path() + " has " + filters.size() + " deployUnits ("+filtersStr+") that matches platform \"java\" (must only be one)"); } DeployUnit du = (DeployUnit) filters.get(0).eContainer(); String tag = "class:" + td.getName() + ":" + td.getVersion(); Value tdefClassName = du.findFiltersByID(tag); if (tdefClassName != null) { return tdefClassName.getValue(); } else { throw new RuntimeException("Cannot find meta-data \"" + tag + "\" in DeployUnit " + du.getHashcode() + "/" + du.getName() + "/" + du.getVersion()); } }
public void run() { try { FlexyClassLoader newKCL = ClassLoaderHelper.createInstanceClassLoader(c, nodeName, bs); Thread.currentThread().setContextClassLoader(newKCL); Thread.currentThread().setName("KevoreeAddInstance" + c.getName()); KInstanceWrapper newBeanKInstanceWrapper; if (c instanceof ContainerNode) { newBeanKInstanceWrapper = wrapperFactory.wrap(c, this/* nodeInstance is useless because launched as external process */, tg, bs, modelService); newBeanKInstanceWrapper.setKcl(newKCL); registry.register(c, newBeanKInstanceWrapper); } else { Object newBeanInstance = bs.createInstance(c, newKCL); newBeanKInstanceWrapper = wrapperFactory.wrap(c, newBeanInstance, tg, bs, modelService); newBeanKInstanceWrapper.setKcl(newKCL); registry.register(c, newBeanKInstanceWrapper); bs.injectDictionary(c, newBeanInstance, true); } newBeanKInstanceWrapper.create(); resultSub = true; Thread.currentThread().setContextClassLoader(null); Log.info("Add instance {}", c.path()); } catch(Throwable e) { Log.error("Error while adding instance {}", e, c.getName()); resultSub = false; } }
@Override public Object createInstance(final Instance instance, final FlexyClassLoader classLoader) { try { final String mainClassName = searchMainClassName(instance); final Class clazz = classLoader.loadClass(mainClassName); final Object newInstance = clazz.newInstance(); injector.register(Context.class, new InstanceContext(instance.path(), nodeName, instance.getName())); injector.register(ModelService.class, new ContextAwareAdapter(core, instance.path())); injector.register(PlatformService.class, core); injector.inject(newInstance); return newInstance; } catch (final Exception e) { Log.error("Error while creating instance \"{}\" of type {}", e, instance.getName(), instance.getTypeDefinition().getName()); } return null; }
public boolean execute() { List<KMFContainer> metas = c.getTypeDefinition().select("deployUnits[]/filters[name=platform,value=java]"); if (metas.isEmpty()) { Log.error("No DeployUnit found for '" + c.getName() + ": " + c.getTypeDefinition().getName() + "/" + c.getTypeDefinition().getVersion() + "' that matches the 'java' platform"); return false; } Thread subThread = null; try { tg = new KevoreeThreadGroup("kev/" + c.path()); subThread = new Thread(tg, this); subThread.start(); subThread.join(); return resultSub; } catch (Throwable e) { if (subThread != null) { try { //subThread.stop(); //kill sub thread subThread.interrupt(); } catch (Throwable t) { //ignore killing thread } } Log.error("Could not add the instance {}:{}", c.getName(), c.getTypeDefinition().getName(), e); return false; } }
public void setModelElement(Instance modelElement) { super.setModelElement(modelElement); context = new ChannelWrapperContext(modelElement.path(), getNodeName(), getModelService()); getBs().injectService(ChannelContext.class, context, getTargetObj()); }
@Override public synchronized Object createInstance(final Instance instance, final ClassLoader classLoader) throws KevoreeCoreException { final DeployUnit du = getJavaDeployUnit(instance); try { final String mainClassName = searchMainClassName(instance); final Class clazz = classLoader.loadClass(mainClassName); final Object newInstance = clazz.newInstance(); final InstanceContext instanceContext = new InstanceContext(instance.path(), core.getNodeName(), instance.getName()); injector.register(Context.class, instanceContext); injector.register(ModelService.class, new ContextAwareModelServiceAdapter(core, instance.path())); // TODO there should be a GroupContext also that gives attached nodes etc.. injector.register(ChannelContext.class, new ChannelContextImpl(instanceContext)); injector.inject(newInstance); return newInstance; } catch (NoClassDefFoundError e) { throw new KevoreeCoreException("@KevoreeInject failed (is " + du.getName() + ":" + du.getVersion() + ":"+du.getHashcode().substring(0, 6)+" up-to-date?)", e); } catch (Throwable e) { throw new KevoreeCoreException("Unable to create instance " + instance.getName(), e); } }
Instance instance = (Instance) dicValue.eContainer().eContainer(); if (instance != null) { KMFContainer previousInstance = previousModel.findByPath(c.path()); if (previousInstance != null) { DictionaryType dt = instance.getTypeDefinition().getDictionaryType();