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

在实现自定义服务时,我们很可能会依赖其它服务或核心服务,在这种情况下,要求自定义服务的启动必须在依赖服务启动之后。例如我们在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. }  
ESP32-C61 eFuse控制器深度解析:寄存器架构与安全烧写实践 eFuse(电子熔丝)是嵌入式芯片实现硬件级不可逆配置与信任根构建的核心物理机制,其本质是通过电学编程固化关键安全参数。原理上依赖熔丝单元的单向导通/断开特性,结合Reed-Solomon纠错、多级写保护和时序可控编程,保障数据在宽温域与工艺偏差下的高可靠性。技术价值在于为Secure Boot、Flash加密、密钥隔离等安全功能提供可信锚点,支撑从启动到运行的全链路防护。典型应用场景涵盖物联网设备量产烧录、安全启动使能、MAC地址固化及抗DPA密码运算配置。本文聚焦ESP32-C61平台,深入解析其eFu 阅读详情

相关推荐

S7-1200PLC 与温控仪表Modbus RTU通信

硬件:cpu 1214C 目的:通过Modbus RTU协议,实现对温控仪表的控制 软件:Portal V14SP1

weixin_43922025的博客 3万+

windows启动顺序大概流程和服务程序遇到的问题

1.服务程序目前遇到的问题 (1)服务程序无法监控剪贴板; (2)服务程序无法设置挂载的磁盘卷标; (3)服务端发到客户端的thritf消息,调用剪贴板写入时会提示com失败的问题; 2.服务程序的启动顺序 参考文档:https://blog.csdn.net/singleyellow/article/details/104031963/ 电脑开机后,大致的启动顺序是BIOS—>MBR—>活动分区—>Ntoskrnl.exe、HAL—>服务类型为0、1的服务—>会话

onlyfunboy的专栏 2648

从想法到零件:手把手拆解一个汽车功能如何从PRD写到SSTS和CTS

本文详细拆解了汽车电子需求从市场文档(MRD)到零部件技术规范(CTS)的完整流程,以雨天自动关窗功能为例,展示了PRD、SSTS和CTS的编写要点与交互设计。文章重点解析了系统分解的艺术和零部件落地的精确参数要求,为汽车电子工程师提供了从概念到实现的全流程实践指南。

weixin_30300225的博客 481

systemd service,rc.local查看启动顺序,调整启动顺序

systemd service,rc.local查看启动顺序,调整启动顺序

7308

电源完整性之仿真设计原理

电源完整性(Power Integrity),简称为PI,也就是大家平常听说的PI。PCB板上的电源设计也是非常重要的,不当的设计也会引起很重要的影响。所以电源完整性PI和信号完整性SI,是我们互连设计人员应该同等重视的问题。今天整理本人接触的电源完整性PI的一些原理,从不的角度去看PI,会有不同的理解,下面开始喽!!! 提到互连的电源设计,可能首先想到的电源分配网络(Power Distribution Nets),因为互连电源会有许多种,直流DC和交流AC,还有不同的电压调节模块(VRM)与不同的负载端

刘小同学的博客 7379

保姆级教程:用PyBullet在Windows/Mac上快速搭建你的第一个机器人仿真环境(附避坑指南)

本教程详细介绍了如何使用PyBullet在Windows和Mac上快速搭建机器人仿真环境,包括Python环境配置、依赖安装避坑指南、首个机械臂仿真实现及性能优化技巧。通过分步指导和实战代码,帮助初学者轻松入门机器人仿真技术。

weixin_42526087的博客 412

linux服务器开机进程启动顺序,Linux服务器启动过程详解(转载)

1)BIOS自检2)启动Grub/Lilo3)加载内核4)执行init进程5)通过/etc/inittab文件进行初始化6)登陆Linux(1) 从BIOS到内核BIOS自检计算机在接通电源之后首先由BIOS进行自检,即进行所谓的POST(Power On SelfTest),然后依据BIOS内设置的引导顺序从硬盘、软盘或CDROM中读入“引导块”。 在 PC 中,引导 Linux 是从 BIOS...

