`
cuizhenfu#gmail.com
  • 浏览: 65978 次
  • 性别: Icon_minigender_1
  • 来自: 北京
文章分类
社区版块
存档分类
最新评论

自定义服务时服务的启动顺序

阅读更多
在实现自定义服务时,我们很可能会依赖其它服务或核心服务,在这种情况下,要求自定义服务的启动必须在依赖服务启动之后。例如我们在ResolverService服务之上实现自己的服务,就是说我们的服务要使用ResolverService来实现自己的功能。
那么在自定义服务的
java 代码
 
  1. public int startApp(String[] args) {  
  2.     // Now that the service is being started, set the ResolverService  
  3.     // object to use handle our queries and send responses.  
  4.     resolver = peerGroup.getResolverService();  
  5.     if(resolver == null) {  
  6.         return Module.START_AGAIN_PROGRESS;  
  7.     }  
  8.     // Add ourselves as a handler using the uniquely constructed  
  9.     // handler name.  
  10.     resolver.registerHandler(handlerName, this);  
  11.     return Module.START_OK;  
  12. }  
通过上述代码判断,如果resolver的值为null,那么说明ResolverService还没有初始化,我们返回Module.START_AGAIN_PROGRESS,表示我们的服务还需要再次初始化。如果resolver的值不为null,那么说明ResolverService已经初始化,我们返回Module.START_OK,即可。其它依赖服务与此类似。

下面的Module接口中对几个常量进行了说明,可以看出
Module.START_AGAIN_PROGRESS与Module.START_AGAIN_STALLED的含义基本相同。

java 代码
 
  1. /* 
  2.  * Copyright (c) 2001-2007 Sun Microsystems, Inc.  All rights reserved. 
  3.  *   
  4.  *  The Sun Project JXTA(TM) Software License 
  5.  *   
  6.  *  Redistribution and use in source and binary forms, with or without  
  7.  *  modification, are permitted provided that the following conditions are met: 
  8.  *   
  9.  *  1. Redistributions of source code must retain the above copyright notice, 
  10.  *     this list of conditions and the following disclaimer. 
  11.  *   
  12.  *  2. Redistributions in binary form must reproduce the above copyright notice,  
  13.  *     this list of conditions and the following disclaimer in the documentation  
  14.  *     and/or other materials provided with the distribution. 
  15.  *   
  16.  *  3. The end-user documentation included with the redistribution, if any, must  
  17.  *     include the following acknowledgment: "This product includes software  
  18.  *     developed by Sun Microsystems, Inc. for JXTA(TM) technology."  
  19.  *     Alternately, this acknowledgment may appear in the software itself, if  
  20.  *     and wherever such third-party acknowledgments normally appear. 
  21.  *   
  22.  *  4. The names "Sun", "Sun Microsystems, Inc.", "JXTA" and "Project JXTA" must  
  23.  *     not be used to endorse or promote products derived from this software  
  24.  *     without prior written permission. For written permission, please contact  
  25.  *     Project JXTA at http://www.jxta.org. 
  26.  *   
  27.  *  5. Products derived from this software may not be called "JXTA", nor may  
  28.  *     "JXTA" appear in their name, without prior written permission of Sun. 
  29.  *   
  30.  *  THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, 
  31.  *  INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND  
  32.  *  FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SUN  
  33.  *  MICROSYSTEMS OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,  
  34.  *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT  
  35.  *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,  
  36.  *  OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF  
  37.  *  LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING  
  38.  *  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,  
  39.  *  EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
  40.  *   
  41.  *  JXTA is a registered trademark of Sun Microsystems, Inc. in the United  
  42.  *  States and other countries. 
  43.  *   
  44.  *  Please see the license information page at : 
  45.  *  <http://www.jxta.org/project/www/license.html> for instructions on use of  
  46.  *  the license in source files. 
  47.  *   
  48.  *  ==================================================================== 
  49.  *   
  50.  *  This software consists of voluntary contributions made by many individuals  
  51.  *  on behalf of Project JXTA. For more information on Project JXTA, please see  
  52.  *  http://www.jxta.org. 
  53.  *   
  54.  *  This license is based on the BSD license adopted by the Apache Foundation.  
  55.  */  
  56.   
  57. package net.jxta.platform;  
  58.   
  59.   
  60. import net.jxta.peergroup.PeerGroup;  
  61. import net.jxta.document.Advertisement;  
  62. import net.jxta.id.ID;  
  63. import net.jxta.exception.PeerGroupException;  
  64.   
  65.   
  66. /** 
  67.  * Defines the interface for modules loaded by PeerGroups. Message transports, 
  68.  * services and applications need to implement this interface if they are 
  69.  * to be loaded and started by a PeerGroup. Service and Application extend 
  70.  * Module, PeerGroup implements Service and ShellApp implements Application, as 
  71.  * a result both implement Module. 
  72.  * 
  73.  * <p/>Jxta Modules are given their initialization parameters via the init() 
  74.  * method rather than a non-default constructor. 
  75.  * 
  76.  * <p/>Modules are passed the peer group within which they are created. 
  77.  * From the peergroup object, Modules can access all the peer group 
  78.  * services. The PeerGroup within which a PeerGroup runs is known as its 
  79.  * parent. 
  80.  * 
  81.  * <p/>The initial root peer group is known as the World Peer Group and is 
  82.  * implemented by an object of class Platform, a subclass of PeerGroup. 
  83.  * The "parent" PeerGroup of the World Peer Group is null. 
  84.  * 
  85.  * @see net.jxta.protocol.ModuleImplAdvertisement 
  86.  * @see net.jxta.platform.ModuleClassID 
  87.  * @see net.jxta.peergroup.PeerGroup 
  88.  * @see net.jxta.document.Advertisement 
  89.  * @see net.jxta.id.ID 
  90.  * @see net.jxta.platform.Application 
  91.  * @see net.jxta.service.Service 
  92.  **/  
  93. public interface Module {  
  94.       
  95.     /** 
  96.      * <code>startApp()</code> completed successfully. This module claims to now 
  97.      * be fully functional and no further invocation of startApp is required. 
  98.      **/  
  99.     public static final int START_OK = 0;  
  100.       
  101.     /** 
  102.      * This is to be used mostly by co-dependent services when started as 
  103.      * a set (such as {@link PeerGroup} services) so that their 
  104.      * <code>startApp()</code> method may be invoked multiple times. 
  105.      * 
  106.      * <p/>This value indicates that startApp must be retried later in order for 
  107.      * this module to become fully functional. However, some progress in 
  108.      * functionality was accomplished. 
  109.      * 
  110.      * <p/>This is a strong indication that some other modules may be able 
  111.      * to advance or complete their initialization if their 
  112.      * <code>startApp()</code> method is invoked again. 
  113.      * 
  114.      * <p/>The distinction between START_AGAIN_STALLED and START_AGAIN_PROGRESS 
  115.      * is only a hint. Each module makes an arbitrary judgment in this 
  116.      * respect. It is up to the invoker of startApp to ensure that the 
  117.      * starting of a set of modules eventually succeeds or fails. 
  118.      **/  
  119.     public static final int START_AGAIN_PROGRESS = 1;  
  120.       
  121.     /** 
  122.      * This is to be used mostly by co-dependent services when started as 
  123.      * a set (such as {@link PeerGroup} services) so that their startApp 
  124.      * method may be invoked multiple times. 
  125.      * 
  126.      * <p/>This value indicates that startApp must be retried later in order for 
  127.      * this module to become fully functional. However, some progress in 
  128.      * functionality was accomplished. 
  129.      * 
  130.      * <p/>If all modules in a set return this value, it is a strong indication 
  131.      * that the modules co-dependency is such that it prevents them 
  132.      * collectively from starting. 
  133.      * 
  134.      * <p/>The distinction between START_AGAIN_STALLED and START_AGAIN_PROGRESS 
  135.      * is only a hint. Each module makes an arbitrary judgment in this 
  136.      * respect. It is up to the invoker of startApp to ensure that the 
  137.      * starting of a set of modules eventually succeeds or fails. 
  138.      **/  
  139.     public static final int START_AGAIN_STALLED = 2;  
  140.           
  141.     /** 
  142.      * This return result is used to indicate that the module refuses to start 
  143.      * because it has been configured to be disabled or otherwise cannot run 
  144.      * (missing hardware, missing system resources, etc.) The module will not be 
  145.      * functional and should be discarded but the failure to load may be ignored  
  146.      * by the loader at it's discretion. 
  147.      */  
  148.     public static final int START_DISABLED = Integer.MIN_VALUE + 100;  
  149.       
  150.     /** 
  151.      * Initialize the module, passing it its peer group and advertisement. 
  152.      * 
  153.      * <p/>Note: when subclassing one of the existing PeerGroup implementations 
  154.      * (which implement Module), it may not be recommended to overload the init 
  155.      * method. See the documentation of the PeerGroup class being subclassed. 
  156.      * 
  157.      *  @param group The PeerGroup from which this Module can obtain services. 
  158.      *  If this module is a Service, this is also the PeerGroup of which this 
  159.      *  module is a service. 
  160.      * 
  161.      *  @param assignedID Identity of Module within group. 
  162.      *  modules can use it as a the root of their namespace to create 
  163.      *  names that are unique within the group but predictable by the 
  164.      *  same module on another peer. This is normally the ModuleClassID 
  165.      *  which is also the name under which the module is known by other 
  166.      *  modules. For a group it is the PeerGroupID itself. 
  167.      *  The parameters of a service, in the Peer configuration, are indexed 
  168.      *  by the assignedID of that service, and a Service must publish its 
  169.      *  run-time parameters in the Peer Advertisement under its assigned ID. 
  170.      * 
  171.      *  @param implAdv The implementation advertisement for this 
  172.      *  Module. It is permissible to pass null if no implementation 
  173.      *  advertisement is available. This may happen if the 
  174.      *  implementation was selected by explicit class name rather than 
  175.      *  by following an implementation advertisement. Modules are not 
  176.      *  required to support that style of loading, but if they do, then 
  177.      *  their documentation should mention it. 
  178.      * 
  179.      *  @exception PeerGroupException This module failed to initialize. 
  180.      **/  
  181.     public void init(PeerGroup group, ID assignedID, Advertisement implAdv) throws PeerGroupException;  
  182.       
  183.     /** 
  184.      * Complete any remaining initialization of the module. The module should 
  185.      * be fully functional after <code>startApp()</code> is completed. That is 
  186.      * also the opportunity to supply arbitrary arguments (mostly to 
  187.      * applications). 
  188.      * 
  189.      * <p/>If this module is a {@link PeerGroup} service, it may be invoked 
  190.      * several times depending on its return value. 
  191.      * 
  192.      * @param args An array of Strings forming the parameters for this 
  193.      * Module. 
  194.      * 
  195.      * @return int A status indication which may be one of 
  196.      * {@link #START_OK}, {@link #START_AGAIN_PROGRESS}, 
  197.      * {@link #START_AGAIN_STALLED}, which indicates partial or complete 
  198.      * success, or any other value (negative values are 
  199.      * recommended for future compatibility), which indicates failure. 
  200.      **/  
  201.     public int startApp(String[] args);  
  202.       
  203.     /** 
  204.      *  Stop a module. This may be called any time after <code>init()</code> 
  205.      *  completes and should not assume that <code>startApp()</code> has been 
  206.      *  called or completed. 
  207.      * 
  208.      *  <p/>The Module cannot be forced to comply, but in the future 
  209.      *  we might be able to deny it access to anything after some timeout. 
  210.      **/  
  211.     public void stopApp();  
  212. }  
分享到:
评论

相关推荐

    自定义软件开机启动顺序

    此软件可以自定义开机软件启动的顺序,我只在Xp系统中测试是正常,其它系统不能保证。

    CentOS7添加自定义系统服务1

    1、Unit部分Unit部分是启动顺序与依赖关系 2、Service部分Service部分定义如何启动/重启/停止服务 3、Install部分Install部分

    windows系统 自动软件 管理系统,可以自定义开机启动的软件

    windows系统 自动软件 管理系统,可以自定义开机启动的软件,并且按照定义的顺序启动

    多气缸顺序启动程序(欧姆龙PLC程序与Fluid_SIM仿真)

    两个气缸顺序启动的控制程序,第一个气缸伸出,行程末端第二个气缸伸出,然后两气缸依次收回。

    ESET nod32 ID自动获取工具【ESET_VC52_AUTOID】 V1.7.2.1

    2、修改了“自动更新ESET”的启动顺序,在自动升级之前,免去和自动升级的冲突。 2、优化了本软件自动升级更新文件的方法,不会出现自动升级后程序不见的问题。 1.6.7更新:2009-01-20 1、鉴于新的网络等待大部分...

    酷q功能插件机器人聊天签到禁言踢人自定义

    1)请将本插件复制到酷q安装目录的 酷Q\plugin 下 ,启动酷q选择本插件 2)讲doudouchong文件夹放到 酷Q\config 下 二、本插件提供功能如下: 提供图形化配置简单明了 签到 抽奖 天气查询 抽签 解签 @机器人聊天 ...

    tomcatOrder

    tomcat多包启动的时候自定义启动顺序

    Python实现多图像转换成连贯的PDF文件,支持所有图片格式,可预览、裁剪、自定义PDF布局、设置图像顺序、PDF质量选择等

    用户可以选择不同的预设图像排序顺序,即文件名称、创建日期或最后修改时间。此外,通过调整左、右、上和下边框,还可以裁剪图像,并排除不必要或不想要的边框或图像部分(如截图中的任务栏),既可以裁剪每个文件,...

    NOD32 3.0 自动获取ID&更换器

    1、修正了1.6.6变量重复导致ID选取不正常(顺序选取时无法选取第一二个ID)。 2、增加了“自动选择”时的随机验证线路,防止验证线路单一被封。 1.6.6更新: 1、修改了软件自动升级的线路,以前的升级线路连接不稳定...

    勤哲excel服务器2010教程

    3.2 服务的启动与停止 24 3.3 客户端功能模块概览 25 3.4 模板的概念 30 3.5 本章练习 34 第4章、 建立部门、角色、用户 35 4.1 管理控制台通用操作 35 4.2 设置全局信息 36 4.3 建立组织机构 37 4.3.1 建立部门 37 ...

    Anomaly-detection-with-DBSCAN:使用自定义DBSCAN实施进行异常检测

    这是一种受DBScan算法启发的简单算法,但由于DBScan是随机启动的,因此适用于按顺序分析数据。 使用的数据集是一些Yahoo公开数据集,其中包含有关给定时间的Yahoo服务器的信息。 例如,在夜间,由于可能没有活动的...

    全能优化(Guardio) v5.08.0.1120

    实时、全面杀除超过40,000种木马/恶意软件,免疫国内外2025种恶意插件/软件/网站,清除48种恶意软件,去除68种系统/常用软件使用痕迹,清除IE的访问历史和...5.改进:增强与优化 之 服务与驱动,详细显示启动顺序;

    docker-compose

    # 此选项解决了启动顺序的问题 这个的意思是必须在php启动以后才能启动 # 注意的是,默认情况下使用 docker-compose up web 这样的方式启动 web 服务时, # 也会启动 php 服务,因为在配置文件中定义了依赖关系 ...

    NODID自动获取填写工具(适用所有版本)

    2、修改了“自动更新ESET”的启动顺序,在自动升级之前,免去和自动升级的冲突。 2、优化了本软件自动升级更新文件的方法,不会出现自动升级后程序不见的问题。 1.6.7更新:2009-01-20 1、鉴于新的网络等待大部分...

    EasyBCD(双系统引导修复工具) v2.2 中文版.zip

    1、自定义的开机预启动的操作系统,调整不同系统开机菜单顺序,定义预启动时等待时间; 2、自定义开机预启动系统菜单的名称;自定义开机多系统预启动菜单的语言; 3、支持Windows、Linux、Mac和NeoGrub等开机菜单...

    JSP和Servlet面试题

    Servlet的执行流程也就是servlet的生命周期,当服务器启动的时候生命周期开始,然后通过init()《启动顺序根据web.xml里的startup-on-load来确定加载顺序》 方法初始化servlet,再根据不同请求调用doGet或doPost...

    COM与COM+从入门到精通(pdf版本,含源码)

    激活顺序 使用即时(JIT)激活 使用对象构造 中性公寓简介 了解同步域 表示事务状态 取得对象信息 使用对象地 对象池的好处 对象地要求 对象地配置 使用排队组件 QC限制 QC配置 QC调用 QC播放控件 ...

    Android代码-TextPathView是一个把文字转化为路径动画然后展现出来的自定义控件

     TextPathView分为两种,一种是每个笔画按顺序刻画的SyncTextPathView,一种是每个笔画同时刻画的AsyncTextPathView,使用方法都是一样,在xml里面配置属性,然后直接在java里面调用startAnimation()方法就行了,...

    ESET nod32 ID自动获取工具【ESET_VC52_AUTOID】 V1.7.2.2

    2、修改了“自动更新ESET”的启动顺序,在自动升级之前,免去和自动升级的冲突。 2、优化了本软件自动升级更新文件的方法,不会出现自动升级后程序不见的问题。 1.6.7更新:2009-01-20 1、鉴于新的网络等待大部分...

    ESET nod32 ID自动获取工具【ESET_VC52_AUTOID】 V1.7.2.3

    2、修改了“自动更新ESET”的启动顺序,在自动升级之前,免去和自动升级的冲突。 2、优化了本软件自动升级更新文件的方法,不会出现自动升级后程序不见的问题。 1.6.7更新:2009-01-20 1、鉴于新的网络等待大部分...

Global site tag (gtag.js) - Google Analytics