本文整理了Java中org.apache.polygene.api.configuration.Configuration
类的一些代码示例,展示了Configuration
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Configuration
类的具体详情如下:
包路径:org.apache.polygene.api.configuration.Configuration
类名称:Configuration
[英]Provide Configurations for Services. A Service that wants to be configurable should inject a reference to Configuration with the Configuration type:
* @This Configuration<MyServiceConfiguration> config;
where MyServiceConfiguration extends ConfigurationComposite, which itself is an ordinary org.apache.polygene.api.entity.EntityComposite. The Configuration implementation will either locate an instance of the given Configuration type in the persistent store using the reference of the Service, or create a new such instance if one doesn't already exist.
If a new Configuration instance is created then it will be populated with properties from the properties file whose filesystem name is the same as the reference (e.g. "MyService.properties"). If a service is not given a name via the org.apache.polygene.bootstrap.ServiceDeclaration#identifiedBy(String), the name will default to the FQCN of the ServiceComposite type.
The Configuration instance can be modified externally just like any other EntityComposite, but its values will not be updated in the Service until #refresh() is called. This allows safe reloads of Configuration state to ensure that it is not reloaded while the Service is handling a request.
The Configuration will be automatically refreshed when the Service is activated by the Polygene runtime. Any refreshes at other points will have to be done manually or triggered through some other mechanism.
The user configuration entity is part of a long running UnitOfWork, and to persist changes to it the #save() method must be called. No other actions are required. Example;
public interface MyConfiguration extends ConfigurationComposite
{
Property<Long> timeout();
}
:
@This Configuration<MyConfiguration> config;
:
private void setTimeoutConfiguration( long timeout )
{
config.get().timeout().set( timeout );
config.save();
}
And even if a separate thread is using the timeout() configuration when this is happening, the UnitOfWork isolation will ensure that the other thread is not affected. That thread, on the other hand will need to do a #refresh() at an appropriate time to pick up the timeout change. For instance;
@Service InventoryService remoteInventoryService;
public void restockInventoryItem( InventoryItemId id, int itemCount )
{
config.refresh();
long timeout = config.get().timeout().get();
remoteInventoryService.restock( id, itemCount, timeout );
:
:
}
[中]提供服务的配置。想要进行配置的服务应该使用以下配置类型插入对配置的引用:
* @This Configuration<MyServiceConfiguration> config;
其中MyServiceConfiguration扩展了ConfigurationComposite,它本身就是一个普通组织。阿帕奇。多基因。应用程序编程接口。实体整体构成。配置实现将使用服务的引用在持久性存储中定位给定配置类型的实例,或者创建一个新的实例(如果还不存在)。
如果创建了一个新的配置实例,那么将使用文件系统名称与引用相同的属性文件(例如“MyService.properties”)中的属性填充该实例。如果服务未通过组织指定名称。阿帕奇。多基因。独自创立ServiceDeclaration#identifiedBy(String),名称默认为ServiceComposite类型的FQCN。
配置实例可以像任何其他EntityComposite一样进行外部修改,但在调用#refresh()之前,其值不会在服务中更新。这允许安全地重新加载配置状态,以确保在服务处理请求时不会重新加载配置状态。
当Polygene运行时激活服务时,配置将自动刷新。其他点的任何刷新都必须手动完成或通过其他机制触发。
用户配置实体是长时间运行的UnitOfWork的一部分,要将更改持久化,必须调用#save()方法。不需要采取其他行动。实例
public interface MyConfiguration extends ConfigurationComposite
{
Property<Long> timeout();
}
:
@This Configuration<MyConfiguration> config;
:
private void setTimeoutConfiguration( long timeout )
{
config.get().timeout().set( timeout );
config.save();
}
即使发生这种情况时一个单独的线程正在使用timeout()配置,UnitOfWork隔离也将确保另一个线程不受影响。另一方面,该线程需要在适当的时间执行#refresh(),以获取超时更改。例如;
@Service InventoryService remoteInventoryService;
public void restockInventoryItem( InventoryItemId id, int itemCount )
{
config.refresh();
long timeout = config.get().timeout().get();
remoteInventoryService.restock( id, itemCount, timeout );
:
:
}
代码示例来源:origin: apache/attic-polygene-java
public void doSomething()
{
// Refresh Configuration before reading it.
config.refresh();
TravelPlanConfiguration tpConf = config.get();
// ...
}
// END SNIPPET: refresh
代码示例来源:origin: apache/attic-polygene-java
@Override
public String findPrefix( Class type )
{
Map<String, String> mapping = config.get().mapping().get();
String prefix = mapping.get( type.getName() );
if( prefix == null )
{
config.refresh();
mapping = config.get().mapping().get();
prefix = Integer.toString( mapping.size() + 1 );
mapping.put( type.getName(), prefix );
config.get().mapping().set( mapping );
config.save();
}
actualClasses.put( type.getName(), type );
return prefix;
}
代码示例来源:origin: apache/attic-polygene-java
@Override
protected JettyConfiguration configuration()
{
return configuration.get();
}
代码示例来源:origin: apache/attic-polygene-java
throws RepositoryException
String dataDir = configuration.get().dataDirectory().get();
File dataDirectory;
if( dataDir == null || "".equals( dataDir ) )
String serviceIdentity = configuration.get().identity().get().toString();
if( fileConfiguration != null )
configuration.get().dataDirectory().set( dataDir );
configuration.save();
dataDirectory = new File( dataDir );
代码示例来源:origin: org.apache.polygene.libraries/org.apache.polygene.library.jmx
@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";
}
}
代码示例来源:origin: org.apache.polygene.libraries/org.apache.polygene.library.http
@Override
protected JettyConfiguration configuration()
{
return configuration.get();
}
代码示例来源:origin: apache/attic-polygene-java
String lastVersion = config.get().lastStartupVersion().get();
config.get().lastStartupVersion().set( version );
config.save();
代码示例来源:origin: apache/attic-polygene-java
@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";
}
}
代码示例来源:origin: apache/attic-polygene-java
@Override
public void reindex()
{
configuration.refresh();
ReindexerConfiguration conf = configuration.get();
Integer loadValue = conf.loadValue().get();
if( loadValue == null )
{
loadValue = 50;
}
ReindexerHelper helper = new ReindexerHelper( loadValue );
helper.reindex( store );
}
代码示例来源:origin: org.apache.polygene.libraries/org.apache.polygene.library.http
@Override
protected JettyConfiguration configuration()
{
return configuration.get();
}
代码示例来源:origin: apache/attic-polygene-java
@Override
public void changeExternalMailService( String hostName, int port )
{
MailServiceConfiguration conf = config.get();
conf.hostName().set( hostName );
conf.port().set( port );
config.save();
}
// START SNIPPET: write
代码示例来源:origin: org.apache.polygene.libraries/org.apache.polygene.library.sql-liquibase
@Override
public Liquibase newConnectedLiquibase() throws SQLException, LiquibaseException
{
config.refresh();
DatabaseConnection dbConnection = new JdbcConnection( dataSource.get().getConnection() );
return new Liquibase( config.get().changeLog().get(),
new ClassLoaderResourceAccessor(),
dbConnection );
}
代码示例来源:origin: apache/attic-polygene-java
@Override
protected JettyConfiguration configuration()
{
return configuration.get();
}
代码示例来源:origin: apache/attic-polygene-java
@Override
public Liquibase newConnectedLiquibase() throws SQLException, LiquibaseException
{
config.refresh();
DatabaseConnection dbConnection = new JdbcConnection( dataSource.get().getConnection() );
return new Liquibase( config.get().changeLog().get(),
new ClassLoaderResourceAccessor(),
dbConnection );
}
代码示例来源:origin: org.apache.polygene.libraries/org.apache.polygene.library.http
@Override
protected ServerConnector buildConnector( Server server, HttpConfiguration httpConfig )
{
SslConnectionFactory sslConnFactory = new SslConnectionFactory();
configureSsl( sslConnFactory, configuration.get() );
return new ServerConnector( server, sslConnFactory, new HttpConnectionFactory( httpConfig ) );
}
代码示例来源:origin: org.apache.polygene.libraries/org.apache.polygene.library.shiro-web
@Override
public void contextInitialized( ServletContextEvent sce )
{
configuration.refresh();
ShiroIniConfiguration config = configuration.get();
String iniResourcePath = config.iniResourcePath().get() == null ? "classpath:shiro.ini" : config.iniResourcePath().get();
sce.getServletContext().setInitParameter( "shiroConfigLocations", iniResourcePath );
WebEnvironment env = initEnvironment( sce.getServletContext() );
if ( realmsRefs != null && realmsRefs.iterator().hasNext() ) {
// Register Realms Services
RealmSecurityManager realmSecurityManager = ( RealmSecurityManager ) env.getSecurityManager();
Collection<Realm> iniRealms = new ArrayList<Realm>( realmSecurityManager.getRealms() );
for ( ServiceReference<Realm> realmRef : realmsRefs ) {
iniRealms.add( realmRef.get() );
LOG.debug( "Realm Service '{}' registered!", realmRef.identity() );
}
realmSecurityManager.setRealms( iniRealms );
}
}
代码示例来源:origin: apache/attic-polygene-java
@Override
protected ServerConnector buildConnector( Server server, HttpConfiguration httpConfig )
{
SslConnectionFactory sslConnFactory = new SslConnectionFactory();
configureSsl( sslConnFactory, configuration.get() );
return new ServerConnector( server, sslConnFactory, new HttpConnectionFactory( httpConfig ) );
}
代码示例来源:origin: apache/attic-polygene-java
@Override
public void contextInitialized( ServletContextEvent sce )
{
configuration.refresh();
ShiroIniConfiguration config = configuration.get();
String iniResourcePath = config.iniResourcePath().get() == null ? "classpath:shiro.ini" : config.iniResourcePath().get();
sce.getServletContext().setInitParameter( "shiroConfigLocations", iniResourcePath );
WebEnvironment env = initEnvironment( sce.getServletContext() );
if ( realmsRefs != null && realmsRefs.iterator().hasNext() ) {
// Register Realms Services
RealmSecurityManager realmSecurityManager = ( RealmSecurityManager ) env.getSecurityManager();
Collection<Realm> iniRealms = new ArrayList<Realm>( realmSecurityManager.getRealms() );
for ( ServiceReference<Realm> realmRef : realmsRefs ) {
iniRealms.add( realmRef.get() );
LOG.debug( "Realm Service '{}' registered!", realmRef.identity() );
}
realmSecurityManager.setRealms( iniRealms );
}
}
代码示例来源:origin: apache/attic-polygene-java
public HttpRepositoryMixin( @This Configuration<HttpRepositoryConfiguration> configuration )
{
super( getRepositoryUrl( configuration.get() ), getRepositoryId( configuration.get() ) );
}
代码示例来源:origin: apache/attic-polygene-java
throws Exception
config.refresh();
storeId = hasIdentity.identity().get().toString();
String pathName = config.get().directory().get();
if( pathName == null )
Integer slicesConf = config.get().slices().get();
if( slicesConf == null )
内容来源于网络,如有侵权,请联系作者删除!