随笔-128  评论-55  文章-5  trackbacks-0
  WS-ResourceLifetime协议

WS-ResourceLifetime协议定义了WS-Resource的资源销毁机制,其中包括资源的立即销毁和资源的调度销毁。立即销毁使得客户可以显示地要求对特定的WS-Resource进行销毁,从而释放该WS-Resource占用的系统资源。调度销毁则允许客户通过设定某个WS-Resource的预定销毁时间(Termination Time),由引擎负责在其生命周期结束时对其进行销毁。在每一种情况都要明白,只有 WS-Resource 有状态资源和 Web 服务的关联—被销毁。资源本身和 Web 服务都没有受到影响

另外值得注意的是此协议并没有定义WS-Resource的创建方式。

1.1.1.1    创建WS-Resource

我们可以发送“create”消息:

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">

    <SOAP-ENV:Header/>

    <SOAP-ENV:Body>

        <createSatellite  xmlns="http://example.com/satellite"/>

    </SOAP-ENV:Body>

</SOAP-ENV:Envelope>

结果是一个 SOAP 消息,其中包含对操作创建的 WS-Resource 的端点引用

<SOAP-ENV:Envelope  xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">

    <SOAP-ENV:Header/>

    <SOAP-ENV:Body>

       <wsa:EndpointReference  xmlns:wsa="http://www.w3.org/2005/02/addressing"

             xmlns:sat="http://example.org/satelliteSystem">

           <wsa:Address> http://example.com/satellite</wsa:Address>

           <wsa:ReferenceProperties>

               <sat:SatelliteId>SAT9928</sat:SatelliteId>

           </wsa:ReferenceProperties>

       </wsa:EndpointReference>

    </SOAP-ENV:Body>

</SOAP-ENV:Envelope>

该端点引用惟一地识别正在谈论的 WS-Resource,所以我们可以使用它来销毁该 WS-Resource

1.1.1.2    立即销毁WS-Resource

当我们准备销毁 WS-Resource 时,可以使用它的端点引用来创建 SOAP 请求:

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"

      xmlns:sat="http://example.org/satelliteSystem"

      xmlns:wsa="http://www.w3.org/2005/02/addressing"

      xmlns:wsrl="http://docs.oasis-open.org/wsrf/2004/06/wsrf-WS-ResourceLifetime-1.2-draft-01.xsd">

    <SOAP-ENV:Header>

       <wsa:Action>

           http://docs.oasis-open.org/wsrf/2004/06/WS-ResourceLifetime/Destroy

       </wsa:Action>

       <wsa:To SOAP-ENV:mustUnderstand="1">

            http://example.com/satellite

       </wsa:To>

       <sat:SatelliteId>SAT9928</sat:SatelliteId>

    </SOAP-ENV:Header>

    <SOAP-ENV:Body>

       <wsrl:Destroy />

    </SOAP-ENV:Body>

</SOAP-ENV:Envelope>

 

假设一切正常,我们会收到确认消息:

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"

       xmlns:sat="http://example.org/satelliteSystem"

       xmlns:wsa="http://www.w3.org/2005/02/addressing"

     xmlns:wsrl="http://docs.oasis-open.org/wsrf/2004/06/wsrf-WS-ResourceLifetime-1.2-draft-01.xsd">

    <SOAP-ENV:Header>

       <wsa:Action>

            http://docs.oasis-open.org/wsrf/2004/06/WS-ResourceLifetime/DestroyResponse

       </wsa:Action>

       <wsa:To SOAP-ENV:mustUnderstand="1">

            http://example.com/myClient

       </wsa:To>

    </SOAP-ENV:Header>

    <SOAP-ENV:Body>

       <wsrl:DestroyResponse />

    </SOAP-ENV:Body>

</SOAP-ENV:Envelope>

这似乎不怎么像确认消息,但是只要收到它,就可以知道一切正常。如果不是一切正常,就会得到 WSRF 故障:WS-ResourceLifetime 中所讨论的一条 fault 消息。如果在 WS-Resource 销毁后还试图访问它,也会得到故障消息。

我们也可以安排 WS-Resource 在以后销毁。

1.1.1.3    调度销毁WS-Resource

