当前位置: 首页>>代码示例>>Java>>正文


Java Factory类代码示例

本文整理汇总了Java中org.apache.felix.ipojo.Factory的典型用法代码示例。如果您正苦于以下问题:Java Factory类的具体用法?Java Factory怎么用?Java Factory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Factory类属于org.apache.felix.ipojo包,在下文中一共展示了Factory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: execute

import org.apache.felix.ipojo.Factory; //导入依赖的package包/类
@Override
public Object execute() throws Exception {

    ShellTable table = new ShellTable();
    table.column("Name");
    table.column("Version");
    table.column("Bundle Id");
    table.column("State");

    for (Factory factory : managerService.getFactories()) {
        table.addRow().addContent(factory.getName(), factory.getVersion(), factory.getBundleContext().getBundle().getBundleId(), (factory.getState() == Factory.VALID ? Ansi.ansi().fg(Ansi.Color.GREEN).a("VALID").reset().toString() : Ansi.ansi().fg(Ansi.Color.GREEN).a((factory.getState() == Factory.INVALID ? "INVALID" : "UNKNOWN")).reset().toString()));
    }

    table.print(System.out);

    return null;
}
 
开发者ID:andyphillips404,项目名称:awplab-core,代码行数:18,代码来源:FactoriesCommand.java

示例2: getFactories

import org.apache.felix.ipojo.Factory; //导入依赖的package包/类
protected Set<Factory> getFactories() {
    Set<Factory> factories = new HashSet<>();

    try {
        BundleContext bundleContext = FrameworkUtil.getBundle(IPOJOJobRunShellFactory.class).getBundleContext();
        ServiceReference[] refs = bundleContext.getServiceReferences(Factory.class.getName(), null);
        if (refs != null) {
            for (ServiceReference serviceReference : refs) {
                factories.add((Factory)bundleContext.getService(serviceReference));
            }
        }

        return factories;
    }
    catch (Exception ex) {
        LoggerFactory.getLogger(IPOJOJobRunShellFactory.class).error("Exception getting factories.", ex);
        return Collections.emptySet();
    }

}
 
开发者ID:andyphillips404,项目名称:awplab-core,代码行数:21,代码来源:IPOJOJobRunShellFactory.java

示例3: setMessagingConfiguration

import org.apache.felix.ipojo.Factory; //导入依赖的package包/类
@Before
public void setMessagingConfiguration() {

	this.msgCfg = new LinkedHashMap<>();
	this.msgCfg.put("net.roboconf.messaging.type", "telepathy");
	this.msgCfg.put("mindControl", "false");
	this.msgCfg.put("psychosisProtection", "active");

	this.manager = Mockito.mock( Manager.class );
	this.standardAgentFactory = Mockito.mock( Factory.class );
	this.nazgulAgentFactory = Mockito.mock( Factory.class );

	this.handler = new InMemoryHandler();
	this.handler.setMessagingFactoryRegistry( new MessagingClientFactoryRegistry());

	this.handler.standardAgentFactory = this.standardAgentFactory;
	this.handler.nazgulAgentFactory = this.nazgulAgentFactory;
	this.handler.manager = this.manager;
}
 
开发者ID:roboconf,项目名称:roboconf-platform,代码行数:20,代码来源:InMemoryHandlerMockedManagerTest.java

示例4: testStop

import org.apache.felix.ipojo.Factory; //导入依赖的package包/类
@Test
public void testStop() throws Exception {

	this.target.standardAgentFactory = Mockito.mock( Factory.class );
	this.target.nazgulAgentFactory = Mockito.mock( Factory.class );

	ComponentInstance agentMock = Mockito.mock( ComponentInstance.class );
	Mockito.when( this.target.standardAgentFactory .getInstances()).thenReturn( Arrays.asList( agentMock ));

	ComponentInstance nazgulMock = Mockito.mock( ComponentInstance.class );
	Mockito.when( this.target.nazgulAgentFactory .getInstances()).thenReturn( Arrays.asList( nazgulMock ));

	this.target.stop();
	Mockito.verify( this.target.standardAgentFactory, Mockito.only()).getInstances();
	Mockito.verify( this.target.nazgulAgentFactory, Mockito.only()).getInstances();

	Mockito.verify( agentMock ).dispose();
	Mockito.verify( nazgulMock ).dispose();
}
 
