Integrated GT3 Development Grid Services with Eclipse - Developing a GUI interface using SWT

xiaoxiao2021-03-06  77

Integrated GT3 Development GT3 Works with Eclipse - Use SWT Development GUI Interface 2004-04-10 Views: 874

1. Introduction Globus Toolkit 3.0 (GT3) is a specific reference implementation of the Globus organization's open grid service infrastructure OGSI (Open Grid Service InfraStructure) developed by GGF (Global Grid forum). GT3 provides a set of libraries and tools to help developers develop a grid service program that meets OGSA (Open Grid Service Architecture) in accordance with Open Grid Service Architecture. Developers need to use the GT3 development grid service, you need to use the text editor to edit the Java source file and various profiles, and compile and configure these files with AT, and finally enter the command to run the service under the console. This makes development grid services that become complicated, and users need to consider too much. Although GT3 provides a graphical grid service viewing and running tool, because the Java language itself is AWT or Swing in the development of drawbacks on the development graphical interface program, it is difficult to develop the GUI program whether it is speed or appearance. accept. Eclipse is a representative of a new generation of IDE development environment, which not only supports the development of Java languages, but also supports development in other languages. The core of Eclipse uses the architecture of the plugin. By developing plugins, developers can expand the features that can be imagined on Eclipse. Eclipse's Java Development Tool (JDT) not only supports Java syntax, but also features such as Code Assist. At the same time, an ANT plug-in is also integrated, making Eclipse development Java programs very easy. Standard Widget Toolbox Standard Widget Toolkit (SWT) is a contribution of the Eclipse organization to Java-based GUI program developed by the majority of Java programmers. The SWT toolbox is similar to Swing and AWT, which provides a group of widgets to developers. However, the main difference between the SWT and other toolboxs is that the SWT is called through the Java Local Interface (JNI) technology to invoke the underlying GUI widget of the operating system. This approach provides Java developers with a cross-platform API to implement the "look" solution like this desktop application. Based on Eclipse and ST, this article implements an echostring grid service with a notification mechanism, and has developed a GUI interface program to manage and run grid services. Echostring service is very simple: client subscribing to the service, and specifies a string when calling this service, the server-side service receives the string to the user who subscribes to this service, this service uses GT3 Notification mechanism. The system interface developed using the SWT is as follows: Figure 1 System interface This article assumes that you have a certain understanding of the grid service, and you can write some basic grid services using GT3. Should look at the reference. 2, Environment Configuration Operation System: Windows 2000 Professional Software:

GT3-Core-src.tar. (Http://www.globus.org). GT3 Core Source Packet. Eclipse-sdk-2.1-win32.zip. (Http://www.eclipse.org). Eclipse's software development package. Here I use version 2.1 under the Windows platform. 2.1 GT3 installation installation GT3 First requires the JDK and Apache Ant tools. See Resources 5. After downloading GT3-Core-src.tar, unzip into a directory, this article is decompressed into the D: // Grid // OGSA // IMPL // java directory. Then run the Ant Dist in this directory to install GT3. This requires waiting for a while, depending on your machine performance. After the installation is complete, run the Ant StartContainer in this directory, then reopen a CMD window to this directory, run the ANT GUI, if there is a successful display, indicating that the GT3 Core installation is successful. 2.2 Eclipse installation Eclipse installation is simple, just extract it into a directory. This article is decompressed to D: // Eclipse. Run Eclipse.exe directly, you will automatically look for JDK when you run, and complete the appropriate configuration, then enter the main interface of Eclipse. About Eclipse's basic usage, IBM DDeveloperWorks, Eclipse's website, and Eclipse's random documents are described in detail, which is not described in detail. If you don't mention it, the directory of GT3 is D: // Grid // OGSA // IMPL // Java; Eclipse's directory is d: // Eclipse. 3, using Eclipse and GT3 for Grid Service Development 3.1 Establishment Project Open File-> New-> Java-> Java Project, create a Java project called Sample. As shown in the figure: Figure 2 Establish an engineering Click Next to enter the next dialog, receive the default setting, then click Finish, such a Java project's framework is automatically generated. 3.2 Settings Class Path 3.2.1 Setting the GT3 path Select the Sample project established, click Right click, select Properties from the pop-up window, open the Properties window, select Java Build Path. Select Add External Jars, select the Lib folder in the GT3 installation directory from the file selection dialog box (in this article is D: // Grid // ogsa // il // java // lib), all added Come in. As shown in the figure: Figure 3 Sets the class path 3.2.2 Setting the SWT and JFACE paths because this article uses the SWT and JFACE development interfaces, so they need their JAR package. The SWT.jar package is in your Eclipse installation directory //plugin/rg.eclipse.swt.win32_2.1.0//ws//win32 directory. The JFace.jar package is in your Eclipse installation directory //plugin/rg.eclipse.jface.win32_2.1.0 directory. Find this two files and add to the class path of the Sample project. To ensure that Java's virtual machine can get the shared library of the SWT GUI when running, we also need to set the parameters: -djava.libarary.path = d: //eclipse//plugin/rg.eclipse.swt. Win32_2.1.0 // OS // Win32 // x86, add the corresponding JNI localization library, which is used when establishing a run configuration. The grid service can be developed below.

3.3 Development of Echostring Grid Services OGSI Defines the Notification Mechanism of Grid Services, which calls the message publisher to NotificationsInk. The transfer process between them is shown below: Figure 4 notified the process of the process GT3 framework for the notification mechanism is implemented by Operation Provider. GT3 provides programming mode of two ways of grid services: one is to directly inherit the GridServiceImpl class and other interfaces, which are provided by GT3 and implements an OGSI defined interface. Another way is how the Operation Provider method is also called a delegate agent. This approach allows us to easily "Plug" Different Different Implements described in the "Plug" WSDL file when the service is deployed. The GT3.0 framework currently implements the Factory and Notification Interfaces defined by OGSI in the Operation Provider. This way, if you want to add Factory and Notification behavior in your own service, you only need to configure in the deployment description file of the service. 3.3.1 Serva 3.3.1.1 Providing Service Interface GT3 provides two ways to generate a WSDL-form service interface: One is through the Java class interface, running a Java2WSDL tool to generate a WSDL document. One is to generate a WSDL document by using a GWSDL2WSDL tool by a GWSDL file. Reference 5 "Developing Grid Services in GT3" is used to generate a service interface from the Java class interface, and the service implementation inherits the GridServiceImpl class provided by GT3. Here I use the GWSDL file to describe the service interface, and the service is implemented by Operation Provider. (For detailed information, please refer to the source file and GT3 programming manual) 1. Define the serviceData mode to select the Sample project in Eclipse, create a Schema // Echostring folder, which is used to store the GWSDL file. Select the newly established Echostring folder, right-click the menu -> new-> file, create an echostringstate.xsd file. As shown below: Figure 5 Create file file content as follows: echostringstate.xsd

The implementation of the GT3 notification mechanism is closely related to ServiceData. To make the messages that contain useful information, we want to define an SDD. When the serviceData value changes, the notification source sends a notification message to the recipient in the following format. In this SDD, we define a STRING variable called Status to record the status. See Sample // Schema // echostring // echostringstate.xsd in the source file. 2. Establish a GWSDL file and add service data with the same method to create a NotificationECHOSTRING.GWSDL file in the sample // schema // echostring directory, edit the file:

Sample // schema // echostring // notificationEChostring.gwsdl

.......

TYPE = "echo: echostringstatustype"

Minoccurs = "1"

Maxoccurs = "1"

Mutability = "mutable"

Modifiable = "false"

Nillable = "false">

... ..

This code shows that this service has a type of service data for echostringstatustype. 3. Implementing the NotificationSource interface After adding the service data in GWSDL, you also need to define NotificationSource PortType in GWSDL in the GWSDL:

Extends = "OGSI: GridService Ogsi: Notificationsource" />

The part of the black body illustrates that it inherits the Notificationsource interface, which is equivalent to the message source defined by the OGSI. 3.3.1.2 Generate STUB 1. Establish a build.xml file, compile with an Eclipse, build WSDL files and service support files such as Stubs. For details, please see the sample // build.xml file. Figure 6 Sets build.xml and then runs Run-> External Tools-> External Tools, configures ANT. From Targets Select GenerateWSDL, as shown below: Figure 7 Configure an ANT and then running Run, Eclipse generates a suitable file. As shown below: Figure 8 Runs ANT Use the same method we can generate a service's Stub file. For detailed procedures, please refer to the reference information 3 and the description of this example 10. 3.3.1.3 After the service is generated, the service is enabled. We use the Operation Provider to implement this service. First create an EchostringProvide class, as shown below: Figure 9 Create a class and then add the generated build // stubs to class path, which will not report in error when editing the EchostringProvide class. As shown below: Figure 10 Sets the contents of the class path echostringProvider.java as follows:

Sample / src / org / nci / sample / echostring / notification / imp / echostringprovider.java

Public Class EchostringProvider Implements OperationProvider, GridServiceCallback {

......

// Operation Provider Methods

Public void initialize (GridServiceBase Base) throws gridServiceException {

THIS.BASE = BASE;

}

Public Qname [] getOperations () {

Return Operations;

Public void Postcreate (GridContext Context) throws gridServiceException {

ServicesData = base.getServicedASet (). Create ("echostringstate"); // Create service data

StatusData = new echostringstatustype ();

ServicesData.SetValue (statusdata);

StatusData.SetStatus ("Initialize");

Base.getServenticeDataSet (). add (servicedata); // Add service data

}

// echostring Porttype Methods

Public string echostring (string value) throws remoteException {

System.out.println ("Recieve String" Value "from client.");

StatusData.SetStatus (Value);

ServicesData.notifychange ();

Return Value;

}

......

}

Use this way to implement the service to implement two interfaces: OperationProvide and GridServiceCallback. Two methods to implement the previous interface: initialize () and getOperaions (). The service data is added to the postCreate method in the GridServiceCallback interface. Finally, we must call the serviceData's NotifyChange function in the interface echostring (), and declare the status change. This time, whenever a customer calls these remote methods, a serviceData.notifyChange () operation is called, and the recipient message is sent to the recipient of the subscription. 3.3.1.4 Service Profile After the above operation is complete, we need to write a service profile:

Sample / echostring-config.wsdd

Value = "Schema / Echostring / Notification Echostring_Service.wsdl" />

Value = "org.nci.sample.echostring.notification.notificationech" />

Value = "Org.globus.ogsa.impl.ogsi.gridservice IMPL" />

Value = "org.nci.sample.ecHostring.Notification.Impl.echostringProvider

Org.globus.ogsa.impl. Ogsi.NotificationsourceProvider "/>

........

Because we use the Operation Provider mode, the value of the parameter's instance-baseclassname is set to GridServiceImpl, which is equivalent to inheriting from this class, but not in the program, but only changing the service profile. The value of the Instance-OperationProviders parameter is a message from the service you have written by EchostringProvider and GT3 implementation NotificationsourceProvider. Then compile, package, and deploy it to the GT3 container. To this server has been developed. 3.3.2 Client Development OGSI Definition Notification Messages Transfer or Service and Message System Between Two Services. Therefore, in order to receive the notification message, the client is also like the service. GT3 provides a NOTIFICATIONSINKMANAGER class to simplify this work. NOTIFICATIONSINKMANAGER is a service container. First we have to subscribe to a service instance:

NOTIFICATIONSINKManager Manager = notificationsinkmanager.getManager ();

Manager.startListening (NotificationsinkManager.main_thread);

String sink = manager.addlistener ("echostringstatus", timeout, source, callback;

The Subscribe method in the service interface is called in the method of addListener, which is automatically called. Then we implements the callback function Callback, which is used to exchange the serviceData form in the service instance and subscribe to its client. It must implement the NotificationsinkCallback interface:

Sample / src / org / nci / sample / echostring / notification / imp / echostringClient.java

......

Public void DeliverNotification (ExtensibilityType Any) Throws RemoteException {

......

ServiceDataValuestype ServicesData = Anyhelper.getaSserviceDataValues ​​(ANY);

EchostringStatustype Echo = (echostringstatustype) Anyhelper.getassingleObject (ServiceData, EchostringStatustype.class);

System.out.println ("Notification Recieve String Form Service" ECHO.GETSTATUS ());

}

Compile to this client development is completed. Below with a picture to summarize the idea we use Notification, this is also a process of writing a general grid service: Figure 11 Development flow chart First we are interested in what information is intended to transfer between services and customers. This information is provided in the service in the form of service data. Once confirmed, we need to describe this information in XML, that is, the so-called SDD. Then we need to add this service data in the WSDL file and let the service porttype inherit the NotificationSource interface. Then, the NOTIFYCHANGE method of calling the service data in the service implementation is required to notify the service data change. The client first wants to subscribe to this service, then realize the DeliverNotification callback function in the NOTIFICATIONSINKCALLBACK interface, so that the service data will change the message to the subscribed customer through DeliveRNotification. 3.3.3 Service Interface Development SWT The emergence makes Java a big step forward on the development graphical interface application. Below I will use SWT to write the GUI program that manages the Echostring service we developed. The main functions of this program are: Ability to list all services on multiple service contapers, and you can query their service data. At the same time, the IP and ports of the service container are configurable. Ability to create a service instance for the Echostring service and call the client program to operate. This GUI program is intended to make it a grid service management program. 3.3.3.1 Basic Concept All SWT classes use org.eclipse.swt for the prefix of the package. The most commonly used graphics components are included in org.eclipse.swt.widgets. The following is a description of the important components. Display and Shell Display are responsible for managing the connection between SWT and underlying operating systems. Its most important function is to convert the SWT event loop to the mode execution of the operating system. Almost all SWT programs require an activated Display. The shell represents the window on the desktop. SHELL generally requires a DISPLAY instance as a parameter of its constructor. The window in the SWT is shown in the following figure, and a window consists of the title bar, menu, toolbar, customer area, and status bar. Figure 12 The window of the window Composite and layout Composite serves as the role of the component container, which is similar to the Panel object in Swing. If we want to add a component in the window, it is best to create a container first and select a suitable layout. The most commonly used Composite is a Group control, which makes several similar controls into a group, allowing the interface to be beautiful and tidy. The SWT is used in a combination of Layout and Layout Data, and most common use is GridLayout and GridData. Next, the specific procedure is described below. The service interface program implementation is in the org.nci.sample.echostring.gui package. 3.3.3.2 Creating a Main window Select Sample // SRC. Then select File-> New-> Class to create the mainconsole class. The main features of the MainConsole class are:

Creating a Window Create Window Menu Creative Toolbar Creating a Customer Create Status Bar Code as follows:

Sample // src // ORG // NCI // Sample // Echostring // Gui // mainconsole.java

......

Public Shell Open (Display Display) {

this.display = display;

Createshell (Display); // Create a shell

CreateMenubar (); // Create a menu

CreateSeparator (); // Create a separator

CreateToolbar (); // Creating a toolbar

CreateSeparator (); // Create a separator

CreateContent (); // Create a CREATESTATUSLINE (); // Create a status bar

Shell.Open (); // Open window

Return shell;

}

......

The above code list is to create a shell and create a menu, tool bar, etc. on this shell. The result is shown in Figure 12. 3.3.3.3 Menu and MenuItem, TOOBAR and TOOLITEM To create a menu on the Shell, first need to create a MENU object and set it to the mode of SWT.BAR. You can create a MenuItem object after you create a Menu object. Menuitem can set MENU through the setMenu method so that you can nested menu items. Such as the following code list:

Public void createmenubar () {

Menu bar = new menu (shell, swt.bar);

Shell.Setmenubar (BAR);

Menuitem fileItem = new menuItem (bar, swt.cascade);

FileItem.Settext ("File (f)");

FileItem.SetMenu (createFileMenu ()); // Add the menu item for the file menu

......

}

Similarly we create Toolbar on the Shell and create ToolItem added to Toolbar. At the same time, SWT also provides a CToolBar control that allows the toolbar to stop in any location. Please visit the source program. 3.3.3.4 Listening events and event responding to user operations in SWT, such as mouse and keyboard events, also use Swing and AWT Observer mode. In the org.eclipse.swt.events package, you can find the Listener interface and the corresponding event you listen to. For example, almost all controls have an AddSelectionListener () interface, and implement the processing function in the widgetSelected () method in the interface. As shown in the following code list, please refer to the source code.

.......

Menuitem exit = new menuitem (filemenu, swt.push);

EXIT.SETTEXT ("& Exit");

EXIT.ADDSELECTIONLISTENER (New SelectionAdapter () {

Public void widgetselected (SelectionEvent E) {

shell.close ();

}

});

......

The above code indicates that when we select the exit item in the menu, it calls the shell's close () method, exits the program. 3.3.3.5 Creating a Customer Area consists of a grid service container view and a grid service view. They are a TabITEM page in TabFolder, respectively. TabFolder is a container of TabItem, TabItem sets the TAB page through the setContorL () method. Creating a TabFolder code is as follows:

Public void createcontent () {

TabFolder = New TabFolder (Shell, Swt.Border);

GridData griddata = new griddata (griddata.fill_both);

TabFolder.setLayOutdata (GridData);

}

By setting the GridData style, this TabFolder will full of the entire customer area. Since the grid service container view and grid service instance view are a TabFolder's TabItem, and their interfaces are similar, so their implementation file serviceab.java and GridServentAb.java have a common base class Tab.java. Tab.java service creates the appearance of these two TabItem, such as tree view, service data group, console output, etc. The description will be described below. 1. Grid service container view: The grid service container view is shown in Figure 1. The current functionality is: list all services for a given grid service container in the form of a tree list You can configure a grid service container to create a grid service instance to query service data. It will gradually increase its function in the future. List all services in the service container service GT3 container are registered in the container registration service Core / RegistryService, and you can get the service registered in this service container by accessing this service. In this program, when this function is called, it first reads the serverconfig.xml file located at the sample // etc directory to get the IP and port of the service container. Then access this service in turn. code show as below:

Public void getServicesList (String Host, String Port, String Baseloc, String ServiceName) {

......

OgsiServiceGridlocator registryService = new ogsiServiceGridlocator ();

URL = New URL ("http: //" host ":" port baseloc service;

GridService Registry = registryservice.getgridServicePort (URL);

EXTENSIBILITYTYPE QueryResult = registry.findServicedata

QueryHelper.getNameSquery (ServiceData.Entry);

ServiceDataValuestype ServiceDataValues ​​= (ServiceDataValuestype) Anyhelper.getassingleObject (queryResult,

ServiceDataValuestype.class

);

Entries = anyhelper.getasobject (serviceDatavalues, entrytype.class);

......

AddTreeItem (itemhost, entry.getMemberviceLocator (). getHandle (0) .tostring ());

......

}

This code first gets the ContainerRegistryService service instance, and then obtains the service data of this service through the standard interface of the Grid service. Then get the URL of the service via the entrytype's getMemberService (). GetHandle (0) method and added to the TreeItem. Please see the source code. Creating a Service Instance GT3 provides a Factory interface to create a grid service instance. GridServiceFactory implemented this interface. So we first have to create a GridServiceFactory, then call the CreateService () method to create a service instance. And create a grid service real aspect.

......

OgSIServiceGridlocator FactoryService =

New ogsiServiceGridlocator ();

Factory factory = factoryservice.getFactoryPort

New Handletype (Textl.getText ())

);

String id = inputdialog.str;

GridServiceFactory GridFactory =

New GridServiceFactory (Factory);

// Create a service

LocatorType Locator = GridFactory.createService (NULL, ID);

CreategridServentAb (Locator);

......

Where TextL.getText () is used to get the URL of the service factory, the ID is the service instance name to be created by the user, which is entered by the user through a dialog box. Finally generate a service example view. The dialog is shown in Figure 13. Figure 13 Enter Grid Instance Name Dialog 2, Grid Serve College View Grid Service Replace View The interface is similar to the service container view function. The biggest difference is that the example view adds a program that invokes the grid service instance, that is, the client, grid service instance view is as follows: Figure 14 Grid Serve View Implementing the echostring service to add an echostringClient object in the GridServiceTab class, Used to make a client call. Add a handler to the response function of the launch service client button:

Sample // ORG // NCI // Sample // Echostring // GUI // GridServentAb.java

Button ClientStart = New Button (ClientPanel, SWT.PUSH);

ClientStart.Settext ("Start Service Client");

ClientStart.AddSelectionListener (New SelectionAdapter () {

Public void widgetselected (SelectionEvent E) {

STARTCLIENT ();

}

});

Public void startclient () {

IF (client == NULL) {

Client = new echostringClient ();

Client.subscribedata (Textl.getText (), Client);

......

}

}

This interface is developed. 3.4 operation

转载请注明原文地址:https://www.9cbs.com/read-91021.html

New Post(0)