weixin_29488835的博客 2570

群晖设置公网ipv6方式域名解析访问

群晖、IPV6、域名解析

爬山虎的博客 2万+

Linux systemd启动守护进程,service启动顺序分析及调整service启动顺序

欢迎转载,请注明出处! ©MrWang_tju 2019.5.15 systemd是Liunx的启动守护进程,已被大多数Liunx发行版所采用。相较于之前被采用的init进程串行启动,systemd进程采用并行启动且为系统启动管理提供了成套的方案。 探索systemd启动的问题背景是,团队使用树莓派zero W+做的产品在系统启动后需要启动声卡播放音频文件,但声卡驱动相关的服务启动需要20s...

xing_huo95的博客 2万+

Windows server Database 2025 安装 i225/i226 网卡驱动

Windows server Database 2025 安装 i225/i226 网卡驱动 windows这比坏得很,intel消费级网卡不准在服务器系统上安装。你要说他是异构不支持?他就纯粹恶心人。 之前已经安装过一次,但是今天database预览版一更新,又给我把网卡驱动杀了,气死,写一篇教程。 到这里就完成了,总之还是想辱骂windows,提供便捷的同时又人为制造困难,多少有点(隔壁linux内核直接自带全家桶了就一省心) 并且近年Intel的新U安装显卡驱动和普通声卡驱动都不会出声

低温热源的博客 1万+

Cesium 场景特效之【全球海洋】GL2兼容版

Cesium 场景特效之【全球海洋】GL2兼容版

喜欢钻研前端和分享技术 1280

docker启动顺序

https://www.jianshu.com/p/9446f210e327 wait-it-for。sh 就是不好使, 我之前的时候是好使的, 然后我修改了这个配置文件,就不好使了。。。 现在的情况就是他每次都是自己执行了命令,没有等mysql启动。 感觉好像是mysql就没创建我想要的那个数据库。 还大,还是这个毛病,就是创建不过去,操了 也就是说,我设置了这个东西,但是就是不好使。 dock...

围城 1746

【笔记篇】Davinci Configurator OS模块(下)

AUTOSAR OS的配置项和Vevtor MICROSAR OS的特性

weixin_47571898的博客 1158

微服务架构 - 解决Docker-Compose服务编排启动顺序问题

基于Docker Compose进行服务编排时,一定碰到服务启动顺序的问题,例如:B服务启动之前,A服务要已经启动并且可以正常对外服务。 这个启动顺序的问题,Docker Compose本身它是无法解决的,即使定义了depends_on或者links,它只能保证该服务依赖这些服务,启动本服务时会将依赖的服务也启动,但是启动顺序无法得到保证。 目前本人实验比较好的方案有两种: 基于wait-for...

一步就一个脚印 898

TMS_WebGMaps_1.9.8.0_Full_Source

TMS_WebGMaps_1.9.8.0_Full_Source 全源码 delphi cbuilder

ET2012新版免狗免安装绿色软件

ET2012新版免狗免安祖昂绿色软件。,新界面,新视觉,

怎么终止linux的次序运行程序,linux – 如何按特定顺序停止systemd服务

当特定的systemd服务停止时,如何确保遵循特定的订单?我有几个运行的系统服务/单元,但在各种已安装的分区上使用资源.使用自定义服务安装和卸载这些分区.在自定义安装程序停止之前,需要以特定顺序停止正在运行的服务(例如ProgramA.service& ProgramB.service).设置启动依赖项非常简单,但我无法弄清楚如何确保在挂载服务停止之前服务已停止.mountCustomPa...

weixin_36028876的博客 206

假人有限元模型

假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用

linux服务设置为开机启动项,Linux 设置开机启动项的几种方法

Linux 设置开机启动项的几种方法Linux 设置开机启动项的几种方法方法一:编辑rc.loacl脚本Ubuntu开机之后会执行/etc/rc.local文件中的脚本。所以我们可以直接在/etc/rc.local中添加启动脚本。vim /etc/rc.local#!/bin/sh## This script will be executed *after* all the other init ...

