<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    posts - 156,  comments - 601,  trackbacks - 0

    前一篇文章已經(jīng)把spy2servers的用戶使用手冊(cè)整理出來了,這次更新主要是把開發(fā)手冊(cè)部分的整理。

    如果沒有下載的朋友可以從下面下載spy2servers。
    1. 下載
    下載地址:
    二進(jìn)制程序
    第三方類庫(kù)下載,第三方類庫(kù)下載2  Jetty類庫(kù) 放到lib目錄下。
    api-docs
    源代碼


    開發(fā)手冊(cè):

    spy2servers對(duì)外提供三個(gè)組件接口,分別SpyComponent, AlertComponent和MessageAlertChannelActiveAwareComponent
    下面是接口的實(shí)現(xiàn)類圖:
    SpyComponent



    AlertComponent


    MessageAlertChannelActiveAwareComponent


    SpyComponet接口提供監(jiān)控組件的功能。我們可以直接去實(shí)現(xiàn)該接口即可。不過為了方便 spy2servers還提供AbstractSpyComponent抽象類
    幫助我們更快速的開發(fā)。
    下面來簡(jiǎn)單的根據(jù)來實(shí)現(xiàn)一個(gè)SimpleSpyComponent.功能很簡(jiǎn)單,就是每5秒鐘發(fā)送一個(gè)監(jiān)控消息。
    SimpleSpyComponent繼承AbstractSpyComponent。
    下面源代碼:因?yàn)閷?shí)現(xiàn)非常簡(jiǎn)單,我就不解釋了。

     1 import java.util.Date;
     2 import java.util.UUID;
     3 
     4 import org.xmatthew.spy2servers.core.AbstractSpyComponent;
     5 import org.xmatthew.spy2servers.core.Message;
     6 
     7 /**
     8  * @author Matthew Xie
     9  *
    10  */
    11 public class SimpleSpyComponent extends AbstractSpyComponent {
    12     
    13     private boolean started;
    14 
    15     /* (non-Javadoc)
    16      * @see org.xmatthew.spy2servers.core.Component#startup()
    17      */
    18     public void startup() {
    19         
    20         started = true;
    21         setStatusRun();
    22         try {
    23             while (started) {
    24                 onSpy(createMessage());
    25                 Thread.sleep(5000);
    26             }
    27         } catch (Exception e) {
    28             e.printStackTrace();
    29         }
    30     }
    31     
    32     private Message createMessage() {
    33         Message message = new Message();
    34         message.setId(UUID.randomUUID().toString());
    35         message.setCreateDate(new Date());
    36         message.setDescription("message sent by " + getName());
    37         message.setLevel(Message.LV_INFO);
    38         message.setType("Test Message");
    39         return message;
    40     }
    41 
    42     public void stop() {
    43         started = false;
    44         setStatusStop();
    45     }
    46 
    47 }


    好了,現(xiàn)在我實(shí)現(xiàn)一個(gè)監(jiān)控組件,讓我們?cè)賮韺?shí)現(xiàn)一個(gè)報(bào)警組件SimpleAlertComponet,它繼承AbstractAlertComponent抽象類。
    下面是實(shí)現(xiàn)的源代碼:功能也是超簡(jiǎn)單,就是如果組件的狀態(tài)正常,則從屏幕輸出Message消息內(nèi)容

     1 import org.xmatthew.spy2servers.core.AbstractAlertComponent;
     2 import org.xmatthew.spy2servers.core.Message;
     3 
     4 /**
     5  * @author Matthew Xie
     6  *
     7  */
     8 public class SimpleAlertComponet extends AbstractAlertComponent{
     9     
    10     private boolean started;
    11 
    12     @Override
    13     protected void onAlert(Message message) {
    14         if (started) {
    15             System.out.println(message);
    16         }
    17     }
    18 
    19     public void startup() {
    20         
    21         started = true;
    22         setStatusRun();
    23     
    24     }
    25 
    26     public void stop() {
    27         started = false;
    28         setStatusStop();
    29         
    30     }
    31 
    32 }

    接下來我們來實(shí)現(xiàn)MessageAlertChannelActiveAwareComponent組件。它的功能是消息調(diào)度監(jiān)控組件接口,提供消息調(diào)度監(jiān)控的管理。
    我們知道JmxServiceComponent組件就實(shí)現(xiàn)該接口,通過JMX服務(wù)提供消息調(diào)度情況。
    下面是實(shí)現(xiàn)的源代碼,只是把每次調(diào)試的消息打印出來

     1 import java.util.Collections;
     2 import java.util.LinkedList;
     3 import java.util.List;
     4 
     5 import org.xmatthew.spy2servers.core.AbstractComponent;
     6 import org.xmatthew.spy2servers.core.MessageAlertChannel;
     7 import org.xmatthew.spy2servers.core.MessageAlertChannelActiveAwareComponent;
     8 
     9 /**
    10  * @author Matthew Xie
    11  *
    12  */
    13 public class SimpleChannelAwareComponent extends AbstractComponent implements
    14         MessageAlertChannelActiveAwareComponent {
    15     
    16     private boolean started;
    17     
    18     private List<MessageAlertChannel> channels = Collections.synchronizedList(new LinkedList<MessageAlertChannel>());
    19 
    20     public List<MessageAlertChannel> getChannels() {
    21         return channels;
    22     }
    23 
    24     public void onMessageAlertChannelActive(MessageAlertChannel channel) {
    25         if (!started) {
    26             return;
    27         }
    28         channels.add(channel);
    29         printChannel(channel);
    30     }
    31 
    32     public void startup() {
    33         started = true;
    34         setStatusRun();
    35         
    36     }
    37 
    38     public void stop() {
    39         started = false;
    40         setStatusStop();
    41         
    42     }
    43 
    44     private void printChannel(MessageAlertChannel channel) {
    45         if (channel != null) {
    46             System.out.println("channel aware component say:");
    47             System.out.print("spyComponent is: ");
    48             System.out.println(channel.getSpyComponent());
    49             System.out.print("alertComponent is: ");
    50             System.out.println(channel.getAlertComponent());
    51             System.out.print("message is: ");
    52             System.out.println(channel.getMessage());            
    53         }
    54     }
    55 
    56 
    57 }

    ok,接下來我們來配置spy2servers.xml文件使用它工作起來。

    <?xml version="1.0" encoding="UTF-8"?>
    <beans:beans xmlns="http://www.xmatthew.org/spy2servers/schema"
        xmlns:xsi
    ="http://www.w3.org/2001/XMLSchema-instance"
        xmlns:beans
    ="http://www.springframework.org/schema/beans"
        xmlns:context
    ="http://www.springframework.org/schema/context"
        xmlns:util
    ="http://www.springframework.org/schema/util"
        xsi:schemaLocation
    ="http://www.springframework.org/schema/beans
            http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
            http://www.xmatthew.org/spy2servers/schema
            http://www.xmatthew.org/spy2servers/schema/spy2servers-1.0.xsd
            http://www.springframework.org/schema/context
            http://www.springframework.org/schema/context/spring-context-2.0.xsd"
    >

        
    <core-component> <!-- 配置核組件,這個(gè)必須要有  -->
            
    <simple-alertRule> <!-- 配置 消息報(bào)警機(jī)制-->
                
    <channel> 
                    
    <from value="mySpyComponent"/>
                    
    <to value="myAlertComponent"/>
                
    </channel>
            
    </simple-alertRule>
        
    </core-component>
        
        
    <jmxService-component/> <!-- 開啟jmx監(jiān)控服務(wù),其IP通過 java啟動(dòng)命令設(shè)置 默認(rèn)為1616 -->

        
    <!-- 定義 SimpleSpyComponent組件-->
        
    <beans:bean class="org.xmatthew.mypractise.SimpleSpyComponent">
            
    <beans:property name="name" value="mySpyComponent"></beans:property>
        
    </beans:bean>
        
        
    <!-- 定義 SimpleAlertComonent 組件-->
        
    <beans:bean class="org.xmatthew.mypractise.SimpleAlertComponet">
            
    <beans:property name="name" value="myAlertComponent"></beans:property>
        
    </beans:bean>    

        
    <!-- 定義 SimpleChannelAwareComponent 組件-->
        
    <beans:bean class="org.xmatthew.mypractise.SimpleChannelAwareComponent">
            
    <beans:property name="name" value="SimpleChannelAwareComponent"></beans:property>
        
    </beans:bean>    

      
    <jetty> <!-- 配置內(nèi)置服務(wù)器  -->
        
    <connectors>
          
    <nioConnector port="7758" /> <!-- using nio connector port is 7758 -->
        
    </connectors>
        
    <handlers>
            
    <!-- 配置內(nèi)置基于web 方式的平臺(tái)組件監(jiān)控 servlet context為 /admin  -->
          
    <servlet servletClass="org.xmatthew.spy2servers.component.web.ComponentsViewServlet" path="/admin" /> 
        
    </handlers>
      
    </jetty>
        
    </beans:beans>


    好了,現(xiàn)在我們運(yùn)行start.sh啟動(dòng)看一下效果
    INFO  Main                           - Server starting
    INFO  
    log                            - Logging to org.slf4j.impl.JCLLoggerAdapter(org.mortbay.log) via org.mortbay.log.Slf4jLog
    INFO  CoreComponent                  
    - plug component CoreComponent
    INFO  CoreComponent                  
    - plug component JmxServiceComponent
    INFO  CoreComponent                  
    - plug component mySpyComponent
    INFO  CoreComponent                  
    - plug component myAlertComponent
    INFO  CoreComponent                  
    - plug component SimpleChannelAwareComponent
    INFO  
    log                            - jetty-6.1.4

    沒問題我們的組件已經(jīng)運(yùn)行起來,接下就是五秒輸出結(jié)果:

    channel aware component say:
    spyComponent 
    is: org.xmatthew.mypractise.SimpleSpyComponent@193385d
    alertComponent 
    is: org.xmatthew.mypractise.SimpleAlertComponet@5973ea
    message 
    is: org.xmatthew.spy2servers.core.Message@171f189[id=cb8c02c8-62b3-4c7f-8dc3-aea41382c178,body=<null>,level=4,properties={},createDate=Fri Apr 25 22:39:24 CST 2008,description=message sent by mySpyComponent,type=Test Message]
    org.xmatthew.spy2servers.core.Message
    @1a897a9[id=52a954ef-2b3b-4374-a257-e3f3a9b5e209,body=<null>,level=4,properties={from=mySpyComponent, to=myAlertComponent},createDate=Fri Apr 25 22:39:29 CST 2008,description=message sent by mySpyComponent,type=Test Message]
    channel aware component say:
    spyComponent 
    is: org.xmatthew.mypractise.SimpleSpyComponent@193385d
    alertComponent 
    is: org.xmatthew.mypractise.SimpleAlertComponet@5973ea
    message 
    is: org.xmatthew.spy2servers.core.Message@17cec96[id=52a954ef-2b3b-4374-a257-e3f3a9b5e209,body=<null>,level=4,properties={},createDate=Fri Apr 25 22:39:29 CST 2008,description=message sent by mySpyComponent,type=Test Message]
    org.xmatthew.spy2servers.core.Message
    @1947496[id=548c0c9f-0aa5-480d-a91b-b0a6d98d4aeb,body=<null>,level=4,properties={from=mySpyComponent, to=myAlertComponent},createDate=Fri Apr 25 22:39:34 CST 2008,description=message sent by mySpyComponent,type=Test Message]

    可以使用JMX或是進(jìn)入web管理頁面查看組件的狀態(tài)。

    大功告成,我們已經(jīng)對(duì)spy2serves平臺(tái)提供三個(gè)組件都做了簡(jiǎn)單實(shí)現(xiàn)。
    如果有什么問題歡迎大家給我留言。

    Good Luck!
    Yours Matthew!
    2008年4月25日
    posted on 2008-04-25 22:47 x.matthew 閱讀(3642) 評(píng)論(18)  編輯  收藏 所屬分類: Spy2Servers
    主站蜘蛛池模板: 免费国产成人高清在线观看网站| 免费精品一区二区三区在线观看| 在线免费观看毛片网站| 亚洲精品网站在线观看不卡无广告 | 天天天欲色欲色WWW免费| 国产成人99久久亚洲综合精品| 亚洲综合综合在线| 免费国产在线精品一区| 1000部国产成人免费视频| 精品亚洲视频在线观看| 亚洲人成网站看在线播放| 中国在线观看免费的www| 天天操夜夜操免费视频| 亚洲一卡2卡三卡4卡有限公司| 国产AV无码专区亚洲AV蜜芽| 精品一区二区三区无码免费视频| 免费h成人黄漫画嘿咻破解版| 中文字幕亚洲色图| 一级毛片免费播放视频| 国语成本人片免费av无码| 国产V亚洲V天堂无码久久久| 久久亚洲色WWW成人欧美| 1000部禁片黄的免费看| 国产成人亚洲综合| 亚洲国产AV一区二区三区四区| 久别的草原电视剧免费观看| 免费看国产一级片| 亚洲一级毛片在线播放| 成人免费777777被爆出| 国产免费av片在线播放| 亚洲人成影院在线高清| 四虎影视成人永久免费观看视频 | 四虎影视免费永久在线观看| 亚洲精品国产电影午夜| a级毛片免费在线观看| 国产乱色精品成人免费视频| 国产亚洲sss在线播放| 精品国产sm捆绑最大网免费站 | 久久久亚洲欧洲日产国码农村| 黄页免费视频播放在线播放| 成人毛片免费视频|