开发者ID:roboconf,项目名称:roboconf-platform,代码行数:20,代码来源:InMemoryHandlerWithoutManagerTest.java

示例5: getRelations

import org.apache.felix.ipojo.Factory; //导入依赖的package包/类
@Override
public List<Relation> getRelations() {
    List<Relation> r = super.getRelations();
    Factory f = m_factory.get();
    if (f == null) {
        // Reference has been released
        return r;
    }
    // Add dynamic relations
    r = new ArrayList<Relation>(r);
    for (String instanceName : getCreatedInstanceNames(f)) {
        r.add(new DefaultRelation(
                INSTANCES.addElements(instanceName),
                Action.READ,
                "instance[" + instanceName + "]",
                "Instance '" + instanceName + "'"));
    }
    return Collections.unmodifiableList(r);
}
 
开发者ID:ow2-chameleon,项目名称:everest,代码行数:20,代码来源:FactoryResource.java

示例6: getCreatedInstanceNames

import org.apache.felix.ipojo.Factory; //导入依赖的package包/类
private Set<String> getCreatedInstanceNames(Factory factory) {
    Field weapon = null;
    try {
        weapon = IPojoFactory.class.getDeclaredField("m_componentInstances");
        weapon.setAccessible(true);
        @SuppressWarnings("unchecked")
        Map<String, ComponentInstance> instances = (Map<String, ComponentInstance>)weapon.get(factory);
        return instances.keySet();
    } catch (Exception e) {
        throw new RuntimeException("cannot get factory created instances", e);
    } finally {
        if (weapon != null) {
            weapon.setAccessible(false);
        }
    }
}
 
开发者ID:ow2-chameleon,项目名称:everest,代码行数:17,代码来源:FactoryResource.java

示例7: getFactoryReference

import org.apache.felix.ipojo.Factory; //导入依赖的package包/类
public ServiceReference<Factory> getFactoryReference(String name, String version) {
    // Scientifically build the selection filter.
    String filter = "(&(factory.name=" + name + ")";
    if (version != null) {
        filter += "(factory.version=" + version + ")";
    } else {
        filter += "(!(factory.version=*))";
    }
    filter += ")";
    Collection<ServiceReference<Factory>> refs;
    try {
        refs = context.getServiceReferences(Factory.class, filter);
    } catch (InvalidSyntaxException e) {
        // Should never happen!
        throw new AssertionError(e);
    }
    if (refs.isEmpty()) {
        return null;
    } else if (refs.size() > 1) {
        // Should never happen!
        throw new AssertionError("multiple factory service with same name/version: " + name + "/" + version);
    }
    return refs.iterator().next();
}
 
开发者ID:ow2-chameleon,项目名称:everest,代码行数:25,代码来源:EverestIpojoTestCommon.java

示例8: killFactory

import org.apache.felix.ipojo.Factory; //导入依赖的package包/类
private boolean killFactory(String name, String version) throws InvalidSyntaxException {
    Factory factory = getFactory(name, version);
    if (factory == null) {
        return false;
    }

    IPojoFactory f = (IPojoFactory) factory;
    Method weapon = null;
    try {
        weapon = IPojoFactory.class.getDeclaredMethod("dispose");
        weapon.setAccessible(true);
        // FATALITY!!!
        weapon.invoke(f);
    } catch (Exception e) {
        throw new IllegalStateException("cannot kill factory", e);
    } finally {
        // It's a bad idea to let kids play with such a weapon...
        if (weapon != null) {
            weapon.setAccessible(false);
        }
    }
    return true;
}
 
开发者ID:ow2-chameleon,项目名称:everest,代码行数:24,代码来源:EverestIpojoTestCommon.java

示例9: instantiateAMPQPlaform

import org.apache.felix.ipojo.Factory; //导入依赖的package包/类
@Before
public void instantiateAMPQPlaform() {

    ipojoHelper = new IPOJOHelper(bundleContext);

    Properties linker = new Properties();
    linker.put(FILTER_IMPORTDECLARATION_PROPERTY, "(id=*)");
    linker.put(FILTER_IMPORTERSERVICE_PROPERTY, "(instance.name=MQTTImporter)");
    linker.put(Factory.INSTANCE_NAME_PROPERTY, "MQTTLinker");

    linkerComponentInstance = ipojoHelper.createComponentInstance(FuchsiaConstants.DEFAULT_IMPORTATION_LINKER_FACTORY_NAME, linker);

    Properties importer = new Properties();
    importer.put(FILTER_IMPORTDECLARATION_PROPERTY, "(id=*)");
    importer.put("target", "(id=*)");
    importer.put(Factory.INSTANCE_NAME_PROPERTY, "MQTTImporter");

    importerComponentInstance = ipojoHelper.createComponentInstance("org.ow2.chameleon.fuchsia.importer.mqtt.MQTTImporter", importer);

}
 
开发者ID:ow2-chameleon,项目名称:fuchsia,代码行数:21,代码来源:MQTTMessageCaptureTest.java

示例10: unbind

import org.apache.felix.ipojo.Factory; //导入依赖的package包/类
public void unbind(ServiceReference serviceReference) {
    synchronized (lock) {
        if (!serviceReferencesHandled.containsKey(fetchServiceId(serviceReference))) {
            serviceReferencesBound.remove(fetchServiceId(serviceReference));
        } else {

            /**
             * Pay attention to this line, this may produce undesired behaviour
             */

            String name = (String) serviceReference.getProperty(Factory.INSTANCE_NAME_PROPERTY);
            LOG.warn(name + " want to unbound a declaration that it is still handling.");
            throw new IllegalStateException(name + " want to unbound a declaration that it is still handling.");

        }
    }
}
 
开发者ID:ow2-chameleon,项目名称:fuchsia,代码行数:18,代码来源:DeclarationImpl.java

示例11: initMocks

import org.apache.felix.ipojo.Factory; //导入依赖的package包/类
/**
 * Inits the mocks.
 */
@SuppressWarnings("unchecked")
@BeforeMethod
public void initMocks() {
    messageConsumerFactoryMock = EasyMock.createMock(Factory.class);
    testHandlerMock = EasyMock.createMock(CommunoteMessageHandler.class);
    messageConsumersMock = EasyMock.createMock(Map.class);
}
 
开发者ID:Communote,项目名称:communote-server,代码行数:11,代码来源:ProviderMessageConsumerFactoryTest.java

示例12: startComponent

import org.apache.felix.ipojo.Factory; //导入依赖的package包/类
/**
 * Starts the multicast broadcaster iPOJO component according to system
 * properties
 */
private void startComponent() {

    if (pInstance != null) {
        pLogger.log(LogService.LOG_ERROR, "Can't run component twice");
        return;
    }

    // Set up properties
    final Dictionary<String, String> props = new Hashtable<>();
    props.put(Factory.INSTANCE_NAME_PROPERTY,
            getProperty(SYSPROP_NAME, DEFAULT_NAME));
    props.put(PROP_GROUP, getProperty(SYSPROP_GROUP, DEFAULT_GROUP));
    props.put(PROP_PORT, getProperty(SYSPROP_PORT, DEFAULT_PORT));
    props.put(PROP_DISCOVER_LOCAL_PEERS, 
    		getProperty(SYSPROP_DISCOVER_LOCAL_PEERS, DEFAULT_DISCOVER_LOCAL_PEERS));
    try {
        // Create the instance
        pInstance = pMulticastFactory.createComponentInstance(props);

        String logStr = "Herald Multicast discovery instantiated: "
                + pInstance;
        if (pInstance instanceof InstanceManager) {
            // Try to grab more details
            final InstanceManager instMan = (InstanceManager) pInstance;
            final Object realComponent = instMan.getPojoObject();
            logStr += " - " + realComponent;
        }
        pLogger.log(LogService.LOG_DEBUG, logStr);

    } catch (UnacceptableConfiguration | MissingHandlerException
            | ConfigurationException ex) {
        // What a Terrible Failure
        pLogger.log(LogService.LOG_ERROR,
                "Multicast broadcaster instantiation error: " + ex, ex);
    }
}
 
开发者ID:cohorte,项目名称:cohorte-herald,代码行数:41,代码来源:MulticastStarter.java

示例13: createMachine