weixin_39692245的博客 294

IEM模型,地表粗糙度模拟

利用微波反演土壤水分时候,利用IEM模型可以实现对随机地表的模拟

FreeBSD开机自启动内网穿透frpc服务

但是针对非官方自带的服务,或者说没有写“官方配置启动”的服务,我们就要手工写配置启动文件了。需要注意的是,有些服务有启动顺序,否则可能启动失败,比如这里的frpc就在sshd之后启动,使用了这条命令`# REQUIRE: sshd `这样这个原来需要用户登录后才能启动的服务,就可以不需要用户自动启动了!

skywalk8163的专栏 987

Centos7 自定义systemctl服务脚本

systemd是靠管理unit的方式来控制开机服务,开机级别等功能。

qianghong000的博客 1088

Tomcat中jar包和class的加载顺序

当我们启动一个tomcat的服务的时候,jar包和claess文件是是以怎么样的顺序被加载进来的? 加载顺序: 1. $java_home/lib 目录下的java核心api 2. $java_home/lib/ext 目录下的java扩展jar包 3. java -classpath/-Djava.class.path所指的目录下的类与jar包 4. $CATALINA_HOME...

weixin_30781107的博客 331

spring-boot入门之路-16-项目服务启动的时候就去加载一些数据或做一些事情这样的需求。

实际应用中,我们会有在项目服务启动的时候就去加载一些数据或做一些事情这样的需求。为了解决这样的问题,Spring Boot为我们提供了一个方法,通过实现接口CommandLineRunner来实现。 很简单,只需要一个类就可以,无需其他配置。创建实现接口com.kfit.runner.CommandLineRunner的类 packagecom.kfit.runner; ...

qq_28384019的博客 288

Linux 开机自启动服务的顺序指定

今天,在产品线上遇到一个问题:产品有两个服务,A.service和B.service,两个服务都是使用systemd来启动,两个服务之间有依赖关系,A.service必须在B.service起来之后,才能使用B.service提供的功能。所以,在设置系统的两个服务的启动时,必须要设置好两者的启动关系,必须保证在B.service彻底启动起来之后,才能启动A.service,否则,A.service启动会因为不能使用B.service提供的功能而启动失败。 看到Unit里面可...

jimmyleeee的专栏 1万+

Docker中如何控制服务启动顺序实现探讨

Docker 是一个开源的应用容器引擎,基于 Go 语言 并遵从 Apache2.0 协议开源。Docker 可以让开发者打包他们的应用以及依赖包到一个轻量级、可移植的容器中,然后发布到任何流行的 Linux 机器上,也可以实现虚拟化。容器是完全使用沙箱机制,相互之间不会有任何接口(类似 iPhone 的 app),更重要的是容器性能开销极低。Docker的应用场景Web 应用的自动化打包和发布。自动化测试和持续集成、发布。在服务型环境中部署和调整数据库或其他的后台应用。

爱码少年 00fly.online 的博客 2万+

docker compose 服务启动顺序控制

docker-compose 可以方便组合多个 docker 容器服务, 但是, 当容器服务之间存在依赖关系时, docker-compose 并不能保证服务的启动顺序. docker-compose 中的 depends_on 配置是容器的启动顺序, 并不是容器中服务的启动顺序....

建伟博客 6290

Spring 启动顺序

加载配置文件: 读取或等配置文件。创建 Spring 容器: 初始化。Bean 定义加载: 通过扫描和配置文件加载 Bean 定义。Bean 实例化: 根据 Bean 定义创建 Bean 实例。依赖注入: 将所需的依赖注入到 Bean 中。Bean 初始化: 调用初始化方法。完成启动: 应用完全启动并准备好处理请求。Spring 容器会根据配置文件和注解扫描路径加载 Bean 定义。在这个阶段,Spring 解析配置文件中的 Bean 定义和注解(如@Component@Service等)。

Wells974 4733
上一篇: 一个最简单的service示例
下一篇: Presence service
cuizhf
博客等级 码龄20年 0粉丝 1原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值