我们并不总是想要当场销毁 WS-Resource。在有些情况下,我们只是想要保持 WS-Resource 活跃一段特定的时间,然后再让它销毁。为了做到这一点,我们需要给 WS-Resource 附加一个 TerminationTime 属性,这意味着将它添加到资源属性文档。对于我们的人造卫星,意味着类似下面的这些东西:

<satProp:GenericSatelliteProperties

    xmlns:satProp="http://example.com/satellite"

    xmlns:counterProp="http://example.com/satellite/CounterSatelliteProperties"

    xmlns:wsrl="http://docs.oasis-open.org/wsrf/2004/06/wsrf-WS-ResourceLifetime-1.2-draft-01.xsd">

   <satProp:latitude>30.3</satProp:latitude>

   <satProp:longitude>223.2</satProp:latitude>

   <satProp:altitude>47700</satProp:altitude>

   <satProp:pitch>49</satProp:pitch>

   <satProp:yaw>0</satProp:yaw>

   <satProp:roll>32</satProp:roll>

   <satProp:focalLength>

       21999992

   </satProp:focalLength>

   <satProp:currentView>

       http://example.com/satellite/2239992333.zip

   </satProp:currentView>

   <counterProp:currentCount>

       92828

   </counterProp:currentCount>

   <wsrl:TerminationTime>

       2005-12-31T12:00:00

   </wsrl:TerminationTime>

   <wsrl:CurrentTime>2005-2-15T03:24:57</CurrentTime>

</satProp:GenericSatelliteProperties>

如果像本例中一样,没有指定时区,就会假设是格林威治标准时间。

注意,除了 TerminationTime,我们还添加了 CurrentTime。该属性使我们不必同步时钟,下面您就会看到。

 

获得 CurrentTime TerminationTime

由于不同系统上的客户机,因而潜在地存在时钟同步的严重问题。例如,假设我们想要指定刚才创建的人造卫星 WS-Resource 应该在 4 小时后终止。选择一个相对于客户机的时间将会成为问题,因为在预定销毁情况下,实际上是由服务器销毁引用的。

幸运的是,WS-Resource 带有自己的“当前时间”。因为它是资源属性文档的一部分,所以我们可以像请求任何其他属性一样请求它:

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"

      xmlns:sat="http://example.org/satelliteSystem"

      xmlns:wsa="http://www.w3.org/2005/02/addressing"

      xmlns:wsrp="http://docs.oasis-open.org/wsrf/2004/06/wsrf-WS-ResourceProperties-1.2-draft-01.xsd"

      xmlns:wsrl="http://docs.oasis-open.org/wsrf/2004/06/wsrf-WS-ResourceLifetime-1.2-draft-01.xsd">

    <SOAP-ENV:Header>

       <wsa:Action>

          http://docs.oasis-open.org/wsrf/2004/06/WS-ResourceProperties/GetMultipleResourceProperties

       </wsa:Action>

       <wsa:To SOAP-ENV:mustUnderstand="1">

            http://example.com/satellite

       </wsa:To>

       <sat:SatelliteId>SAT9928</sat:SatelliteId>

    </SOAP-ENV:Header>

    <SOAP-ENV:Body>

       <wsrp:GetMultipleResourceProperties>

          <wsrp:ResourceProperty>wsrl:CurrentTime</wsrp:ResourceProperty>

          <wsrp:ResourceProperty>wsrl:TerminationTime</wsrp:ResourceProperty>

       </wsrp:GetMultipleResourceProperties>

    </SOAP-ENV:Body>

</SOAP-ENV:Envelope>

 

在本例中,我们请求了 CurrentTime TerminationTime,所以响应中包含了它们俩:

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"

       xmlns:sat="http://example.org/satelliteSystem"

       xmlns:wsa="http://www.w3.org/2005/02/addressing"

      xmlns:wsrp="http://docs.oasis-open.org/wsrf/2004/06/wsrf-WS-ResourceProperties-1.2-draft-01.xsd"

      xmlns:wsrl="http://docs.oasis-open.org/wsrf/2004/06/wsrf-WS-ResourceLifetime-1.2-draft-01.xsd">

    <SOAP-ENV:Header>

       <wsa:Action> http://docs.oasis-open.org/wsrf/2004/06/WS-Resour