import org.apache.felix.ipojo.Factory; //导入依赖的package包/类
@Override
public String createMachine( TargetHandlerParameters parameters ) throws TargetException {

	this.logger.fine( "Creating a new agent in memory." );
	Map<String,String> targetProperties = preventNull( parameters.getTargetProperties());

	// Need to wait?
	try {
		String delayAsString = targetProperties.get( DELAY );
		long delay = delayAsString != null ? Long.parseLong( delayAsString ) : this.defaultDelay.get();
		if( delay > 0 )
			Thread.sleep( delay );

	} catch( Exception e ) {
		this.logger.warning( "An error occurred while applying the delay property. " + e.getMessage());
		Utils.logException( this.logger, e );
	}

	String machineId = parameters.getScopedInstancePath() + " @ " + parameters.getApplicationName();
	Factory factory = findIPojoFactory( parameters );
	createIPojo(
			targetProperties,
			parameters.getMessagingProperties(),
			machineId,
			parameters.getScopedInstancePath(),
			parameters.getApplicationName(),
			parameters.getDomain(),
			factory );

	return machineId;
}
 
开发者ID:roboconf,项目名称:roboconf-platform,代码行数:32,代码来源:InMemoryHandler.java

示例14: isMachineRunning

import org.apache.felix.ipojo.Factory; //导入依赖的package包/类
@Override
public boolean isMachineRunning( TargetHandlerParameters parameters, String machineId )
throws TargetException {

	this.logger.fine( "Verifying the in-memory agent for " + machineId + " is running." );
	Map<String,String> targetProperties = preventNull( parameters.getTargetProperties());

	// No agent factory => no iPojo instance => not running
	boolean result = false;
	if( this.standardAgentFactory != null )
		result = this.standardAgentFactory.getInstancesNames().contains( machineId );

	// On restoration, in-memory agents will ALL have disappeared.
	// So, it makes sense to recreate them if they do not exist anymore.
	// To determine whether we should restore them or no, we look for the model in the manager.
	if( ! result && ! simulatePlugins( targetProperties )) {

		Map.Entry<String,String> ctx = parseMachineId( machineId );
		ManagedApplication ma = this.manager.applicationMngr().findManagedApplicationByName( ctx.getValue());
		Instance scopedInstance = InstanceHelpers.findInstanceByPath( ma.getApplication(), ctx.getKey());

		// Is it supposed to be running?
		if( scopedInstance.getStatus() != InstanceStatus.NOT_DEPLOYED ) {
			this.logger.fine( "In-memory agent for " + machineId + " is supposed to be running but is not. It will be restored." );
			Map<String,String> messagingConfiguration = this.manager.messagingMngr().getMessagingClient().getConfiguration();
			Factory factory = findIPojoFactory( parameters );
			createIPojo( targetProperties, messagingConfiguration, machineId, ctx.getKey(), ctx.getValue(), this.manager.getDomain(), factory );
			result = true;
			// The agent will restore its model by asking it to the DM.
		}
	}

	return result;
}
 
开发者ID:roboconf,项目名称:roboconf-platform,代码行数:35,代码来源:InMemoryHandler.java

示例15: terminateMachine

import org.apache.felix.ipojo.Factory; //导入依赖的package包/类
@Override
public void terminateMachine( TargetHandlerParameters parameters, String machineId ) throws TargetException {

	this.logger.fine( "Terminating an in-memory agent." );
	Map<String,String> targetProperties = preventNull( parameters.getTargetProperties());

	// If we executed real recipes, undeploy everything first.
	// That's because we do not really terminate the agent's machine, we just kill the agent.
	// So, it is important to stop and undeploy properly.
	if( ! simulatePlugins( targetProperties )) {
		this.logger.fine( "Stopping instances correctly (real recipes are used)." );
		Map.Entry<String,String> ctx = parseMachineId( machineId );
		ManagedApplication ma = this.manager.applicationMngr().findManagedApplicationByName( ctx.getValue());

		// We do not want to undeploy the scoped instances, but its children.
		try {
			Instance scopedInstance = InstanceHelpers.findInstanceByPath( ma.getApplication(), ctx.getKey());
			for( Instance childrenInstance : scopedInstance.getChildren())
				this.manager.instancesMngr().changeInstanceState( ma, childrenInstance, InstanceStatus.NOT_DEPLOYED );

		} catch( IOException e ) {
			throw new TargetException( e );
		}
	}

	// Destroy the IPojo
	Factory factory = findIPojoFactory( parameters );
	deleteIPojo( factory, machineId );
}
 
开发者ID:roboconf,项目名称:roboconf-platform,代码行数:30,代码来源:InMemoryHandler.java


注:本文中的org.apache.felix.ipojo.Factory类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。