Quick start tutorial: Writing a service
Estimated time to complete: 4-5 minutes
With your Martini package ready, you can start creating services for your application. Applications are typically a chain of services invoked upon certain conditions, and services are where you specify executable logic.
This page will describe how to write a hello
service. This service will accept a name, then return, and print
Hello, ${name}
to the console when invoked. To do this, follow the instructions (grouped by topic) below in order.
Create a new service
Create a new Gloop service using these steps:
- Expand the package you've just created.
- Right click on your package's
code
directory, and then select New > Service. - Provide a name for your service.
- Click Finish.
Quickly open views, menus, preferences, and others
If you want to open a view that is not currently displayed on screen, you can use the Quick Access bar in Martini Desktop to swiftly search and open your desired view. You can use this feature to re-open interfaces closed accidentally.
Add a name
input property
The Greet
service will be accepting an input called name
. To add an input property called
name
to your service, follow these steps:
- If the
Greet
service isn't open, double-click on it in the Navigator. - At the bottom of the window, select the Input/Output tab.
- This tab's content is split into two sections: Input and Output. In the Input half, (which is on the left-hand side) click the green, '+'-labeled button on the toolbar, and then select Add String.
- A new string property will be added in the Input half of the tab.
Set this property's name to
name
while in edit mode, and then press . If the property name isn't editable, click on it then press either or to make the name editable.
I messed up Martini's layout. How do I reset it?
Missing views and menus, jumbled layout - has this ever happened to you? Fortunately, Martini Desktop makes it easy to go back to the default perspective. At the top right hand side of Martini Desktop's window:
- Right click on the active perspective icon.
- From the appearing context menu, select Reset.
- A dialog will appear to confirm your action; select Reset.
Declaring a new input or output the ninja way
If you prefer to use a keyboard instead of a mouse or touchpad whilst developing, you can also declare properties using content-assist. You can learn more about content-assist here.
Add a greeting
output property
The service will also be producing an output called greeting
. This is the Hello, ${name}
string the Greet
service will be returning when invoked. To specify service outputs, output properties must be added. To add an output
property named greeting
to your service, follow these steps:
- If the
Greet
service isn't open, double click on it in the Navigator. - At the bottom of the window, select the Input/Output tab.
- This tab's content is split into two sections: Input and Output. In the Output half, (which is on the right-hand side) click the green, '+'-labeled button on the toolbar, and then select Add String.
- A new String property will be added in the Output half of the tab.
Set this property's name to
greeting
while in edit mode, and then press . If the property name isn't editable, click on it then press either or to make the name editable.
Set greeting
's value
The greeting
property value will now be set to Hello, ${name}
, where name
will be substituted by the value of
the name
input property at runtime.
To set the greeting
property's value:
- If the
Greet
service isn't open, double click on it in the Navigator. - Click the step editor to shift focus to it.
- Click the green, '+'-labeled button on the toolbar, and then select Add Map.
- Double click the newly added map step to open the Mapper view.
- Double click the
greeting
property in the Mapper view. The Set Expression dialog will appear. - Enable script evaluation by selecting Groovy from the Language dropdown.
-
In the dialog's editor, provide the following expression:
1
"Hello, ${name}"
-
Click OK.
Log greeting
to the console
To log greeting
to the console, you need to add an invoke step that calls
LoggerMethods.println(String)
. To do this:
- If the
Greet
service isn't open, double click on it in the Navigator. - Click the step editor to shift focus to it.
- Press the key to trigger content-assist.
- Search for
LoggerMethods.println(String)
. - Use the and keys to select the method, then press to add it to the service (or double-click on it).
- While the newly added invoke step is selected, open the Mapper view.
- In the Mapper view, create a map line from
greeting
tomessage
.
Test your service by running it
After saving your changes, you can run your Gloop service in order to test if it works as expected. To do this, open the service in the editor and then click the run button on the toolbar.
When you run the service, you will be asked to provide a value for the name
input property.
Upon finalizing your inputs, the Console view will also open, and the service will execute.
After running, you will see the Hello, ${name}
message printed on the Console view. If you entered Bob
as the
name
, then you will see a Hello, Bob
message.
When the service terminates, you'll see these messages at the end of the Console view:
1 2 |
|
Click the <Click here to see output>
link to see the greeting
output returned by your service,
which should be Hello, ${name}
.