智慧城市柵格操作系統-服務封裝說明書V1.2.12083

3.2.2.1[4]


選擇資源屬性的信息提供者以及查詢方式,點擊Finish,如圖3.2.2.1[5]

3.2.2.1[5]

至此,一個網格服務工程創建完畢。在Eclipse的各個工作區顯示如圖3.2.2.1[6]所示。

3.2.2.1[6]

3.2.2    編寫服務定義文件

在此部分中,主要是對要封裝為服務的資源屬性以及各種操作進行定義,並指明了收集資源屬性信息的聚集源類型等相關信息。其具體過程是在文件Database.java中實現的,大致內容如下所示:

package org.globus.grid.database;

 

import de.fb12.gdt.GridService;

import de.fb12.gdt.GridAttribute;

import de.fb12.gdt.GridMethod;

 

import com.kuiyi.examples.database.*;

 

@GridService (name = “Database”, namespace = “http://globus.org/grid/Database”, targetPackage = “org.globus.grid.database”, serviceStyle = “SSTYLE_SIMPLE”, resourceStyle = “RSTYLE_GLOBUS”, operationProvider = “GetRPProvider, GetMRPProvider, QueryRPProvider”, loadOnStartup = true, filePersistentResource = false, hotLoadable = false, securityDesc = “[]”, clientSecurityDesc = “[]”, resourceSecurityDesc = “[]”)

public
class Database {

    

    @GridAttribute(mds_agg_type=“Query”,mds_renew=“300”,mds_term_time=“2008-08-08T00:00:00”,mds_query_type=“GetMultipleResourceProperties”,mds_query_poll=“100000”) private String ResourceType; //源的屬性

 

    public String getResourceType() { //屬性的set()和get()方法

        return
ResourceType;

    }

    public
void setResourceType(String resourceType) {

        ResourceType = resourceType;

    }

    @GridMethod
public String[] findexpfrommaterial(String type){ //
外介面1

        String[] result = null;

        DataSearch q = new DataSearch(); //引用業務邏輯

        result = q.SearchExpFromMaterial(type);

        return result;

    }

    @GridMethod
public String[] findexpfromsc(String type, String dimension){ //
外介面2

        String[] result = null;

        DataSearch q = new DataSearch(); //引用業務邏輯

        result = q.SearchExpFromSC(type, dimension);

        return result;

    }

    @GridMethod
public String[] findexpfromscandmaterial(String materialtype, String sctype, String scdimension){ //
外介面3

        String[] result = null;

        DataSearch q = new DataSearch(); //引用業務邏輯

        result = q.SearchExpFromSCAndMaterial(materialtype, sctype, scdimension);

        return result;

    }

}

Database.java中可以只定義變數(資源屬性)和方法(對外介面),具體的業務邏輯可以在生成的服務代碼中添加。

編輯完Database.java文件後,點擊保存按鈕。保存成功後,GDT會自動根據編寫的java文件生成服務代碼、wsdl文件以及各種配置文件。在Eclipse的左側工作區DatabaseService工程的目錄如圖3.2.2.2所示:

3.2.2.2 工程目錄

3.3    資源屬性初始化及對外介面實現

在此部分,要做的工作有兩項:一方面是在網格服務的資源文件DatabaseResource.java中初始化上一部分所定義屬性;另一方面是在網格服務文件DatabaseService.java中實現了對外介面。

首先,對所定義屬性的初始化方法如下所示:

/**

     *

     *
@modifiablegenerated

     */

    public
void initialize()

    {

        this.propSet = new SimpleResourcePropertySet(RESOURCE_PROPERTIES);

        try {

     ResourceTypeRP = new SimpleResourceProperty(RP_RESOURCETYPE);

     this.ResourceTypeRP.add(new Object());

         this.propSet.add(ResourceTypeRP);

        } catch (Exception e) {

         throw
new RuntimeException(e.getMessage());

        }

        // begin-user-code

     this.setResourceType(“DatabaseResource”); //將屬性ResourceType初始化DatabaseResource

        // end-user-code

    }

其次,對外介面的實現方法如下所示:

/**

     *

     *
@modifiablegenerated

     */

    public FindexpfrommaterialResponse findexpfrommaterial(Findexpfrommaterial complexType) throws RemoteException {        

        FindexpfrommaterialResponse response = new FindexpfrommaterialResponse();

 

        // begin-user-code

        String[] result = null; //外介面1的初始化

        DataSearch q = new DataSearch();

        result = q.SearchExpFromMaterial(complexType.getType());

        response.setFindexpfrommaterialReturn(result);

        // end-user-code

        return response;        

    }

 

/**

     *

     *
@modifiablegenerated

     */

    public FindexpfromscResponse findexpfromsc(Findexpfromsc complexType) throws RemoteException {        

        FindexpfromscResponse response = new FindexpfromscResponse();

 

        // begin-user-code

        String[] result = null; //外介面2的初始化

        DataSearch q = new DataSearch();

        result = q.SearchExpFromSC(complexType.getType(), complexType.getDimension());

        response.setFindexpfromscReturn(result);

        // end-user-code

        return response;        

    }

    

/**

     *

     *
@modifiablegenerated

     */

    public FindexpfromscandmaterialResponse findexpfromscandmaterial(Findexpfromscandmaterial complexType) throws RemoteException {        

        FindexpfromscandmaterialResponse response = new FindexpfromscandmaterialResponse();

 

        // begin-user-code

        String[] result = null; //外介面3的初始化

        DataSearch q = new DataSearch();

        result = q.SearchExpFromSCAndMaterial(complexType.getMaterialtype(), complexType.getSctype(), complexType.getScdimension());

        response.setFindexpfromscandmaterialReturn(result);

        // end-user-code

        return response;        

    }

3.4    編譯生成存根類及gar包

以上所有的操作都完成後,可以說網格服務已經開發完成了。接下來,還需要將生成把DatabaseService服務部署到GT4容器中去所需要的gar包。具體過程如下:

1、點擊圖標,編譯生成存根類。在Console工作區顯示如下結果時,表示編譯成功。

此時,在Eclipse左側的區域此項目的目錄如圖3.2.4[1]所示:

3.2.4[1] 工程目錄

2、點擊圖標,生成部署時需要用的gar包。在Console工作區顯示如

以下文章點擊率最高

Loading…

     

如果這文章對你有幫助,請掃左上角微信支付-支付寶,給於打賞,以助博客運營