@Override public StateHolder stateOf( TransientComposite composite ) { return compositeInstanceOf( composite ).state(); }
@Override public ServiceDescriptor serviceDescriptorFor( Object service ) { if( service instanceof ServiceReferenceInstance ) { ServiceReferenceInstance<?> ref = (ServiceReferenceInstance<?>) service; return ref.serviceDescriptor(); } if( service instanceof ServiceComposite ) { ServiceComposite composite = (ServiceComposite) service; return (ServiceDescriptor) compositeInstanceOf( composite ).descriptor(); } throw new IllegalArgumentException( "Wrong type. Must be subtype of " + ServiceComposite.class + " or " + ServiceReference.class ); }
@SuppressWarnings( "unchecked" ) public T proxy() { TransientComposite composite = get(); Stream<Class<?>> types = PolygeneAPI.FUNCTION_COMPOSITE_INSTANCE_OF.apply( composite ).types(); return (T) Proxy.newProxyInstance( composite.getClass().getClassLoader(), types.toArray( Class[]::new ), new ContextInvocationhandler() ); }
@Override public TemplateCollectionModel values() throws TemplateModelException { List<Object> values = PolygeneAPI.FUNCTION_COMPOSITE_INSTANCE_OF.apply( composite ) .state().properties() .map( (Function<Property<?>, Object>) objectProperty -> { try { return wrapper.wrap( objectProperty.get() ); } catch( TemplateModelException e ) { throw new IllegalStateException( e ); } } ) .collect( Collectors.toList() ); return (TemplateCollectionModel) wrapper.wrap( values ); }
(StatefulAssociationCompositeDescriptor) instance.descriptor(); AssociationStateHolder state = (AssociationStateHolder) instance.state(); StatefulAssociationValueType<?> valueType = descriptor.valueType();
try Configuration config = compositeInstance.newProxy( Configuration.class ); String serviceClass = compositeInstance.types().findFirst().get().getName(); ServiceDescriptor serviceDescriptor = spi.serviceDescriptorFor( configurableService ); ModuleDescriptor module = spi.moduleOf( configurableService );
protected <T> T role( Object object, Class<T> roleType ) { return PolygeneAPI.FUNCTION_COMPOSITE_INSTANCE_OF.apply( (Composite) object ).newProxy( roleType ); } }
public InjectionContext( CompositeInstance compositeInstance, UsesInstance uses, StateHolder state ) { this.module = compositeInstance.module(); this.compositeInstance = compositeInstance; this.uses = uses; this.state = state; }
return compositeInstanceOf( (Composite) compositeOrServiceReferenceOrUow ).module();
@Override public TemplateCollectionModel values() throws TemplateModelException { List<Object> values = PolygeneAPI.FUNCTION_COMPOSITE_INSTANCE_OF.apply( composite ) .state().properties() .map( (Function<Property<?>, Object>) objectProperty -> { try { return wrapper.wrap( objectProperty.get() ); } catch( TemplateModelException e ) { throw new IllegalStateException( e ); } } ) .collect( Collectors.toList() ); return (TemplateCollectionModel) wrapper.wrap( values ); }
(StatefulAssociationCompositeDescriptor) instance.descriptor(); AssociationStateHolder state = (AssociationStateHolder) instance.state(); StatefulAssociationValueType<?> valueType = descriptor.valueType();
try Configuration config = compositeInstance.newProxy( Configuration.class ); String serviceClass = compositeInstance.types().findFirst().get().getName(); ServiceDescriptor serviceDescriptor = spi.serviceDescriptorFor( configurableService ); ModuleDescriptor module = spi.moduleOf( configurableService );
@Override public <K> K prototypeFor( Class<K> mixinType ) { // Instantiate given value type if( prototypeInstance == null ) { prototypeInstance = model.newInstance( uses, state ); } return prototypeInstance.newProxy( mixinType ); }
@Override @SuppressWarnings( "unchecked" ) public Object map( Composite composite, Type type, String value ) { return PolygeneAPI.FUNCTION_COMPOSITE_INSTANCE_OF.apply( composite ) .module() .instance() .newValueFromSerializedState( (Class<Object>) type, value ); } }
@Override public NamedAssociation<T> apply( Composite entity ) { try { Object target = entity; if( traversedAssociation != null ) { target = traversedAssociation.apply( entity ).get(); } if( traversedManyAssociation != null ) { throw new IllegalArgumentException( "Cannot traverse ManyAssociations" ); } if( traversedNamedAssociation != null ) { throw new IllegalArgumentException( "Cannot traverse NamedAssociations" ); } CompositeInstance handler = (CompositeInstance) Proxy.getInvocationHandler( target ); return ( (AssociationStateHolder) handler.state() ).namedAssociationFor( accessor ); } catch( IllegalArgumentException e ) { throw e; } catch( Throwable e ) { throw new IllegalArgumentException( e ); } }
(StatefulAssociationCompositeDescriptor) instance.descriptor(); AssociationStateHolder state = (AssociationStateHolder) instance.state(); StatefulAssociationValueType<?> valueType = descriptor.valueType();
private static ValueStateInstance getValueStateInstance( Object value ) { return (ValueStateInstance) compositeInstanceOf( (Composite) value ).state(); } }
return compositeInstanceOf( (Composite) compositeOrServiceReference ).descriptor();
@SuppressWarnings( "unchecked" ) public T proxy() { TransientComposite composite = get(); Stream<Class<?>> types = PolygeneAPI.FUNCTION_COMPOSITE_INSTANCE_OF.apply( composite ).types(); return (T) Proxy.newProxyInstance( composite.getClass().getClassLoader(), types.toArray( Class[]::new ), new ContextInvocationhandler() ); }
@Override public Object invoke( String s, Object[] objects, String[] strings ) throws MBeanException, ReflectionException { if( s.equals( "restart" ) ) { try { // Refresh and restart if( serviceRef.isActive() ) { // Refresh configuration CompositeInstance compositeInstance = PolygeneAPI.FUNCTION_COMPOSITE_INSTANCE_OF .apply( (Composite) serviceRef.get() ); compositeInstance.newProxy( Configuration.class ).refresh(); ( (Activation) serviceRef ).passivate(); ( (Activation) serviceRef ).activate(); } return "Service restarted"; } catch( Exception e ) { return "Could not restart service:" + e.getMessage(); } } return "Unknown operation"; } }