ceProperties/GetMutlipleResourcePropertiesResponse

       </wsa:Action>

       <wsa:To SOAP-ENV:mustUnderstand="1">

            http://example.com/myClient

       </wsa:To>

    </SOAP-ENV:Header>

    <SOAP-ENV:Body>

       <wsrp:GetMultipleResourcePropertiesResponse>

          <wsrl:CurrentTime>2005-2-15T03:24:57</wsrl:CurrentTime>

          <wsrl:TerminationTime>2005-2-15T03:30:00</wsrl:TerminationTime>

       </wsrp:GetMultipleResourcePropertiesResponse>

    </SOAP-ENV:Body>

</SOAP-ENV:Envelope>

 

在应用程序中,然后我们可以使用 CurrentTime 来确定和设置新的 TerminationTime

注意,尽管我们可以像请求任何其他资源属性一样请求 CurrentTime TerminationTime,但是不能像设置任何其他资源属性一样设置它们。CurrentTime 是只读的,而 TerminationTime 必须使用我们下面将会看到的消息来设置

 

设置新的 TerminationTime

一旦为 TerminationTime 确定了适当的值,我们就可以发送 SetTerminationTime 消息了:

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"

      xmlns:sat="http://example.org/satelliteSystem"

      xmlns:wsa="http://www.w3.org/2005/02/addressing"

      xmlns:wsrp="http://docs.oasis-open.org/wsrf/2004/06/wsrf-WS-ResourceProperties-1.2-draft-01.xsd"

      xmlns:wsrl="http://docs.oasis-open.org/wsrf/2004/06/wsrf-WS-ResourceLifetime-1.2-draft-01.xsd">

    <SOAP-ENV:Header>

       <wsa:Action>

           http://docs.oasis-open.org/wsrf/2004/06/WS-ResourceLifetime/SetTerminationTime

       </wsa:Action>

       <wsa:To SOAP-ENV:mustUnderstand="1">

            http://example.com/satellite

       </wsa:To>

       <sat:SatelliteId>SAT9928</sat:SatelliteId>

    </SOAP-ENV:Header>

    <SOAP-ENV:Body>

       <wsrl:SetTerminationTime>

          <wsrl:RequestedTerminationTime>

                 2005-2-15T07:24:00

          </wsrl:RequestedTerminationTime>

       </wsrl:SetTerminationTime>

    </SOAP-ENV:Body>

</SOAP-ENV:Envelope>

注意,我们不是通过直接操纵 TerminationTime 属性来设置时间的。这是因为我们需要系统实施它自己的任何一个时间相关规则,比如,不缩短资源的生存期,或者不扩展它超过某个特定的点

响应消息包含新的 TerminationTime CurrentTime

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"

       xmlns:sat="http://example.org/satelliteSystem"

       xmlns:wsa="http://www.w3.org/2005/02/addressing"

     xmlns:wsrp="http://docs.oasis-open.org/wsrf/2004/06/wsrf-WS-ResourceProperties-1.2-draft-01.xsd"

     xmlns:wsrl="http://docs.oasis-open.org/wsrf/2004/06/wsrf-WS-ResourceLifetime-1.2-draft-01.xsd">

    <SOAP-ENV:Header>

       <wsa:Action>

           http://docs.oasis-open.org/wsrf/2004/06/WS-ResourceLifetime/SetTerminationTimeResponse

       </wsa:Action>

       <wsa:To SOAP-ENV:mustUnderstand="1">

            http://example.com/myClient

       </wsa:To>

    </SOAP-ENV:Header>

    <SOAP-ENV:Body>

       <wsrl:SetTerminationTimeResponse>

          <wsrl:NewTerminationTime>2005-2-15T07:24:00</wsrl:NewTerminationTime>

          <wsrl:CurrentTime>2005-2-15T03:25:08</wsrl:CurrentTime>

       </wsrl:SetTerminationTimeResponse>

    </SOAP-ENV:Body>

</SOAP-ENV:Envelope>

除非应用程序本身具有设置时间的特定规则,否则没有任何特殊的约束。您甚至可以将 TerminationTime 设置为过去的值,这与发送 Destroy 消息的效果是一样的。

 



Author: orangelizq
email: orangelizq@163.com

欢迎大家访问我的个人网站 萌萌的IT人
posted on 2009-07-19 15:45 桔子汁 阅读(320) 评论(0)  编辑  收藏 所属分类: Web Service

只有注册用户登录后才能发表评论。


网站导航: