📄 genericfactory.java
字号:
/* ************************** BEHAVIOURS RELATED METHODS *****************/
/**
* Test if the behaviours part is activated (if and only if the overlay
* use behaviours).
* @throws InitializationException only if the behaviours part is not activated.
*/
private static void ensureActivatedBehaviours() throws InitializationException
{
if (!Properties.overlayWithBehaviours)
throw new InitializationException("The current overlay doesn't use behaviours.");
}
/**
* Builds an instance of the current BehavioursFactory implementation.
* @return An instance of the current BehavioursFactory implementation.
* @throws InitializationException when an error occurs during the
* initialization or when this factory method is nonapplicable, because
* the current overlay doesn't use behaviours.
*/
public static BehavioursFactory buildBehavioursFactory()
throws InitializationException {
ensureActivatedBehaviours();
return ((BehavioursFactory)GenericFactory.newInstance(Properties.behavioursFactory)).
setValues(Properties.behavioursPool,Properties.behavioursFilter,
Properties.behavioursInvoker, Properties.behavioursPattern,
Properties.behavioursRoleSelector);
}
/**
* @see planet.commonapi.behaviours.BehavioursFactory#buildBehavioursFilter()
*/
public static BehavioursFilter buildBehavioursFilter()
throws InitializationException {
ensureActivatedBehaviours();
return behavioursFactory.buildBehavioursFilter();
}
/**
* @see planet.commonapi.behaviours.BehavioursFactory#buildBehavioursInvoker()
*/
public static BehavioursInvoker buildBehavioursInvoker()
throws InitializationException {
ensureActivatedBehaviours();
return behavioursFactory.buildBehavioursInvoker();
}
/**
* @see planet.commonapi.behaviours.BehavioursFactory#buildBehavioursPattern()
*/
public static BehavioursPattern buildBehavioursPattern()
throws InitializationException {
ensureActivatedBehaviours();
return behavioursFactory.buildBehavioursPattern();
}
/**
* @see planet.commonapi.behaviours.BehavioursFactory#buildBehavioursPool()
*/
public static BehavioursPool buildBehavioursPool() throws InitializationException {
ensureActivatedBehaviours();
return behavioursFactory.buildBehavioursPool();
}
/**
* @see planet.commonapi.behaviours.BehavioursFactory#buildBehavioursRoleSelector()
*/
public static BehavioursRoleSelector buildBehavioursRoleSelector()
throws InitializationException {
ensureActivatedBehaviours();
return behavioursFactory.buildBehavioursRoleSelector();
}
/**
* @see planet.commonapi.behaviours.BehavioursPool#onMessage(planet.commonapi.RouteMessage, planet.commonapi.Node)()
*/
public void onMessage(RouteMessage msg, Node node) throws NoSuchBehaviourException,NoBehaviourDispatchedException, InitializationException
{
ensureActivatedBehaviours();
behavioursPool.onMessage(msg,node);
}
/* *************** RESULTS RELATED METHODS ********************************/
/**
* Test if the results part is activated.
* @throws InitializationException only if the results part is not activated.
*/
private static void ensureActivatedResults() throws InitializationException
{
if (!Properties.isResultsActivated())
throw new InitializationException("The current configuration has not the activated results.");
}
/**
* Builds an instance of the current BehavioursFactory implementation.
* @return An instance of the current BehavioursFactory implementation.
* @throws InitializationException when an error occurs during the
* initialization or when this factory method is nonapplicable, because
* the no results are activated, or when the <b>resultsName</b> doesn't
* appears in the current configuration.
*/
public static ResultsFactory buildResultsFactory(String resultName)
throws InitializationException {
ensureActivatedResults();
return ((ResultsFactory)GenericFactory.newInstance(Properties.getResultsFactory(resultName))).
setValues( Properties.getResultsEdge(resultName),
Properties.getResultsConstraint(resultName),
Properties.getResultsGenerator(resultName));
}
/**
* @param resultsName Results type name to use.
* @throws InitializationException when an error occurs during the
* initialization or when this factory method is nonapplicable, because
* the no results are activated, or when the <b>resultsName</b> doesn't
* appears in the current configuration.
* @see planet.commonapi.results.ResultsGenerator#generateResults(planet.commonapi.Network, java.lang.String, planet.commonapi.results.ResultsConstraint, boolean)
*/
public static void generateResults(String resultsName, Network network, String out, ResultsConstraint constraint, boolean wholeNetworkLayout) throws InitializationException {
ensureActivatedResults();
ResultsGenerator gen = (ResultsGenerator)resultsGenerator.get(resultsName);
if (gen == null)
throw new InitializationException("The results type '"+resultsName+"' doesn't appears in the current configuration.");
gen.generateResults(network,out,constraint,wholeNetworkLayout);
}
/**
* @param resultsName Results type name to use.
* @throws InitializationException when an error occurs during the
* initialization or when this factory method is nonapplicable, because
* the no results are activated, or when the <b>resultsName</b> doesn't
* appears in the current configuration.
* @see planet.commonapi.results.ResultsFactory#buildEdge(planet.commonapi.Id, planet.commonapi.Id, boolean, java.lang.String)
*/
public static ResultsEdge buildEdge(String resultsName, Id source, Id target, boolean directed, String fill) throws InitializationException {
ensureActivatedResults();
ResultsFactory fact = (ResultsFactory)resultsFactory.get(resultsName);
if (fact == null)
throw new InitializationException("The results type '"+resultsName+"' doesn't appears in the current configuration.");
return fact.buildEdge(source,target,directed,fill);
}
/**
* @param resultsName Results type name to use.
* @throws InitializationException when an error occurs during the
* initialization or when this factory method is nonapplicable, because
* the no results are activated, or when the <b>resultsName</b> doesn't
* appears in the current configuration.
* @see planet.commonapi.results.ResultsFactory#buildGenerator()
*/
public static ResultsGenerator buildGenerator(String resultsName) throws InitializationException {
ensureActivatedResults();
ResultsFactory fact = (ResultsFactory)resultsFactory.get(resultsName);
if (fact == null)
throw new InitializationException("The results type '"+resultsName+"' doesn't appears in the current configuration.");
return fact.buildGenerator();
}
/**
* @param resultsName Results type name to use.
* @throws InitializationException when an error occurs during the
* initialization or when this factory method is nonapplicable, because
* the no results are activated, or when the <b>resultsName</b> doesn't
* appears in the current configuration.
* @see planet.commonapi.results.ResultsFactory#buildConstraint()
*/
public static ResultsConstraint buildConstraint(String resultsName) throws InitializationException {
ensureActivatedResults();
ResultsFactory fact = (ResultsFactory)resultsFactory.get(resultsName);
if (fact == null)
throw new InitializationException("The results type '"+resultsName+"' doesn't appears in the current configuration.");
return fact.buildConstraint();
}
/* ****************** MESSAGE KEY RELATED METHODS ********************* */
/**
* Generate a unique key, based on a simple int. Based on the context of the
* simulator, its implementation ensures that the returned key is unique at
* the time that it is generated. This key is used to identify a unique
* RouteMessage.
* @return An unique key for a RouteMessage to be send.
*/
public static String generateKey() {
return keyGen.generateKey();
}
/* ********************* RETRIEVING DEFAULT INSTANCES *********************/
/**
* Returns the NetworkFactory that is used internally to invoke the
* NetworkFactory methods.
* @return The NetworkFactory that is used internally to invoke
* the current NetworkFactory methods.
* @throws InitializationException if some error occurs during the retrieving.
*/
public static NetworkFactory getDefaultNetworkFactory() throws InitializationException {
return factoryNetworkFactory;
}
/**
* Returns the IdFactory that is used internally to invoke the
* IdFactory methods.
* @return The IdFactory that is used internally to invoke the
* IdFactory methods.
* @throws InitializationException if some error occurs during the retrieving.
*/
public static IdFactory getDefaultIdFactory() throws InitializationException {
return factoryIdFactory;
}
/**
* Returns the NodeHandleFactory that is used internally to invoke the
* nodehandle factory methods.
* @return The NodeHandleFactory that is used internally to invoke the
* nodehandle factory methods.
* @throws InitializationException if some error occurs during the retrieving.
*/
public static NodeHandleFactory getDefaultNodeHandleFactory() throws InitializationException
{
return factoryNodeHandleFactory;
}
/**
* Returns the NodeFactory that is used internally to invoke the node
* factory methods.
* @return The NodeFactory that is used internally to invoke the node
* factory methods.
* @throws InitializationException if some error occurs during the retrieving.
*/
public static NodeFactory getDefaultNodeFactory() throws InitializationException
{
return factoryNodeFactory;
}
/**
* Returns the ApplicationFactory that is used internally to invoke the
* application factory methods.
* @return The ApplicationFactory that is used internally to invoke the
* application factory methods.
* @throws InitializationException if some error occurs during the retrieving.
*/
public static ApplicationFactory getDefaultApplicationFactory() throws InitializationException
{
return factoryApplicationFactory;
}
/**
* Return the EndPointFactory that is used internally to invoke the
* endpoint factory methods.
* @return The EndPointFactory that is used internally to invoke the
* endpoint factory methods.
* @throws InitializationException if some error occurs during the retrieving.
*/
public static EndPointFactory getDefaultEndPointFactory() throws InitializationException
{
return factoryEndPointFactory;
}
/**
* Return the BehavioursFactory that is used internally to invoke the
* behaviours factory methods.
* @return The BehavioursFactory that is used internally to invoke the
* behaviours factory methods.
* @throws InitializationException if some error occurs during the retrieving.
*/
public static BehavioursFactory getDefaultBehavioursFactory() throws InitializationException
{
return behavioursFactory;
}
/**
* Return the BehavioursPool that is used internally to invoke the
* behaviours pool methods.
* @return The BehavioursPool that is used internally to invoke the
* behaviours pool methods.
* @throws InitializationException if some error occurs during the retrieving.
*/
public static BehavioursPool getDefaultBehavioursPool() throws InitializationException
{
return behavioursPool;
}
/**
* Returns the RouteMessagePool that is used internally to invoke the pool
* methods.
* @return The RouteMessagePool that is used internally to invoke the pool
* methods.
* @throws InitializationException if some error occurs during the retrieving.
*/
public static RouteMessagePool getDefaultRouteMessagePool() throws InitializationException
{
return routeMessagePool;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -