blob: 91c1d045ce44d588322e7861d5eea7fb1e29b5c5 [file] [log] [blame]
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" dir="ltr">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="keywords" content="SMILA/Documentation/HowTo/How to write a Worker,SMILA/Development Guidelines/Create a bundle (plug-in),SMILA/Development Guidelines/Create a test bundle (plug-in),SMILA/Development Guidelines/Howto set up dev environment,SMILA/Documentation/JobManager,SMILA/Documentation/WorkerManager" />
<link rel="shortcut icon" href="http://wiki.eclipse.org/SMILA/Documentation/HowTo/favicon.ico" />
<link rel="search" type="application/opensearchdescription+xml" href="http://wiki.eclipse.org/opensearch_desc.php" title="Eclipsepedia (English)" />
<link rel="alternate" type="application/rss+xml" title="Eclipsepedia RSS Feed" href="http://wiki.eclipse.org/index.php?title=Special:Recentchanges&amp;feed=rss" />
<link rel="alternate" type="application/atom+xml" title="Eclipsepedia Atom Feed" href="http://wiki.eclipse.org/index.php?title=Special:Recentchanges&amp;feed=atom" />
<title>SMILA/Documentation/HowTo/How to write a Worker - Eclipsepedia</title>
<style type="text/css" media="screen,projection">/*<![CDATA[*/ @import "/skins/eclipsenova/novaWide.css?116"; /*]]>*/</style>
<link rel="stylesheet" type="text/css" media="print" href="http://wiki.eclipse.org/skins/eclipsenova/eclipsenovaPrint.css?116" />
<link rel="stylesheet" type="text/css" media="handheld" href="http://wiki.eclipse.org/skins/eclipsenova/handheld.css?116" />
<link rel="stylesheet" type="text/css" href="http://wiki.eclipse.org/skins/eclipsenova/Nova/css/header.css" media="screen" />
<link rel="stylesheet" type="text/css" href="http://wiki.eclipse.org/skins/eclipsenova/tabs.css" media="screen" />
<link rel="stylesheet" type="text/css" href="http://wiki.eclipse.org/skins/eclipsenova/Nova/css/visual.css" media="screen" />
<link rel="stylesheet" type="text/css" href="http://wiki.eclipse.org/skins/eclipsenova/Nova/css/layout.css" media="screen" />
<link rel="stylesheet" type="text/css" href="http://wiki.eclipse.org/skins/eclipsenova/Nova/css/footer.css" media="screen" />
<!--[if IE]><link rel="stylesheet" type="text/css" href="/skins/eclipsenova/IEpngfix.css" media="screen" /><![endif]-->
<!--[if lt IE 5.5000]><style type="text/css">@import "/skins/eclipsenova/IE50Fixes.css?116";</style> <![endif]-->
<!--[if IE 5.5000]><style type="text/css">@import "/skins/eclipsenova/IE55Fixes.css?116";</style><![endif]-->
<!--[if IE 6]><style type="text/css">@import "/skins/eclipsenova/IE60Fixes.css?116";</style><![endif]-->
<!--[if IE 7]><style type="text/css">@import "/skins/eclipsenova/IE70Fixes.css?116";</style><![endif]-->
<!--[if lt IE 7]><script type="text/javascript" src="/skins/common/IEFixes.js?116"></script>
<meta http-equiv="imagetoolbar" content="no" /><![endif]-->
<script type= "text/javascript">/*<![CDATA[*/
var skin = "eclipsenova";
var stylepath = "/skins";
var wgArticlePath = "/$1";
var wgScriptPath = "";
var wgScript = "/index.php";
var wgServer = "http://wiki.eclipse.org";
var wgCanonicalNamespace = "";
var wgCanonicalSpecialPageName = false;
var wgNamespaceNumber = 0;
var wgPageName = "SMILA/Documentation/HowTo/How_to_write_a_Worker";
var wgTitle = "SMILA/Documentation/HowTo/How to write a Worker";
var wgAction = "view";
var wgRestrictionEdit = [];
var wgRestrictionMove = [];
var wgArticleId = "33513";
var wgIsArticle = true;
var wgUserName = null;
var wgUserGroups = null;
var wgUserLanguage = "en";
var wgContentLanguage = "en";
var wgBreakFrames = false;
var wgCurRevisionId = "288329";
var wgVersion = "1.12.0";
var wgEnableAPI = true;
var wgEnableWriteAPI = false;
/*]]>*/</script>
<script type="text/javascript" src="http://wiki.eclipse.org/skins/common/wikibits.js?116"><!-- wikibits js --></script>
<!-- Performance mods similar to those for bug 166401 -->
<script type="text/javascript" src="http://wiki.eclipse.org/index.php?title=-&amp;action=raw&amp;gen=js&amp;useskin=eclipsenova"><!-- site js --></script>
<!-- Head Scripts -->
<script type="text/javascript" src="http://wiki.eclipse.org/skins/common/ajax.js?116"></script>
<style type="text/css">/*<![CDATA[*/
.source-javascript {line-height: normal; font-size: medium;}
.source-javascript li {line-height: normal;}
/**
* GeSHi Dynamically Generated Stylesheet
* --------------------------------------
* Dynamically generated stylesheet for javascript
* CSS class: source-javascript, CSS id:
* GeSHi (C) 2004 - 2007 Nigel McNie (http://qbnz.com/highlighter)
*/
.source-javascript .de1, .source-javascript .de2 {font-family: 'Courier New', Courier, monospace; font-weight: normal;}
.source-javascript {}
.source-javascript .head {}
.source-javascript .foot {}
.source-javascript .imp {font-weight: bold; color: red;}
.source-javascript .ln-xtra {color: #cc0; background-color: #ffc;}
.source-javascript li {font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;}
.source-javascript li.li2 {font-weight: bold;}
.source-javascript .kw1 {color: #000066; font-weight: bold;}
.source-javascript .kw2 {color: #003366; font-weight: bold;}
.source-javascript .kw3 {color: #000066;}
.source-javascript .co1 {color: #009900; font-style: italic;}
.source-javascript .coMULTI {color: #009900; font-style: italic;}
.source-javascript .es0 {color: #000099; font-weight: bold;}
.source-javascript .br0 {color: #66cc66;}
.source-javascript .st0 {color: #3366CC;}
.source-javascript .nu0 {color: #CC0000;}
.source-javascript .me1 {color: #006600;}
.source-javascript .sc0 {}
.source-javascript .sc1 {}
.source-javascript .sc2 {}
.source-javascript .sc3 {}
.source-javascript .re0 {color: #0066FF;}
/*]]>*/
</style>
<style type="text/css">/*<![CDATA[*/
@import "/index.php?title=MediaWiki:Geshi.css&usemsgcache=yes&action=raw&ctype=text/css&smaxage=18000";
/*]]>*/
</style><link rel="stylesheet" type="text/css" href="How_to_write_a_Worker.html" /> </head>
<body class="mediawiki ns-0 ltr page-SMILA_Documentation_HowTo_How_to_write_a_Worker">
<div id="globalWrapper">
<div id="column-one">
<!-- Eclipse Additions for the Top Nav start here M. Ward-->
<div id="header">
<div id="header-graphic">
<img src="http://wiki.eclipse.org/skins/eclipsenova/eclipse.png" alt="Eclipse Wiki">
</div>
<!-- Pulled 101409 Mward -->
<div class="portlet" id="p-personal">
<div class="pBody">
<ul>
<li id="pt-login"><a href="http://wiki.eclipse.org/index.php?title=Special:Userlogin&amp;returnto=SMILA/Documentation/HowTo/How_to_write_a_Worker">Log in</a></li>
</ul>
</div>
</div>
<div id="header-icons">
<div id="sites">
<ul id="sitesUL">
<li><a href="http://www.eclipse.org"><img src="http://dev.eclipse.org/custom_icons/eclipseIcon.png" width="28" height="28" alt="Eclipse Foundation" title="Eclipse Foundation" /><div>Eclipse Foundation</div></a></li>
<li><a href="http://marketplace.eclipse.org"><img src="http://dev.eclipse.org/custom_icons/marketplace.png" width="28" height="28" alt="Eclipse Marketplace" title="Eclipse Marketplace" /><div>Eclipse Marketplace</div></a></li>
<li><a href="https://bugs.eclipse.org/bugs"><img src="http://dev.eclipse.org/custom_icons/system-search-bw.png" width="28" height="28" alt="Bugzilla" title="Bugzilla" /><div>Bugzilla</div></a></li>
<li><a href="http://live.eclipse.org"><img src="http://dev.eclipse.org/custom_icons/audio-input-microphone-bw.png" width="28" height="28" alt="Live" title="Live" /><div>Eclipse Live</div></a></li>
<li><a href="http://planeteclipse.org"><img src="http://dev.eclipse.org/large_icons/devices/audio-card.png" width="28" height="28" alt="PlanetEclipse" title="Planet" /><div>Planet Eclipse</div></a></li>
<li><a href="http://portal.eclipse.org"><img src="http://dev.eclipse.org/custom_icons/preferences-system-network-proxy-bw.png" width="28" height="28" alt="Portal" title="Portal" /><div>My Foundation Portal</div></a></li>
</ul>
</div>
</div>
</div>
<!-- NEW HEADER STUFF HERE -->
<div id="header-menu">
<div id="header-nav">
<ul> <li><a class="first_one" href="http://wiki.eclipse.org/" target="_self">Home</a></li> <li><a href="http://www.eclipse.org/downloads/" target="_self">Downloads</a></li>
<li><a href="http://www.eclipse.org/users/" target="_self">Users</a></li>
<li><a href="http://www.eclipse.org/membership/" target="_self">Members</a></li>
<li><a href="http://wiki.eclipse.org/index.php/Development_Resources" target="_self">Committers</a></li>
<li><a href="http://www.eclipse.org/resources/" target="_self">Resources</a></li>
<li><a href="http://www.eclipse.org/projects/" target="_self">Projects</a></li>
<li><a href="http://www.eclipse.org/org/" target="_self">About Us</a></li>
</ul>
</div>
<div id="header-utils">
<!-- moved the search window here -->
<form action="http://wiki.eclipse.org/Special:Search" >
<input class="input" name="search" type="text" accesskey="f" value="" />
<input type='submit' onclick="this.submit();" name="go" id="searchGoButton" class="button" title="Go to a page with this exact name if one exists" value="Go" />&nbsp;
<input type='submit' onclick="this.submit();" name="fulltext" class="button" id="mw-searchButton" title="Search Eclipsepedia for this text" value="Search" />
</form>
</div>
</div>
<!-- Eclipse Additions for the Header stop here -->
<!-- Additions and mods for leftside nav Start here -->
<!--Started nav rip here-->
<!-- these are the nav controls main page, changes etc -->
<div id="novaContent" class="faux">
<div id="leftcol">
<ul id="leftnav">
<!-- these are the page controls, edit history etc -->
<li class="separator"><a class="separator">Navigation &#160;&#160;</li>
<li id="n-mainpage"><a href="http://wiki.eclipse.org/Main_Page">Main Page</a></li>
<li id="n-portal"><a href="http://wiki.eclipse.org/Eclipsepedia:Community_Portal">Community portal</a></li>
<li id="n-currentevents"><a href="http://wiki.eclipse.org/Eclipsepedia:Current_events">Current events</a></li>
<li id="n-recentchanges"><a href="http://wiki.eclipse.org/Special:Recentchanges">Recent changes</a></li>
<li id="n-randompage"><a href="http://wiki.eclipse.org/Special:Random">Random page</a></li>
<li id="n-help"><a href="http://wiki.eclipse.org/Help:Contents">Help</a></li>
<li class="separator"><a class="separator">Toolbox &#160;&#160;</a></li>
<li id="t-whatlinkshere"><a href="http://wiki.eclipse.org/Special:Whatlinkshere/SMILA/Documentation/HowTo/How_to_write_a_Worker">What links here</a></li>
<li id="t-recentchangeslinked"><a href="http://wiki.eclipse.org/Special:Recentchangeslinked/SMILA/Documentation/HowTo/How_to_write_a_Worker">Related changes</a></li>
<!-- This is the toolbox section -->
<li id="t-upload"><a href="http://wiki.eclipse.org/Special:Upload">Upload file</a></li>
<li id="t-specialpages"><a href="http://wiki.eclipse.org/Special:Specialpages">Special pages</a></li>
<li id="t-print"><a href="http://wiki.eclipse.org/index.php?title=SMILA/Documentation/HowTo/How_to_write_a_Worker&amp;printable=yes">Printable version</a></li> <li id="t-permalink"><a href="http://wiki.eclipse.org/index.php?title=SMILA/Documentation/HowTo/How_to_write_a_Worker&amp;oldid=288329">Permanent link</a></li> </ul>
</div>
<!-- Additions and mods for leftside nav End here -->
<div id="column-content">
<div id="content">
<a name="top" id="top"></a>
<div id="tabs">
<ul class="primary">
<li class="active"><a href="How_to_write_a_Worker.html"><span class="tab">Page</span></a></li>
<li><a href="http://wiki.eclipse.org/index.php?title=Talk:SMILA/Documentation/HowTo/How_to_write_a_Worker&amp;action=edit"><span class="tab">Discussion</span></a></li>
<li><a href="http://wiki.eclipse.org/index.php?title=SMILA/Documentation/HowTo/How_to_write_a_Worker&amp;action=edit"><span class="tab">View source</span></a></li>
<li><a href="http://wiki.eclipse.org/index.php?title=SMILA/Documentation/HowTo/How_to_write_a_Worker&amp;action=history"><span class="tab">History</span></a></li>
<li><a href="http://wiki.eclipse.org/index.php?title=Special:Userlogin&amp;returnto=SMILA/Documentation/HowTo/How%20to%20write%20a%20Worker"><span class="tab">Edit</span></a></li>
</ul>
</div>
<script type="text/javascript"> if (window.isMSIE55) fixalpha(); </script>
<h1 class="firstHeading">SMILA/Documentation/HowTo/How to write a Worker</h1>
<div id="bodyContent">
<h3 id="siteSub">From Eclipsepedia</h3>
<div id="contentSub"><span class="subpages">&lt; <a href="../../../SMILA.html" title="SMILA">SMILA</a> | <a href="../../Documentation.1.html" title="SMILA/Documentation">Documentation</a> | <a href="../HowTo.html" title="SMILA/Documentation/HowTo">HowTo</a></span></div>
<div id="jump-to-nav">Jump to: <a href="How_to_write_a_Worker.html#column-one">navigation</a>, <a href="How_to_write_a_Worker.html#searchInput">search</a></div> <!-- start content -->
<p>
This HowTo describes the necessary steps for writing a worker in SMILA.
</p>
<table id="toc" class="toc" summary="Contents"><tr><td><div id="toctitle"><h2>Contents</h2></div>
<ul>
<li class="toclevel-1"><a href="How_to_write_a_Worker.html#Preconditions"><span class="tocnumber">1</span> <span class="toctext">Preconditions</span></a></li>
<li class="toclevel-1"><a href="How_to_write_a_Worker.html#Project_templates"><span class="tocnumber">2</span> <span class="toctext">Project templates</span></a></li>
<li class="toclevel-1"><a href="How_to_write_a_Worker.html#Adapting_SMILA.application"><span class="tocnumber">3</span> <span class="toctext">Adapting SMILA.application</span></a>
<ul>
<li class="toclevel-2"><a href="How_to_write_a_Worker.html#Adding_the_worker_description"><span class="tocnumber">3.1</span> <span class="toctext">Adding the worker description</span></a></li>
<li class="toclevel-2"><a href="How_to_write_a_Worker.html#Adding_the_bundles_to_the_configuration"><span class="tocnumber">3.2</span> <span class="toctext">Adding the bundles to the configuration</span></a>
<ul>
<li class="toclevel-3"><a href="How_to_write_a_Worker.html#config.ini"><span class="tocnumber">3.2.1</span> <span class="toctext">config.ini</span></a></li>
<li class="toclevel-3"><a href="How_to_write_a_Worker.html#launcher"><span class="tocnumber">3.2.2</span> <span class="toctext">launcher</span></a></li>
</ul>
</li>
<li class="toclevel-2"><a href="How_to_write_a_Worker.html#Scale_up"><span class="tocnumber">3.3</span> <span class="toctext">Scale up</span></a></li>
</ul>
</li>
<li class="toclevel-1"><a href="How_to_write_a_Worker.html#Running"><span class="tocnumber">4</span> <span class="toctext">Running</span></a>
<ul>
<li class="toclevel-2"><a href="How_to_write_a_Worker.html#Run_the_application"><span class="tocnumber">4.1</span> <span class="toctext">Run the application</span></a></li>
<li class="toclevel-2"><a href="How_to_write_a_Worker.html#Run_the_test_case"><span class="tocnumber">4.2</span> <span class="toctext">Run the test case</span></a></li>
</ul>
</li>
<li class="toclevel-1"><a href="How_to_write_a_Worker.html#Create_your_own_worker"><span class="tocnumber">5</span> <span class="toctext">Create your own worker</span></a>
<ul>
<li class="toclevel-2"><a href="How_to_write_a_Worker.html#Use_template"><span class="tocnumber">5.1</span> <span class="toctext">Use template</span></a></li>
<li class="toclevel-2"><a href="How_to_write_a_Worker.html#Bundle_dependencies"><span class="tocnumber">5.2</span> <span class="toctext">Bundle dependencies</span></a></li>
<li class="toclevel-2"><a href="How_to_write_a_Worker.html#Worker_Implementation_Java_Class"><span class="tocnumber">5.3</span> <span class="toctext">Worker Implementation Java Class</span></a></li>
<li class="toclevel-2"><a href="How_to_write_a_Worker.html#OSGI_Declarative_Service"><span class="tocnumber">5.4</span> <span class="toctext">OSGI Declarative Service</span></a></li>
<li class="toclevel-2"><a href="How_to_write_a_Worker.html#Activate_the_Worker:_config.ini_file"><span class="tocnumber">5.5</span> <span class="toctext">Activate the Worker: config.ini file</span></a></li>
<li class="toclevel-2"><a href="How_to_write_a_Worker.html#Activate_the_Worker:_launcher"><span class="tocnumber">5.6</span> <span class="toctext">Activate the Worker: launcher</span></a></li>
<li class="toclevel-2"><a href="How_to_write_a_Worker.html#Register_your_worker_in_jobmanager_configuration"><span class="tocnumber">5.7</span> <span class="toctext">Register your worker in jobmanager configuration</span></a>
<ul>
<li class="toclevel-3"><a href="How_to_write_a_Worker.html#Worker_definition"><span class="tocnumber">5.7.1</span> <span class="toctext">Worker definition</span></a></li>
<li class="toclevel-3"><a href="How_to_write_a_Worker.html#Workflow_definition"><span class="tocnumber">5.7.2</span> <span class="toctext">Workflow definition</span></a></li>
<li class="toclevel-3"><a href="How_to_write_a_Worker.html#Bucket_definition"><span class="tocnumber">5.7.3</span> <span class="toctext">Bucket definition</span></a></li>
</ul>
</li>
</ul>
</li>
<li class="toclevel-1"><a href="How_to_write_a_Worker.html#Testing"><span class="tocnumber">6</span> <span class="toctext">Testing</span></a>
<ul>
<li class="toclevel-2"><a href="How_to_write_a_Worker.html#Use_the_launcher"><span class="tocnumber">6.1</span> <span class="toctext">Use the launcher</span></a></li>
<li class="toclevel-2"><a href="How_to_write_a_Worker.html#Create_worker_unit_test"><span class="tocnumber">6.2</span> <span class="toctext">Create worker unit test</span></a></li>
</ul>
</li>
<li class="toclevel-1"><a href="How_to_write_a_Worker.html#Manually_installing_the_worker_in_SMILA"><span class="tocnumber">7</span> <span class="toctext">Manually installing the worker in SMILA</span></a>
<ul>
<li class="toclevel-2"><a href="How_to_write_a_Worker.html#Create_a_feature_project"><span class="tocnumber">7.1</span> <span class="toctext">Create a feature project</span></a></li>
<li class="toclevel-2"><a href="How_to_write_a_Worker.html#Deploy_your_features"><span class="tocnumber">7.2</span> <span class="toctext">Deploy your features</span></a></li>
<li class="toclevel-2"><a href="How_to_write_a_Worker.html#Install_your_worker_feature_in_a_SMILA_installation"><span class="tocnumber">7.3</span> <span class="toctext">Install your worker feature in a SMILA installation</span></a></li>
</ul>
</li>
<li class="toclevel-1"><a href="How_to_write_a_Worker.html#Advanced_How_To.27s"><span class="tocnumber">8</span> <span class="toctext">Advanced How To's</span></a>
<ul>
<li class="toclevel-2"><a href="How_to_write_a_Worker.html#How_to_access_another_OSGi_Service_inside_your_Worker"><span class="tocnumber">8.1</span> <span class="toctext">How to access another OSGi Service inside your Worker</span></a></li>
<li class="toclevel-2"><a href="How_to_write_a_Worker.html#How_to_add_.2F_access_a_configuration_for_your_Worker"><span class="tocnumber">8.2</span> <span class="toctext">How to add / access a configuration for your Worker</span></a></li>
<li class="toclevel-2"><a href="How_to_write_a_Worker.html#Exception_Handling_and_Logging"><span class="tocnumber">8.3</span> <span class="toctext">Exception Handling and Logging</span></a></li>
<li class="toclevel-2"><a href="How_to_write_a_Worker.html#Create_worker_in_new_bundle_resp._rename_template_bundle"><span class="tocnumber">8.4</span> <span class="toctext">Create worker in new bundle resp. rename template bundle</span></a></li>
</ul>
</li>
</ul>
</td></tr></table><script type="text/javascript"> if (window.showTocToggle) { var tocShowText = "show"; var tocHideText = "hide"; showTocToggle(); } </script>
<a name="Preconditions"></a><h1> <span class="mw-headline"> Preconditions </span></h1>
<ul><li> Set up your development environment, see <a href="../../Development_Guidelines/Howto_set_up_dev_environment.html" class="mw-redirect" title="SMILA/Development Guidelines/Howto set up dev environment">How to set up the development environment</a>.
</li><li> You should have read and understood the documentation about the <a href="../JobManager.html" title="SMILA/Documentation/JobManager">JobManager</a>, especially the configuration of workers and workflows if you want to create new workers.
</li><li> You should have at least an idea about the OSGi framework and OSGi services. For links to introductory articles and tutorials see <a href="http://www.osgi.org/About/HowOSGi" class="external autonumber" title="http://www.osgi.org/About/HowOSGi" rel="nofollow">[1]</a>. For a quite comprehensive overview on OSGi see <a href="http://njbartlett.name/osgibook.html" class="external autonumber" title="http://njbartlett.name/osgibook.html" rel="nofollow">[2]</a>. SMILA makes intensive use of OSGi's Declarative Services facility, so you may want to have at least a quick look at it.
</li></ul>
<a name="Project_templates"></a><h1> <span class="mw-headline"> Project templates </span></h1>
<p>You can either start with a new bundle by following the two HowTos:
</p>
<ul><li> <a href="../../Development_Guidelines/Create_a_bundle_(plug-in).html" class="mw-redirect" title="SMILA/Development Guidelines/Create a bundle (plug-in)">How to create a bundle (plug-in)</a>
</li><li> <a href="../../Development_Guidelines/Create_a_test_bundle_(plug-in).html" class="mw-redirect" title="SMILA/Development Guidelines/Create a test bundle (plug-in)">How to create a test bundle (plug-in)</a>
</li></ul>
<p>Now you have two (completely empty) bundles, one to develop your worker(s), and one to test it/them.
</p><p>If you do not want to use the example bundes as templates, go on with <a href="How_to_write_a_Worker.html#Create_your_own_worker" title="">Create your own worker</a>.
</p><p>Or, you can export the <a href="http://dev.eclipse.org/svnroot/rt/org.eclipse.smila/trunk/examples" class="external text" title="http://dev.eclipse.org/svnroot/rt/org.eclipse.smila/trunk/examples" rel="nofollow">example bundles</a> from SMILA's repository and import it into your SMILA workspace and use them as templates:
</p>
<ul><li> <a href="http://dev.eclipse.org/svnroot/rt/org.eclipse.smila/trunk/examples/org.eclipse.smila.integration.worker" class="external text" title="http://dev.eclipse.org/svnroot/rt/org.eclipse.smila/trunk/examples/org.eclipse.smila.integration.worker" rel="nofollow">org.eclipse.smila.integration.worker</a>: template bundle for worker development, containing an example worker class
</li><li> <a href="http://dev.eclipse.org/svnroot/rt/org.eclipse.smila/trunk/examples/org.eclipse.smila.integration.worker.test" class="external text" title="http://dev.eclipse.org/svnroot/rt/org.eclipse.smila/trunk/examples/org.eclipse.smila.integration.worker.test" rel="nofollow">org.eclipse.smila.integration.worker.test</a>: template bundle to test a developed worker, containg an example test class
</li></ul>
<p>You can also download these examples from the <a href="http://www.eclipse.org/smila/downloads.php" class="external text" title="http://www.eclipse.org/smila/downloads.php" rel="nofollow">release downloads</a> or the <a href="http://build.eclipse.org/rt/smila/nightly/" class="external text" title="http://build.eclipse.org/rt/smila/nightly/" rel="nofollow">nightly build downloads</a>.
</p>
<a name="Adapting_SMILA.application"></a><h1> <span class="mw-headline"> Adapting SMILA.application </span></h1>
<p>(This applies only when you've checked out the example bundles and imported them into your workspace, not if you start with fresh bundles.)
We now need to enable our worker and start the bundle during SMILA's startup.
Do the following steps to enable this:
</p>
<a name="Adding_the_worker_description"></a><h2> <span class="mw-headline"> Adding the worker description </span></h2>
<p>The workers' descriptions are read by the jobmanager on startup, if a worker does not provide a description it won't get any tasks, so you have to provide one.
</p>
<ul><li> Edit the <tt>workers.json</tt> file in <tt>SMILA.application/configuration/org.eclipse.smila.jobmanager</tt> and add the following worker description to the json array (don't forget the comma):
</li></ul>
<div dir="ltr" style="text-align: left;"><pre class="source-javascript"><span class="br0">&#123;</span>
<span class="st0">&quot;name&quot;</span>: <span class="st0">&quot;HelloWorldWorker&quot;</span>,
<span class="st0">&quot;input&quot;</span>: <span class="br0">&#91;</span>
<span class="br0">&#123;</span> <span class="st0">&quot;name&quot;</span>: <span class="st0">&quot;inputRecords&quot;</span>,
<span class="st0">&quot;type&quot;</span>: <span class="st0">&quot;recordBulks&quot;</span>
<span class="br0">&#125;</span> <span class="br0">&#93;</span>,
<span class="st0">&quot;output&quot;</span>: <span class="br0">&#91;</span>
<span class="br0">&#123;</span> <span class="st0">&quot;name&quot;</span>: <span class="st0">&quot;outputRecords&quot;</span>,
<span class="st0">&quot;type&quot;</span>: <span class="st0">&quot;recordBulks&quot;</span>
<span class="br0">&#125;</span> <span class="br0">&#93;</span>
<span class="br0">&#125;</span></pre></div>
<a name="Adding_the_bundles_to_the_configuration"></a><h2> <span class="mw-headline"> Adding the bundles to the configuration </span></h2>
<p>Next we need to make sure the bundle is started.
</p>
<a name="config.ini"></a><h3> <span class="mw-headline"> config.ini </span></h3>
<p>To start the bundle in the built application, add the following line to <tt>SMILA.application/configuration/config.ini</tt> as the second last line:
</p>
<ul><li> org.eclipse.smila.integration.worker@4:start, \
</li></ul>
<p>(To be honest, it does not matter at all, where exaclty you add your bundle in the file, as long as the syntax (end of lines must be escaped for all lines except the last one, of course) is correct.)
</p>
<a name="launcher"></a><h3> <span class="mw-headline"> launcher </span></h3>
<p>You also have to adapt your launcher:
</p>
<ul><li> Click on <i>Run configurations...</i>
</li><li> Select the <i>OSGi Framework</i>--&gt;<i>SMILA</i> configuration
</li><li> In the <i>Bundles</i> page, check the box before <tt>org.eclipse.smila.integration.worker</tt>, leave Start Level on <tt>default</tt>, set Auto-Start to <tt>true</tt>.
</li><li> Click <i>Apply</i>
</li></ul>
<a name="Scale_up"></a><h2> <span class="mw-headline"> Scale up </span></h2>
<p>Finally you should add the scale up limits (see <a href="../WorkerManager.html#ScaleUp" title="SMILA/Documentation/WorkerManager"> ScaleUp</a>) to the cluster configuration file (if you use the standard simple clusterconfig service, you will find the configuration file as <tt>org.eclipse.smila.clusterconfig.simple/clusterconfig.json</tt>).
</p><p>E.g. add the following snippet to the existing ones in the <span style="font-family:monospace;">workers</span> map to limit scale up of the worker to a maximum of concurrent tasks (be sure, your worker label is the same as in the <tt>workers.json</tt>). If you do not add your worker's scale up here, the worker is limited to one concurrent task.
</p><p>Example to limit the worker <tt>HelloWorldWorker</tt> to a maximum of 4 concurrent tasks:
</p>
<div dir="ltr" style="text-align: left;"><pre class="source-javascript"><span class="st0">&quot;HelloWorldWorker&quot;</span>:<span class="br0">&#123;</span>
<span class="st0">&quot;maxScaleUp&quot;</span>:<span class="nu0">4</span>
<span class="br0">&#125;</span>,</pre></div>
<a name="Running"></a><h1> <span class="mw-headline"> Running </span></h1>
<p>You should now test your workspace setup to make sure that everything works with the prepared stuff.
</p>
<a name="Run_the_application"></a><h2> <span class="mw-headline"> Run the application </span></h2>
<ul><li> Select "Run" -&gt; "Run Configurations" or "Debug Configurations"
</li><li> Select "OSGi Frameworks" -&gt; "SMILA".
</li><li> Click "Run" or "Debug" and SMILA should start just like when started from the command line.
</li></ul>
<p>Find the configuration of this SMILA instance in your workspace in "SMILA.application/configuration".
</p><p>When starting the <tt>SMILA.launch</tt> in eclipse, you should see something like the following output in the console window:
</p>
<pre>
...
Added worker HelloWorldWorker to WorkerManager.
...
</pre>
<p>You should also be able to read the worker definition using the jobmanager HTTP API now: Go to <tt><a href="http://localhost:8080/smila/jobmanager/workers/" class="external free" title="http://localhost:8080/smila/jobmanager/workers/" rel="nofollow">http://localhost:8080/smila/jobmanager/workers/</a></tt> to see something like this:
</p>
<pre>
{
&quot;workers&quot;&nbsp;: [ ...,
{
&quot;name&quot;&nbsp;: &quot;HelloWorldWorker&quot;,
&quot;url&quot;&nbsp;: &quot;http://localhost:8080/smila/jobmanager/workers/HelloWorldWorker/&quot;
}, ... ]
}
</pre>
<p>You can now click on the link to the worker description and you should see the description of the HelloWorldWorker:
</p>
<pre>
{
&quot;name&quot;&nbsp;: &quot;HelloWorldWorker&quot;,
&quot;input&quot;&nbsp;: [ {
&quot;name&quot;&nbsp;: &quot;inputRecords&quot;,
&quot;type&quot;&nbsp;: &quot;recordBulks&quot;
} ],
&quot;output&quot;&nbsp;: [ {
&quot;name&quot;&nbsp;: &quot;outputRecords&quot;,
&quot;type&quot;&nbsp;: &quot;recordBulks&quot;
} ]
}
</pre>
<a name="Run_the_test_case"></a><h2> <span class="mw-headline"> Run the test case </span></h2>
<p><b>To run the JUnit test case for the HelloWorldWorker</b>
</p>
<ul><li> Stop the SMILA.launch if it is running.
</li><li> Select "Run" -&gt; "Run Configurations".
</li><li> Select "JUnit Plugin Test" -&gt; "TestHelloWorldWorker".
</li><li> Click "Run".
</li><li> You should find the following message in the "Console" view:
</li></ul>
<pre>
TestHelloWorldWorker: Value of attribute 'greeting' = 'HelloWorldWorker was here&nbsp;:-)'
</pre>
<p>This shows that the HelloWorldWorker has done something. Of course, the test also contains an assertion so that it will fail when the attribute has not the expceted value.
</p>
<a name="Create_your_own_worker"></a><h1> <span class="mw-headline"> Create your own worker </span></h1>
<a name="Use_template"></a><h2> <span class="mw-headline"> Use template </span></h2>
<p>The easiest way to create a new worker is by implementing it in the bundle <tt>org.eclipse.smila.integration.worker</tt> (see <a href="How_to_write_a_Worker.html#Project_templates" title="">Project Templates</a>). There you can just place your new worker beside the <tt>HelloWorldWorker</tt> example worker, or replace it. Things you have to do when renaming the bundle/package or creating your own worker bundle are described later on.
</p>
<a name="Bundle_dependencies"></a><h2> <span class="mw-headline"> Bundle dependencies </span></h2>
<p>The dependencies of the bundle are managed by the OSGi framework and have to be configured explicitly in the <tt>MANIFEST.MF</tt> file so that the OSGi framework can resolve them (in the correct versions) when the services are started.
</p><p>To create a worker that reads and writes <tt>Records</tt>, we need at least the following bundles imported as packages (see <tt>META-INF</tt> -&gt; "Dependencies" -&gt; "Imported Packages"):
</p>
<ul><li><tt>org.eclipse.smila.datamodel</tt>: For the <tt>Record</tt> class.
</li><li><tt>org.eclipse.smila.objectstore</tt>: Possible exceptions when accessing input/output streams.
</li><li><tt>org.eclipse.smila.taskworker</tt>: The <tt>TaskWorker</tt> bundle containing the <tt>Worker</tt> and <tt>TaskContext</tt> interfaces.
</li><li><tt>org.eclipse.smila.taskworker.input</tt>: Input streams of the <tt>TaskWorker</tt> bundle.
</li><li><tt>org.eclipse.smila.taskworker.output</tt>: Output streams of the <tt>TaskWorker</tt> bundle.
</li></ul>
<p>This is already configured. If access to other packages is needed, just extend the <tt>MANIFEST.MF</tt> file in section "Imported Packages" accordingly.
</p>
<a name="Worker_Implementation_Java_Class"></a><h2> <span class="mw-headline"> Worker Implementation Java Class </span></h2>
<p>Create a worker class which implements <tt>org.eclipse.smila.taskworker.Worker</tt>. Have a look at the example worker <tt>org.eclipse.smila.integration.worker.HelloWorldWorker</tt> that comes with the SDK in the <tt>org.eclipse.smila.integration.worker</tt> bundle. You must implement two methods:
</p>
<ul><li> <tt>getName()</tt> must return a unique name for your worker. Exactly the same name (case sensitive) must be used later in the worker descriptions and workflow definitions.
</li><li> <tt>perform()</tt> does the actual work. It is called with a <tt>TaskContext</tt> object that provides access to the task properties, input and output objects, and counters.
</li></ul>
<a name="OSGI_Declarative_Service"></a><h2> <span class="mw-headline"> OSGI Declarative Service </span></h2>
<p>Every worker must be declared as an OSGi Declarative Service (DS) in order to be registered properly to the worker framework. To configure your worker as DS, you have to add an appropriate XML file to the folder <tt>&lt;WORKSPACE&gt;/bundles/org.eclipse.smila.integration.worker/OSGI-INF</tt>.
</p><p>The file can be created either manually or using the <i>Component Definition</i> wizard.
</p><p>Have a look at <tt>helloworldworker.xml</tt> as an example:
</p>
<pre>
&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;scr:component xmlns:scr=&quot;http://www.osgi.org/xmlns/scr/v1.1.0&quot;
name=&quot;HelloWorldWorker&quot; immediate=&quot;true&quot;&gt;
&lt;implementation class=&quot;org.eclipse.smila.integration.worker.HelloWorldWorker&quot;/&gt;
&lt;service&gt;
&lt;provide interface=&quot;org.eclipse.smila.taskworker.Worker&quot;/&gt;
&lt;/service&gt;
&lt;/scr:component&gt;
</pre>
<p>The file describes (1) the interface that the worker has to implement (and through which it will be accessed in the OSGi application by means of dependency injection), (2) the class being the concrete implementor of that interface, (3) the services that it references (our simple worker does not reference any, you can find a description later on), (4) and the name of the service.
</p><p>To describe your own worker, just create a copy of the <tt>OSGI-INF/helloworldworker.xml</tt> file in the same directory. Then change at least the "name" attribute in the root element and the "class" element in the "implementation" element.
</p><p>When you don't need the <tt>HelloWorldWorker</tt> anymore you may want to remove at least its component definition file from the bundle. Otherwise, it will always be running and asking for tasks in the final deployment. While it should not really be a problem, it causes some unnecessary overhead that can easily be avoided.
</p><p>You should check in your MANIFEST.MF that your component definition is included in the build and it is listed as <i>Service-Component</i> (e.g. as a line in your MANIFEST.MF <span style="font-family:monospace;">Service-Component: OSGI-INF/*.xml</span> and the <span style="font-family:monospace;">bin.includes</span> of the build.properties file should contain <span style="font-family:monospace;">OSGI-INF/</span>).
</p>
<a name="Activate_the_Worker:_config.ini_file"></a><h2> <span class="mw-headline"> Activate the Worker: config.ini file </span></h2>
<p>This file describes which OSGi services are automatically started and defines the start order.
You can find this file in: <tt>&lt;WORKSPACE&gt;/SMILA.application/configuration</tt>
</p><p>Check that the custom bundle is added with an appropriate start level (level 4 is usually fine). One of the latest lines should look like this:
</p>
<pre>
org.eclipse.smila.integration.worker@4:start, \
</pre>
<a name="Activate_the_Worker:_launcher"></a><h2> <span class="mw-headline"> Activate the Worker: launcher </span></h2>
<p>Open the SMILA launcher and activate the worker's bundle (check the box beside it, and set Auto-Start to <span style="font-family:monospace;">true</span>).
</p>
<a name="Register_your_worker_in_jobmanager_configuration"></a><h2> <span class="mw-headline"> Register your worker in jobmanager configuration </span></h2>
<p>These are the steps to use your new worker with the jobmanager framework.
</p>
<a name="Worker_definition"></a><h3> <span class="mw-headline"> Worker definition </span></h3>
<p>Edit <tt>workers.json</tt> from <tt>&lt;WORKSPACE&gt;/SMILA.application/configuration/org.eclipse.smila.jobmanager</tt> folder and add the definition for the new worker.
</p><p><b>Important:</b> The <tt>name</tt> in the worker definition has to be the same that is returned by the <tt>getName()</tt> method in the worker implementation!
</p><p>For the example worker <tt>HelloWorldWorker</tt> we want to use one input and output slot. And we use <tt>recordBulks</tt> as data object type cause we want to modify (bulks of) records with this worker:
</p>
<pre>
{ &quot;name&quot;: &quot;HelloWorldWorker&quot;,
&quot;input&quot;: [
{ &quot;name&quot;: &quot;inputRecords&quot;,
&quot;type&quot;: &quot;recordBulks&quot;
} ],
&quot;output&quot;: [
{ &quot;name&quot;: &quot;outputRecords&quot;,
&quot;type&quot;: &quot;recordBulks&quot;
} ]
}
</pre>
<a name="Workflow_definition"></a><h3> <span class="mw-headline"> Workflow definition </span></h3>
<p>To use your worker in a workflow you have to add a new workflow or change an existing one. You can either use the jobmanager API to add a workflow definition to the running system, or you can edit <tt>workflows.json</tt> from <tt>&lt;WORKSPACE&gt;/SMILA.application/configuration/org.eclipse.smila.jobmanager</tt> folder and add/change a workflow.
</p><p>This example is a test workflow that uses the <tt>HelloWorldWorker</tt> to manipulate all records which where pushed into the system using the bulkbuilder. Because it's pretty useless as such, we did not add it to <tt>SMILA.application/configuration/org.eclipse.smila.jobmanager/workflows.json</tt>, but it's used in the unit test bundle <tt>org.eclipse.smila.integration.worker.test</tt>: The test case reads the output bulk created by the <tt>HelloWorldWorker</tt> to check if it been running.
</p>
<pre>
{
&quot;name&quot;:&quot;HelloWorldWorkflow&quot;,
&quot;startAction&quot;:{
&quot;worker&quot;:&quot;bulkbuilder&quot;,
&quot;output&quot;:{
&quot;insertedRecords&quot;:&quot;importBucket&quot;
}
},
&quot;actions&quot;:[
{
&quot;worker&quot;:&quot;HelloWorldWorker&quot;,
&quot;input&quot;:{
&quot;inputRecords&quot;:&quot;importBucket&quot;
},
&quot;output&quot;:{
&quot;outputRecords&quot;:&quot;helloWorldExportBucket&quot;
}
}
]
}
</pre>
<a name="Bucket_definition"></a><h3> <span class="mw-headline"> Bucket definition </span></h3>
<p>If you want to use a new <i>persistent</i> bucket for your workflow (see jobmanager documentation) you have to add it via the jobmanager API or add it to the configuration: Edit <tt>buckets.json</tt> from <tt>&lt;WORKSPACE&gt;/SMILA.application/configuration/org.eclipse.smila.jobmanager</tt> folder and create desired bucket.
</p><p>Here's an example from the test bundle <tt>org.eclipse.smila.integration.worker.test</tt> for the workflow above that makes the final bucket <tt>helloWorldExportBucket</tt> persistent. For the unit test, the output bucket of the worker must be persistent so that the test case can still read the result records when the workflow has ended. Otherwise the jobmanager would remove the transient object immediately after the <tt>HelloWorldWorker</tt> has finished.
</p>
<pre>
{
&quot;name&quot;:&quot;helloWorldExportBucket&quot;,
&quot;type&quot;:&quot;recordBulks&quot;
}
</pre>
<a name="Testing"></a><h1> <span class="mw-headline"> Testing </span></h1>
<a name="Use_the_launcher"></a><h2> <span class="mw-headline"> Use the launcher </span></h2>
<p>If everything was done correctly and you start the <tt>SMILA.launch</tt> in Eclipse, you should see something like the following output in the console window, but with the name of your own worker:
</p>
<pre>
...
Added worker HelloWorldWorker to WorkerManager.
...
</pre>
<p>You should also be able to read your worker definition using the jobmanager HTTP API now: Go to <tt><a href="http://localhost:8080/smila/jobmanager/workers/" class="external free" title="http://localhost:8080/smila/jobmanager/workers/" rel="nofollow">http://localhost:8080/smila/jobmanager/workers/</a></tt> to see something like this:
</p>
<pre>
{
&quot;workers&quot;&nbsp;: [ ...,
{
&quot;name&quot;&nbsp;: &quot;HelloWorldWorker&quot;,
&quot;url&quot;&nbsp;: &quot;http://localhost:8080/smila/jobmanager/workers/HelloWorldWorker/&quot;
}, ... ]
}
</pre>
<p>and click on the link to the worker description and you should see the description you added to <tt>workers.json</tt> earlier.
</p><p>You should also check whether your new workflow definition is visible in <a href="http://localhost:8080/smila/jobmanager/workflows/" class="external autonumber" title="http://localhost:8080/smila/jobmanager/workflows/" rel="nofollow">[3]</a>.
If not, you maybe misstyped a worker name or something. If there is no workflow at all, the <tt>workflows.json</tt> file has invalid syntax.
</p>
<a name="Create_worker_unit_test"></a><h2> <span class="mw-headline"> Create worker unit test </span></h2>
<p>You can use the test bundle template <tt>org.eclipse.smila.integration.worker.test</tt> to add a test for your worker. Have a look at the example test class <tt>org.eclipse.smila.integration.worker.test.TestHelloWorldWorker</tt> that comes with the SDK.
</p><p>All configuration files for the test are in <tt>org.eclipse.smila.integration.worker.test/configuration</tt>. This is similar to <tt>SMILA.application/configuration</tt>, but contains only the configuration files necessary to run the tests, not all files needed by a complete system. Also, some configuration files may differ from those in <tt>SMILA.application</tt>, e.g. some components may be configured with smaller limits to make tests run quicker. However, if you create a new worker, you must add its description to the <tt>workers.json</tt> in the test bundles and define persistent buckets and workflows required to run the test. Additionally make sure that the <tt>config.ini</tt> contains the names of your worker bundles and those of services your worker needs to access.
</p><p>To start the test in eclipse you have to copy the launch for TestHelloWorldWorker and adapt it to your new test class.
</p>
<a name="Manually_installing_the_worker_in_SMILA"></a><h1> <span class="mw-headline"> Manually installing the worker in SMILA </span></h1>
<p>In the following we describe the steps to deploy your worker to an existing SMILA installation.
</p>
<a name="Create_a_feature_project"></a><h2> <span class="mw-headline"> Create a feature project </span></h2>
<p>A feature project is a container project that defines the Plug-ins needed for a specific feature. In our case our feature is to provide a worker, so we'll only have one Plug-in included in that feature, but it can also be reasonable to include all worker Plug-ins that are necessary to extend the SMILA to be able to handle a specific scenario in one feature that can be deployed and so includes all plugins necessary. The SDK contains already a prepared project <b>org.eclipse.smila.integration.feature</b> that includes the custom worker bundle. If you create further worker bundles (or other SMILA extensions) you can just add them to this feature (see below).
</p><p>If you ever need to create an own feature project you can use Eclipse's <i>New...</i> wizard:
</p>
<ul><li> New --&gt; Plug-in Development --&gt; Feature Project
<ul><li> Enter a Project name
</li><li> Version e.g. 1.0.0 (should match the version of your plug-in)
</li><li> Fill in other feature properties to describe the new feature
</li></ul>
</li><li> Next
<ul><li> select your worker plugin
</li></ul>
</li><li> Finish
</li></ul>
<a name="Deploy_your_features"></a><h2> <span class="mw-headline"> Deploy your features </span></h2>
<p>Now it's easy to export your custom bundles to files that can be easily deployed into SMILA:
</p>
<ul><li>Select your feature project
</li><li>Right-click on it
</li><li>Click on <i>Export...</i>
</li><li>Select <i>Plug-in Development</i> --&gt; <i>Deployable features</i>
</li><li>Next
</li><li>Select your new worker feature(s)
</li><li>Select a destination folder. If you are re-exporting after changes (especially after renames), you should first delete the destination folder.
</li><li>Click <i>Finish</i>
</li></ul>
<p>After that you will find <tt>plugins</tt> and <tt>features</tt> directories in your destination directory that contain the deployable software. The export process produces two additional files <tt>artifacts.jar</tt> and <tt>contents.jar</tt> which are not for our purposes.
</p>
<a name="Install_your_worker_feature_in_a_SMILA_installation"></a><h2> <span class="mw-headline"> Install your worker feature in a SMILA installation </span></h2>
<ul><li> Copy the <tt>features</tt> and <tt>plugins</tt> folder to your SMILA installation.
</li><li> merge your configuration changes (e.g. <tt>configuration/org.eclipse.smila.jobmanager</tt>) into the SMILA configuration
<ul><li> copy your <tt>configuration/config.ini</tt> file (see above) or edit the installed <tt>config.ini</tt> directly to start up your bundle
<ul><li> e.g. for the above bundle and version this would be (in the second last line): <tt>org.eclipse.smila.integration.worker@4:start, \</tt>
</li></ul>
</li></ul>
</li><li> start your system
</li><li> In <tt>data/log/smila.log</tt> you should now find such a line:
</li></ul>
<pre>
...
2011-06-06 15:17:15,035 INFO [Component Resolve Thread (Bundle 5) ] internal.WorkerManagerImpl - Added worker HelloWorldWorker to WorkerManager.
...
</pre>
<p>Of course, additionally you should be able to retrieve the worker description you added to <tt>configuration/org.eclipse.smila.jobmanager/workers.json</tt> via the JobManager REST API.
</p>
<a name="Advanced_How_To.27s"></a><h1> <span class="mw-headline"> Advanced How To's </span></h1>
<a name="How_to_access_another_OSGi_Service_inside_your_Worker"></a><h2> <span class="mw-headline"> How to access another OSGi Service inside your Worker </span></h2>
<p>With SMILA there come a lot of components with APIs for different purposes. Sometimes you may want to access such an API inside your worker. With the concept of OSGi Declarative Services (DS) this is just a matter of configuration.
</p><p><b>Example: Reading all cluster nodes</b>
</p><p>Assumed, we want to know the names of all cluster nodes in our worker. This is possible via ClusterConfigService API. Here are the steps to access this API in your worker:
</p>
<ul><li> Precondition: We assume you already configured your worker as OSGi Declarative Service as described before.
</li></ul>
<ul><li> To use the ClusterConfigService you have to import the appropriate package <tt>org.eclipse.smila.clusterconfig</tt> in the MANIFEST.MF/Dependencies (see "Bundle Dependencies")
</li></ul>
<ul><li> Configure ClusterConfigService as referenced service in the service description xml (OSGI-INF/...):
</li></ul>
<pre>
&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;scr:component org.eclipse.smila.jobmanager name=&quot;MyWorker&quot; immediate=&quot;true&quot;&gt;
&lt;implementation class=&quot;mypackage.MyWorkerImpl&quot; /&gt;
&lt;service&gt;
&lt;provide interface=&quot;org.eclipse.smila.taskworker.Worker&quot;/&gt;
&lt;/service&gt;
&lt;reference bind=&quot;setClusterConfigService&quot;
cardinality=&quot;1..1&quot;
interface=&quot;org.eclipse.smila.clusterconfig.ClusterConfigService&quot;
name=&quot;ClusterConfigService&quot;
policy=&quot;static&quot;
unbind=&quot;unsetClusterConfigService&quot;/&gt;
&lt;/scr:component&gt;
</pre>
<ul><li> Implement the specifed methods <tt>setClusterConfigService</tt> and <tt>unsetClusterConfigService</tt> in your worker implementation. This may look like this:
</li></ul>
<pre>
private ClusterConfigService _ccs;
public void setClusterConfigService(final ClusterConfigService ccs) {
_ccs = ccs;
}
public void unsetClusterConfigService(final ClusterConfigService ccs) {
if (_ccs == ccs) {
_ccs = null;
}
}
</pre>
<ul><li> Now, the OSGi framework will automatically set the SimpleClusterConfigService (which implements the interface ClusterConfigService) in your worker at startup via the specified method. So the ClusterConfigService API will be accessible at runtime:
</li></ul>
<pre>
...
List&lt;String&gt; clusterNodes = _ccs.getClusterNodes();
...
</pre>
<a name="How_to_add_.2F_access_a_configuration_for_your_Worker"></a><h2> <span class="mw-headline"> How to add / access a configuration for your Worker </span></h2>
<p>You can add a worker configuration, e.g. a property file, by adding it to the application configuration.
</p><p><b>Example: Adding a property file "myWorker.properties" and access it in the worker</b>
</p>
<ul><li> To add a worker configuration create an appropriate folder in the application configuration and place the property file there:
</li></ul>
<pre>
SMILA.application/configuration/MY_BUNDLE_NAME/myWorker.properties
</pre>
<ul><li> To easiest way to access the configuration in your worker is via <tt>org.eclipse.smila.utils.config.ConfigUtils</tt> class
</li><li> To use this class you have to import the appropriate package <tt>org.eclipse.smila.utils.config</tt> in the MANIFEST.MF/Dependencies (see "Bundle Dependencies")
<ul><li> For the following example code you should also import <tt>org.apache.commons.io</tt>
</li></ul>
</li><li> Your code could look somehow like that:
</li></ul>
<pre>
InputStream configFileStream = null;
try {
configFileStream = ConfigUtils.getConfigStream(MY_BUNDLE_NAME, myWorker.properties);
Properties props = new Properties();
props.load(configFileStream);
...
} finally {
if (configFileStream&nbsp;!= null) {
IOUtils.closeQuietly(configFileStream);
}
}
</pre>
<p><b>Add on: Read configuration at startup</b>
</p>
<ul><li> If you want to initialize your worker by configuration at startup, you can use the <tt>activate()</tt> method automatically called by the OSGi framework at bundle startup.
</li><li> To use an activate method you have to import the package <tt>org.osgi.service.component</tt> in the MANIFEST.MF.
</li><li> Then your code could look like that
</li></ul>
<pre>
protected void activate(final ComponentContext context) {
try {
readConfiguration();
...
</pre>
<p><br />
</p>
<a name="Exception_Handling_and_Logging"></a><h2> <span class="mw-headline"> Exception Handling and Logging </span></h2>
<p><b>Exception Handling:</b>
</p><p>There are three possible ways your worker's <tt>perform()</tt> method can finish when processing its current task:
</p>
<ul><li> return (without exception): The normal case where you just processed the task without errors. The task will be finished and marked as successful.
</li><li> throw a <tt>RecoverableTaskException</tt>: If you get an error, but you see a chance that the same task could be successful when being processed next time, you can throw a <tt>RecoverableTaskException</tt>. This will cause the current task to be finished but retried later on. (Hint: For internal reasons, UnavailableException and IOException will also cause a retry.)
</li><li> throw a "non-retry" Exception: These are all exceptions not mentioned before. The current task will be marked as failed and not be retried.
</li></ul>
<p><b>Logging:</b>
</p><p>You can use the log4j logging that comes with SMILA in your worker too. Your logging output will be logged in the standard <tt>smila.log</tt>.
</p>
<ul><li> import the package <tt>org.apache.commons.logging</tt> in the MANIFEST.MF.
</li></ul>
<p>Then your code could look somehow like that:
</p>
<pre>
private final Log _log = LogFactory.getLog(getClass());
...
_log.debug(&quot;My worker was successful&quot;);
...
</pre>
<p><br />
</p>
<a name="Create_worker_in_new_bundle_resp._rename_template_bundle"></a><h2> <span class="mw-headline"> Create worker in new bundle resp. rename template bundle </span></h2>
<p><b>For creating a new bundle:</b>
</p>
<ul><li> Follow the description <a href="../../Development_Guidelines/Create_a_bundle_(28plug-in).html" class="external text" title="http://wiki.eclipse.org/SMILA/Development_Guidelines/Create_a_bundle_(28plug-in)" rel="nofollow">here</a> to create a new bundle.
</li></ul>
<p><b>For renaming a bundle:</b>
</p>
<ul><li> Right-click the bundle to rename in eclipse and select (<tt>Refactor/Rename</tt>).
</li><li> Right-click java package and select (<tt>Refactor/Rename</tt>).
</li><li> Open MANIFEST.MF and set a version property to the (renamed) exported package. <tt>Runtime/Exported Packages</tt>
</li></ul>
<p><i>Hint: if there are strange compile problems afterwards, and refresh resp. clean projects doesn't help, try restarting your eclipse IDE.</i>
</p><p><b>MANIFEST.MF / OSGI-INF / build.properties:</b>
</p>
<ul><li> Apapt the changes in your OSGI-INF component description xml file
</li><li> Please be sure that your OSGi component definition file is included in the <tt>MANIFEST.MF</tt> file in the <i>Service-Component</i> section! Otherwise the service component will not be recognized and thus not be started.
</li><li> Please be sure that the <tt>OSGI-INF/</tt> folder is included in your <tt>build.properties</tt>
</li></ul>
<p><b>test bundle:</b>
</p>
<ul><li> Adapt the test bundle to the changes:
<ul><li> change name of test bundle and java package (<tt>Refactor/Rename</tt>, like described above for the worker bundle itself).
</li><li> correct the imported packages in the code and the MANIFEST.MF (if not done correctly by refactoring)
</li><li> adapt the test's run configuration, e.g. name, test bundle's java package, configuration file location (on tab "configuration")
</li><li> adapt the config.ini file
</li></ul>
</li></ul>
<p><b>Application launch:</b>
</p>
<ul><li> Add the new/renamed bundle to the eclipse launcher and also to your application <tt>configuration/config.ini</tt> file with an appropriate start level.
</li></ul>
<p><b>feature project:</b>
</p>
<ul><li> You have to add your new/renamed bundle to the feature project.
</li><li> clear the destination folder for feature exports.
</li></ul>
<!--
NewPP limit report
Preprocessor node count: 223/1000000
Post-expand include size: 285/2097152 bytes
Template argument size: 65/2097152 bytes
#ifexist count: 0/100
-->
<!-- Saved in parser cache with key wikidb:pcache:idhash:33513-0!1!0!!en!2!edit=0 and timestamp 20120203101212 -->
<div class="printfooter">
Retrieved from "<a href="How_to_write_a_Worker.html">http://wiki.eclipse.org/SMILA/Documentation/HowTo/How_to_write_a_Worker</a>"</div>
<div id="catlinks"><p class='catlinks'><a href="http://wiki.eclipse.org/Special:Categories" title="Special:Categories">Category</a>: <span dir='ltr'><a href="http://wiki.eclipse.org/Category:SMILA" title="Category:SMILA">SMILA</a></span></p></div> <!-- end content -->
<div class="visualClear"></div>
</div>
</div>
</div>
<!-- Yoink of toolbox for phoenix moved up -->
</div>
</div>
<div id="clearFooter"/>
<div id="footer" >
<ul id="footernav">
<li class="first"><a href="http://www.eclipse.org/">Home</a></li>
<li><a href="http://www.eclipse.org/legal/privacy.php">Privacy Policy</a></li>
<li><a href="http://www.eclipse.org/legal/termsofuse.php">Terms of Use</a></li>
<li><a href="http://www.eclipse.org/legal/copyright.php">Copyright Agent</a></li>
<li><a href="http://www.eclipse.org/org/foundation/contact.php">Contact</a></li>
<li><a href="http://wiki.eclipse.org/Eclipsepedia:About" title="Eclipsepedia:About">About Eclipsepedia</a></li>
</ul>
<span id="copyright">Copyright &copy; 2012 The Eclipse Foundation. All Rights Reserved</span>
<p id="footercredit">This page was last modified 09:36, 3 February 2012 by <a href="http://wiki.eclipse.org/index.php?title=User:Juergen.schumacher.attensity.com&amp;action=edit" class="new" title="User:Juergen.schumacher.attensity.com">Juergen Schumacher</a>. Based on work by <a href="http://wiki.eclipse.org/index.php?title=User:Nadine.auslaender.attensity.com&amp;action=edit" class="new" title="User:Nadine.auslaender.attensity.com"> </a>, <a href="http://wiki.eclipse.org/User:Andreas.schank.attensity.com" title="User:Andreas.schank.attensity.com">A. Schank</a> and <a href="http://wiki.eclipse.org/User:Drazen.cindric.attensity.com" title="User:Drazen.cindric.attensity.com">Drazen Cindric</a>.</p>
<p id="footerviews">This page has been accessed 622 times.</p>
</div>
<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
var pageTracker = _gat._getTracker("UA-910670-4");
pageTracker._trackPageview();
</script>
<!-- <div class="visualClear"></div> -->
<script type="text/javascript">if (window.runOnloadHook) runOnloadHook();</script>
</div>
<!-- Served in 0.264 secs. --></body></html>