本文整理汇总了Java中org.springframework.core.InfrastructureProxy类的典型用法代码示例。如果您正苦于以下问题:Java InfrastructureProxy类的具体用法?Java InfrastructureProxy怎么用?Java InfrastructureProxy使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
InfrastructureProxy类属于org.springframework.core包,在下文中一共展示了InfrastructureProxy类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testSpringInfrastructureProxyOnImportersWithTheSameRef
import org.springframework.core.InfrastructureProxy; //导入依赖的package包/类
public void testSpringInfrastructureProxyOnImportersWithTheSameRef() throws Exception {
Object service = new Object();
ServiceInvoker invokerA = new ServiceStaticInterceptor(createObjectTrackingBundleContext(service), ref);
ServiceInvoker invokerB = new ServiceStaticInterceptor(createObjectTrackingBundleContext(service), ref);
InfrastructureProxy proxyA = new InfrastructureOsgiProxyAdvice(invokerA);
InfrastructureProxy proxyB = new InfrastructureOsgiProxyAdvice(invokerB);
// though this is not normal, we want the interceptors to be different to make sure the wrapped object
// gets properly delegated
assertFalse("invokers should not be equal (they have different bundle contexts)", invokerA.equals(invokerB));
assertFalse("proxies should not be equal", proxyA.equals(proxyB));
assertSame(proxyA.getWrappedObject(), proxyB.getWrappedObject());
}
示例2: testProxyForUnaryCardinality
import org.springframework.core.InfrastructureProxy; //导入依赖的package包/类
public void testProxyForUnaryCardinality() throws Exception {
long time = 1234;
Date date = new Date(time);
ServiceRegistration reg = publishService(date);
fb.setAvailability(Availability.MANDATORY);
fb.setInterfaces(new Class<?>[] { Date.class });
fb.afterPropertiesSet();
ImportedOsgiServiceProxy refAware = null;
try {
Object result = fb.getObject();
assertTrue(result instanceof Date);
// check it's our object
assertEquals(time, ((Date) result).getTime());
assertTrue(result instanceof SpringProxy);
assertTrue(result instanceof ImportedOsgiServiceProxy);
assertTrue(result instanceof InfrastructureProxy);
refAware = (ImportedOsgiServiceProxy) result;
assertNotNull(refAware.getServiceReference());
assertEquals("wrong target returned", date, ((InfrastructureProxy) result).getWrappedObject());
}
finally {
if (reg != null)
reg.unregister();
}
// test reference after the service went down
assertNotNull(refAware.getServiceReference());
assertNull(refAware.getServiceReference().getBundle());
}
示例3: testServiceReferenceProperties
import org.springframework.core.InfrastructureProxy; //导入依赖的package包/类
public void testServiceReferenceProperties() throws Exception {
long time = 1234;
Date date = new Date(time);
Dictionary dict = new Properties();
dict.put("foo", "bar");
dict.put("george", "michael");
ServiceRegistration reg = publishService(date, dict);
fb.setAvailability(Availability.MANDATORY);
fb.setFilter("(&(foo=bar)(george=michael))");
fb.setInterfaces(new Class<?>[] { Date.class });
fb.afterPropertiesSet();
try {
Object result = fb.getObject();
assertTrue(result instanceof Date);
// check it's our object
assertEquals(time, ((Date) result).getTime());
ImportedOsgiServiceProxy refAware = (ImportedOsgiServiceProxy) result;
assertTrue(doesMapContainsDictionary(dict,
OsgiServiceReferenceUtils.getServicePropertiesAsMap(refAware.getServiceReference())));
InfrastructureProxy targetAware = (InfrastructureProxy) result;
assertEquals(date, targetAware.getWrappedObject());
}
finally {
if (reg != null)
reg.unregister();
}
}
示例4: testSpringInfrastructureProxyOnImportersWithDifferentRefs
import org.springframework.core.InfrastructureProxy; //导入依赖的package包/类
public void testSpringInfrastructureProxyOnImportersWithDifferentRefs() throws Exception {
Object service = new Object();
BundleContext ctx = createObjectTrackingBundleContext(service);
ServiceInvoker invokerA = new ServiceStaticInterceptor(ctx, new MockServiceReference());
ServiceInvoker invokerB = new ServiceStaticInterceptor(ctx, new MockServiceReference());
InfrastructureProxy proxyA = new InfrastructureOsgiProxyAdvice(invokerA);
InfrastructureProxy proxyB = new InfrastructureOsgiProxyAdvice(invokerB);
assertFalse("invokers should not be equal (they have different service references)", invokerA.equals(invokerB));
assertFalse("proxies should not be equal", proxyA.equals(proxyB));
assertFalse("target objects should not be equal", proxyA.getWrappedObject().equals(proxyB.getWrappedObject()));
}
示例5: testNakedTargetPropertyReturnedByTheInfrastructureProxy
import org.springframework.core.InfrastructureProxy; //导入依赖的package包/类
public void testNakedTargetPropertyReturnedByTheInfrastructureProxy() throws Exception {
Object service = new Object();
ServiceInvoker invoker = new ServiceStaticInterceptor(createObjectTrackingBundleContext(service), ref);
InfrastructureProxy proxy = new InfrastructureOsgiProxyAdvice(invoker);
assertSame(TestUtils.invokeMethod(invoker, "getTarget", null), proxy.getWrappedObject());
assertSame(service, proxy.getWrappedObject());
}
示例6: testCreatedProxy
import org.springframework.core.InfrastructureProxy; //导入依赖的package包/类
public void testCreatedProxy() throws Exception {
MockServiceReference ref = new MockServiceReference();
Object proxy = proxyCreator.createServiceProxy(ref).proxy;
assertTrue(proxy instanceof ImportedOsgiServiceProxy);
assertTrue(proxy instanceof InfrastructureProxy);
}
示例7: unwrapResourceIfNecessary
import org.springframework.core.InfrastructureProxy; //导入依赖的package包/类
/**
* Unwrap the given resource handle if necessary; otherwise return
* the given handle as-is.
* @see org.springframework.core.InfrastructureProxy#getWrappedObject()
*/
static Object unwrapResourceIfNecessary(Object resource) {
Assert.notNull(resource, "Resource must not be null");
Object resourceRef = resource;
// unwrap infrastructure proxy
if (resourceRef instanceof InfrastructureProxy) {
resourceRef = ((InfrastructureProxy) resourceRef).getWrappedObject();
}
if (aopAvailable) {
// now unwrap scoped proxy
resourceRef = ScopedProxyUnwrapper.unwrapIfNecessary(resourceRef);
}
return resourceRef;
}
示例8: testProxyForUnaryCardinality
import org.springframework.core.InfrastructureProxy; //导入依赖的package包/类
public void testProxyForUnaryCardinality() throws Exception {
long time = 1234;
Date date = new Date(time);
ServiceRegistration reg = publishService(date);
fb.setCardinality(Cardinality.C_1__1);
fb.setInterfaces(new Class[] { Date.class });
fb.afterPropertiesSet();
ImportedOsgiServiceProxy refAware = null;
try {
Object result = fb.getObject();
assertTrue(result instanceof Date);
// check it's our object
assertEquals(time, ((Date) result).getTime());
assertTrue(result instanceof SpringProxy);
assertTrue(result instanceof ImportedOsgiServiceProxy);
assertTrue(result instanceof InfrastructureProxy);
refAware = (ImportedOsgiServiceProxy) result;
assertNotNull(refAware.getServiceReference());
assertEquals("wrong target returned", date, ((InfrastructureProxy) result).getWrappedObject());
}
finally {
if (reg != null)
reg.unregister();
}
// test reference after the service went down
assertNotNull(refAware.getServiceReference());
assertNull(refAware.getServiceReference().getBundle());
}
示例9: testServiceReferenceProperties
import org.springframework.core.InfrastructureProxy; //导入依赖的package包/类
public void testServiceReferenceProperties() throws Exception {
long time = 1234;
Date date = new Date(time);
Dictionary dict = new Properties();
dict.put("foo", "bar");
dict.put("george", "michael");
ServiceRegistration reg = publishService(date, dict);
fb.setCardinality(Cardinality.C_1__1);
fb.setFilter("(&(foo=bar)(george=michael))");
fb.setInterfaces(new Class[] { Date.class });
fb.afterPropertiesSet();
try {
Object result = fb.getObject();
assertTrue(result instanceof Date);
// check it's our object
assertEquals(time, ((Date) result).getTime());
ImportedOsgiServiceProxy refAware = (ImportedOsgiServiceProxy) result;
assertTrue(doesMapContainsDictionary(dict,
OsgiServiceReferenceUtils.getServicePropertiesAsMap(refAware.getServiceReference())));
InfrastructureProxy targetAware = (InfrastructureProxy) result;
assertEquals(date, targetAware.getWrappedObject());
}
finally {
if (reg != null)
reg.unregister();
}
}
示例10: testFactoryBeanForMultipleServicesAsClasses
import org.springframework.core.InfrastructureProxy; //导入依赖的package包/类
public void testFactoryBeanForMultipleServicesAsClasses() throws Exception {
fb.setAvailability(Availability.OPTIONAL);
fb.setInterfaces(new Class<?>[] { Date.class });
fb.afterPropertiesSet();
List registrations = new ArrayList(3);
long time = 321;
Date dateA = new Date(time);
try {
Object result = fb.getObject();
assertTrue(result instanceof Collection);
Collection col = (Collection) result;
assertTrue(col.isEmpty());
Iterator iter = col.iterator();
assertFalse(iter.hasNext());
registrations.add(publishService(dateA));
try {
iter.next();
fail("should have thrown exception");
}
catch (NoSuchElementException ex) {
// expected
}
assertTrue(iter.hasNext());
Object service = iter.next();
assertTrue(service instanceof Date);
assertEquals(time, ((Date) service).getTime());
assertEquals(dateA, ((InfrastructureProxy) service).getWrappedObject());
assertFalse(iter.hasNext());
time = 111;
Date dateB = new Date(time);
registrations.add(publishService(dateB));
assertTrue(iter.hasNext());
service = iter.next();
assertTrue(service instanceof Date);
assertEquals(time, ((Date) service).getTime());
assertFalse(dateA.equals(((InfrastructureProxy) service).getWrappedObject()));
assertEquals(dateB, ((InfrastructureProxy) service).getWrappedObject());
}
finally {
cleanRegistrations(registrations);
}
}
示例11: testIteratorWhenServiceGoesDown
import org.springframework.core.InfrastructureProxy; //导入依赖的package包/类
public void testIteratorWhenServiceGoesDown() throws Exception {
fb.setAvailability(Availability.OPTIONAL);
fb.setInterfaces(new Class<?>[] { Date.class });
fb.afterPropertiesSet();
long time = 123;
Date date = new Date(time);
Properties props = new Properties();
props.put("Moroccan", "Sunset");
List registrations = new ArrayList(3);
try {
Collection col = (Collection) fb.getObject();
Iterator iter = col.iterator();
assertFalse(iter.hasNext());
registrations.add(publishService(date, props));
assertTrue(iter.hasNext());
// deregister service
((ServiceRegistration) registrations.remove(0)).unregister();
// has to successed
Object obj = iter.next();
assertTrue(obj instanceof ImportedOsgiServiceProxy);
assertTrue(obj instanceof Date);
assertTrue(obj instanceof InfrastructureProxy);
// the properties will contain the ObjectClass also
assertEquals(((ImportedOsgiServiceProxy) obj).getServiceReference().getProperty("Moroccan"), "Sunset");
try {
// make sure the service is dead
((Date) obj).getTime();
fail("should have thrown exception");
}
catch (ServiceUnavailableException ex) {
// proxy is dead
}
}
finally {
cleanRegistrations(registrations);
}
}
示例12: testProxyForMultipleCardinality
import org.springframework.core.InfrastructureProxy; //导入依赖的package包/类
public void testProxyForMultipleCardinality() throws Exception {
fb.setAvailability(Availability.OPTIONAL);
fb.setInterfaces(new Class<?>[] { Date.class });
fb.afterPropertiesSet();
List registrations = new ArrayList(3);
long time = 321;
Date dateA = new Date(time);
try {
Object result = fb.getObject();
assertTrue(result instanceof Collection);
Collection col = (Collection) result;
assertTrue(col.isEmpty());
Iterator iter = col.iterator();
assertFalse(iter.hasNext());
registrations.add(publishService(dateA));
assertTrue(iter.hasNext());
Object service = iter.next();
assertTrue(service instanceof Date);
assertEquals(time, ((Date) service).getTime());
assertTrue(service instanceof ImportedOsgiServiceProxy);
assertNotNull(((ImportedOsgiServiceProxy) service).getServiceReference());
assertSame(dateA, ((InfrastructureProxy) service).getWrappedObject());
assertFalse(iter.hasNext());
time = 111;
Date dateB = new Date(time);
registrations.add(publishService(dateB));
assertTrue(iter.hasNext());
service = iter.next();
assertTrue(service instanceof Date);
assertEquals(time, ((Date) service).getTime());
assertTrue(service instanceof ImportedOsgiServiceProxy);
assertNotNull(((ImportedOsgiServiceProxy) service).getServiceReference());
assertTrue(service instanceof InfrastructureProxy);
assertSame(dateB, ((InfrastructureProxy) service).getWrappedObject());
}
finally {
for (int i = 0; i < registrations.size(); i++) {
((ServiceRegistration) registrations.get(i)).unregister();
}
}
}
示例13: testFactoryBeanForMultipleServicesAsClasses
import org.springframework.core.InfrastructureProxy; //导入依赖的package包/类
public void testFactoryBeanForMultipleServicesAsClasses() throws Exception {
fb.setCardinality(Cardinality.C_0__N);
fb.setInterfaces(new Class[] { Date.class });
fb.afterPropertiesSet();
List registrations = new ArrayList(3);
long time = 321;
Date dateA = new Date(time);
try {
Object result = fb.getObject();
assertTrue(result instanceof Collection);
Collection col = (Collection) result;
assertTrue(col.isEmpty());
Iterator iter = col.iterator();
assertFalse(iter.hasNext());
registrations.add(publishService(dateA));
try {
iter.next();
fail("should have thrown exception");
}
catch (NoSuchElementException ex) {
// expected
}
assertTrue(iter.hasNext());
Object service = iter.next();
assertTrue(service instanceof Date);
assertEquals(time, ((Date) service).getTime());
assertEquals(dateA, ((InfrastructureProxy) service).getWrappedObject());
assertFalse(iter.hasNext());
time = 111;
Date dateB = new Date(time);
registrations.add(publishService(dateB));
assertTrue(iter.hasNext());
service = iter.next();
assertTrue(service instanceof Date);
assertEquals(time, ((Date) service).getTime());
assertFalse(dateA.equals(((InfrastructureProxy) service).getWrappedObject()));
assertEquals(dateB, ((InfrastructureProxy) service).getWrappedObject());
}
finally {
cleanRegistrations(registrations);
}
}
示例14: testIteratorWhenServiceGoesDown
import org.springframework.core.InfrastructureProxy; //导入依赖的package包/类
public void testIteratorWhenServiceGoesDown() throws Exception {
fb.setCardinality(Cardinality.C_0__N);
fb.setInterfaces(new Class[] { Date.class });
fb.afterPropertiesSet();
long time = 123;
Date date = new Date(time);
Properties props = new Properties();
props.put("Moroccan", "Sunset");
List registrations = new ArrayList(3);
try {
Collection col = (Collection) fb.getObject();
Iterator iter = col.iterator();
assertFalse(iter.hasNext());
registrations.add(publishService(date, props));
assertTrue(iter.hasNext());
// deregister service
((ServiceRegistration) registrations.remove(0)).unregister();
// has to successed
Object obj = iter.next();
assertTrue(obj instanceof ImportedOsgiServiceProxy);
assertTrue(obj instanceof Date);
assertTrue(obj instanceof InfrastructureProxy);
// the properties will contain the ObjectClass also
assertEquals(((ImportedOsgiServiceProxy) obj).getServiceReference().getProperty("Moroccan"), "Sunset");
try {
// make sure the service is dead
((Date) obj).getTime();
fail("should have thrown exception");
}
catch (ServiceUnavailableException ex) {
// proxy is dead
}
}
finally {
cleanRegistrations(registrations);
}
}
示例15: testProxyForMultipleCardinality
import org.springframework.core.InfrastructureProxy; //导入依赖的package包/类
public void testProxyForMultipleCardinality() throws Exception {
fb.setCardinality(Cardinality.C_0__N);
fb.setInterfaces(new Class[] { Date.class });
fb.afterPropertiesSet();
List registrations = new ArrayList(3);
long time = 321;
Date dateA = new Date(time);
try {
Object result = fb.getObject();
assertTrue(result instanceof Collection);
Collection col = (Collection) result;
assertTrue(col.isEmpty());
Iterator iter = col.iterator();
assertFalse(iter.hasNext());
registrations.add(publishService(dateA));
assertTrue(iter.hasNext());
Object service = iter.next();
assertTrue(service instanceof Date);
assertEquals(time, ((Date) service).getTime());
assertTrue(service instanceof ImportedOsgiServiceProxy);
assertNotNull(((ImportedOsgiServiceProxy) service).getServiceReference());
assertSame(dateA, ((InfrastructureProxy) service).getWrappedObject());
assertFalse(iter.hasNext());
time = 111;
Date dateB = new Date(time);
registrations.add(publishService(dateB));
assertTrue(iter.hasNext());
service = iter.next();
assertTrue(service instanceof Date);
assertEquals(time, ((Date) service).getTime());
assertTrue(service instanceof ImportedOsgiServiceProxy);
assertNotNull(((ImportedOsgiServiceProxy) service).getServiceReference());
assertTrue(service instanceof InfrastructureProxy);
assertSame(dateB, ((InfrastructureProxy) service).getWrappedObject());
}
finally {
for (int i = 0; i < registrations.size(); i++) {
((ServiceRegistration) registrations.get(i)).unregister();
}
}
}