本文整理汇总了Java中org.apache.felix.ipojo.architecture.Architecture类的典型用法代码示例。如果您正苦于以下问题:Java Architecture类的具体用法?Java Architecture怎么用?Java Architecture使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Architecture类属于org.apache.felix.ipojo.architecture包,在下文中一共展示了Architecture类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: execute
import org.apache.felix.ipojo.architecture.Architecture; //导入依赖的package包/类
@Override
public Object execute() throws Exception {
ShellTable table = new ShellTable();
table.column("Name");
table.column("Bundle Id");
table.column("State");
for (Architecture architecture : managerService.getArchitectures()) {
InstanceDescription instanceDescription = architecture.getInstanceDescription();
if (verbose || instanceDescription.getState() != ComponentInstance.DISPOSED) {
table.addRow().addContent(instanceDescription.getName(), instanceDescription.getBundleId(), IPojoManagerService.instanceDescriptionState(instanceDescription.getState()));
}
}
table.print(System.out);
return null;
}
示例2: adaptTo
import org.apache.felix.ipojo.architecture.Architecture; //导入依赖的package包/类
@Override
public <A> A adaptTo(Class<A> clazz) {
if (clazz == Architecture.class) {
// Returns null if reference has been released
return clazz.cast(m_instance.get());
} else if (clazz == ComponentInstance.class) {
// Returns null if reference has been released
Architecture a = m_instance.get();
if (a == null) {
return null;
} else {
return clazz.cast(getComponentInstance(a));
}
} else {
return super.adaptTo(clazz);
}
}
示例3: getArchitectureReference
import org.apache.felix.ipojo.architecture.Architecture; //导入依赖的package包/类
public ServiceReference<Architecture> getArchitectureReference(String instance) {
// Scientifically build the selection filter.
String filter = "(architecture.instance=" + instance + ")";
Collection<ServiceReference<Architecture>> refs;
try {
refs = context.getServiceReferences(Architecture.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 architecture service with same instance: " + instance);
}
return refs.iterator().next();
}
示例4: getInvalidControllers
import org.apache.felix.ipojo.architecture.Architecture; //导入依赖的package包/类
private List<InstanceDescription> getInvalidControllers() {
List<InstanceDescription> invalid = new ArrayList<>();
for (Architecture architecture : architectures) {
final InstanceDescription description = architecture.getInstanceDescription();
// Is it invalid ?
if (description.getState() == ComponentInstance.INVALID) {
// Is it a controller
ProvidedServiceHandlerDescription hd = (ProvidedServiceHandlerDescription)
description.getHandlerDescription("org.apache.felix.ipojo:provides");
if (hd != null) {
for (ProvidedServiceDescription psd : hd.getProvidedServices()) {
if (Arrays.asList(psd.getServiceSpecifications()).contains(org.wisdom.api.Controller.class
.getName())) {
invalid.add(description);
}
}
}
}
}
return invalid;
}
示例5: testInstanceModel
import org.apache.felix.ipojo.architecture.Architecture; //导入依赖的package包/类
@Test
public void testInstanceModel() {
InstanceDescription description = mock(InstanceDescription.class);
when(description.getName()).thenReturn("my-instance");
when(description.getDescription()).thenReturn(new Element("instance", null));
when(description.getState()).thenReturn(ComponentInstance.VALID);
Architecture arch = mock(Architecture.class);
when(arch.getInstanceDescription()).thenReturn(description);
InstanceModel model = new InstanceModel(arch);
assertThat(model.getName()).isEqualTo("my-instance");
assertThat(model.getState()).isEqualTo("VALID");
assertThat(model.getArchitecture()).contains("instance");
// Check the other state.
when(description.getState()).thenReturn(ComponentInstance.INVALID);
assertThat(model.getState()).isEqualTo("INVALID");
when(description.getState()).thenReturn(ComponentInstance.STOPPED);
assertThat(model.getState()).isEqualTo("STOPPED");
when(description.getState()).thenReturn(28);
assertThat(model.getState()).isEqualTo("UNKNOWN");
}
示例6: dumpArchitecture
import org.apache.felix.ipojo.architecture.Architecture; //导入依赖的package包/类
public static void dumpArchitecture(BundleContext context) {
OSGiHelper helper = new OSGiHelper(context);
StringBuilder builder = new StringBuilder();
try {
for (Architecture arch : helper.getServiceObjects(Architecture.class)) {
InstanceDescription description = arch.getInstanceDescription();
builder.append("Instance : ").append(description.getName()).append(" - ").append(formatInstanceState
(description.getState())).append("\n");
builder.append(description.getDescription().toString());
builder.append("\n---------------------------------------\n");
}
} finally {
helper.dispose();
}
System.out.println(builder.toString());
}
示例7: getInstanceDescription
import org.apache.felix.ipojo.architecture.Architecture; //导入依赖的package包/类
@Override
public InstanceDescription getInstanceDescription(Object instance) {
for (Architecture architecture : architectures) {
if (architecture.getInstanceDescription().getState() == ComponentInstance.VALID) {
if (architecture.getInstanceDescription().getInstance() instanceof InstanceManager) {
InstanceManager instanceManager = (InstanceManager) architecture.getInstanceDescription().getInstance();
if (Arrays.asList(instanceManager.getPojoObjects()).contains(instance)) {
return architecture.getInstanceDescription();
}
}
}
}
return null;
}
示例8: getComponentInstance
import org.apache.felix.ipojo.architecture.Architecture; //导入依赖的package包/类
public static ComponentInstance getComponentInstance(Architecture arch) {
Field shunt = null;
try {
shunt = InstanceDescription.class.getDeclaredField("m_instance");
shunt.setAccessible(true);
return (ComponentInstance) shunt.get(arch.getInstanceDescription());
} catch (Exception e) {
throw new IllegalStateException("cannot get component instance", e);
} finally {
if (shunt != null) {
shunt.setAccessible(false);
}
}
}
示例9: getMetadata
import org.apache.felix.ipojo.architecture.Architecture; //导入依赖的package包/类
@Override
public ResourceMetadata getMetadata() {
Architecture i = m_instance.get();
ResourceMetadata m = super.getMetadata();
if (i == null) {
// Reference has been released
return m;
}
// Add dynamic metadata
return new ImmutableResourceMetadata.Builder(m)
.set("state", stateAsString(i.getInstanceDescription().getState())) // String
.set("configuration", getInstanceConfiguration(i.getInstanceDescription())) // ResourceMetadata
.build();
}
示例10: delete
import org.apache.felix.ipojo.architecture.Architecture; //导入依赖的package包/类
@Override
public Resource delete(Request request) throws IllegalActionOnResourceException {
Architecture a = m_instance.get();
if (a == null) {
throw new IllegalActionOnResourceException(request, this, "Architecture has gone");
}
// The instance must be destroyed
getComponentInstance(a).dispose();
// At this point, this resource must have been set to a stale state!
return this;
}
示例11: cleanup
import org.apache.felix.ipojo.architecture.Architecture; //导入依赖的package包/类
public void cleanup() {
Architecture a = m_instance.get();
if (a == null) {
return;
}
getComponentInstance(a).removeInstanceStateListener(this);
ConfigurationHandlerDescription chd = (ConfigurationHandlerDescription)
a.getInstanceDescription().getHandlerDescription("org.apache.felix.ipojo:properties");
if (chd != null) {
chd.addListener(this);
}
}
示例12: testReadInstanceDeclaredFoo123
import org.apache.felix.ipojo.architecture.Architecture; //导入依赖的package包/类
/**
* Read /ipojo/instance
*/
@Test
public void testReadInstanceDeclaredFoo123() throws ResourceNotFoundException, IllegalActionOnResourceException {
Resource r = read("/ipojo/instance/DeclaredFoo123");
// Resource should be observable
assertThat(r.isObservable()).isTrue();
ResourceMetadata m = r.getMetadata();
// Check name, factory
assertThat(m.get("name")).isEqualTo("DeclaredFoo123");
assertThat(m.get("factory.name")).isEqualTo("Foo");
assertThat(m.get("factory.version")).isEqualTo("1.2.3.foo");
// Check state
assertThat(m.get("state")).isEqualTo("valid");
//TODO Check more metadata, as soon as more metadata are provided...
// Check adaptations
assertThat(r.adaptTo(Architecture.class)).isSameAs(getArchitecture("DeclaredFoo123"));
assertThat(r.adaptTo(ComponentInstance.class)).isSameAs(getComponentInstance("DeclaredFoo123"));
// Check relation on factory resource
assertThatResource(r).hasRelation(RelationFilters.and(
RelationFilters.hasName("factory"),
RelationFilters.hasAction(READ),
RelationFilters.hasHref("/ipojo/factory/Foo/1.2.3.foo")));
// Check relation on Architecture service
assertThatResource(r).hasRelation(RelationFilters.and(
RelationFilters.hasName("service"),
RelationFilters.hasAction(READ),
RelationFilters.hasHref("/osgi/services/" + getArchitectureReference("DeclaredFoo123").getProperty(Constants.SERVICE_ID))));
}
示例13: testReconfiguration
import org.apache.felix.ipojo.architecture.Architecture; //导入依赖的package包/类
/**
* Update /ipojo/instance/Foo-2001 with "configuration" parameter.
*/
@Test
public void testReconfiguration() throws ResourceNotFoundException, IllegalActionOnResourceException {
// Wait because sometime... once upon a time...
osgiHelper.waitForService(Architecture.class.getName(), "(architecture.instance=Foo-2001)", 1000, true);
// Reconfigure the instance and check
Map<String, Object> configuration = new HashMap<String, Object>();
configuration.put("fooPrefix", "__reconfigured");
Map<String, Object> params = new HashMap<String, Object>();
params.put("configuration", configuration);
Resource r = everest.process(new DefaultRequest(UPDATE, Path.from("/ipojo/instance/Foo-2001"), params));
assertThat(r.getMetadata().get("configuration", Map.class).get("fooPrefix")).isEqualTo("__reconfigured");
}
示例14: getArchitecture
import org.apache.felix.ipojo.architecture.Architecture; //导入依赖的package包/类
public Architecture getArchitecture(String instance) {
ServiceReference<Architecture> ref = getArchitectureReference(instance);
if (ref == null) {
throw new AssertionError("no architecture service with same instance name: " + instance);
}
return context.getService(ref);
}
示例15: getServiceReferenceByName
import org.apache.felix.ipojo.architecture.Architecture; //导入依赖的package包/类
/**
* Returns the service reference of a service registered in the specified
* service context, offering the specified interface and having the given
* name.
*
* @param serviceContext the service context in which services are searched.
* @param itf the interface provided by the searched service.
* @param name the name of the searched service.
* @return a service registered in the specified service context, offering
* the specified interface and having the given name.
*/
public ServiceReference getServiceReferenceByName(
ServiceContext serviceContext, String itf, String name) {
String filter;
if (itf.equals(Factory.class.getName())
|| itf.equals(ManagedServiceFactory.class.getName())) {
filter = "(" + "factory.name" + "=" + name + ")";
} else if (itf.equals(Architecture.class.getName())) {
filter = "(" + "architecture.instance" + "=" + name + ")";
} else {
filter = "(" + "instance.name" + "=" + name + ")";
}
return getServiceReference(serviceContext, itf, filter);
}