<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss xmlns:atom="http://www.w3.org/2005/Atom" xmlns:openSearch="http://a9.com/-/spec/opensearch/1.1/" xmlns:georss="http://www.georss.org/georss" xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr="http://purl.org/syndication/thread/1.0" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0"><channel><atom:id>tag:blogger.com,1999:blog-1859167416855250911</atom:id><lastBuildDate>Mon, 20 Feb 2012 14:01:18 +0000</lastBuildDate><category>Pictures</category><category>Source code</category><category>Publications</category><category>Games</category><category>Windows</category><category>Apple</category><category>Linux</category><category>HowTo</category><category>Web</category><category>Music</category><title>Scumm Bar</title><description>Spreading happiness since 1987</description><link>http://groglogs.blogspot.com/</link><managingEditor>noreply@blogger.com (Stefano Ghio)</managingEditor><generator>Blogger</generator><openSearch:totalResults>98</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/groglogs" /><feedburner:info uri="groglogs" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1859167416855250911.post-8020890941984335951</guid><pubDate>Fri, 10 Feb 2012 14:18:00 +0000</pubDate><atom:updated>2012-02-10T15:34:34.805+01:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">HowTo</category><category domain="http://www.blogger.com/atom/ns#">Source code</category><title>[Java] Find free port</title><description>Getting the number of an unused port on the system via Java 7 is as easy as:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;&lt;span style="white-space: pre;"&gt;import java.net.ServerSocket;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;&lt;span style="white-space: pre;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;public static int findFreePort(){&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;  &lt;/span&gt;int port = 0;&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;  &lt;/span&gt;try(ServerSocket server = new ServerSocket(0);){&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;   &lt;/span&gt;port = server.getLocalPort();&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;  &lt;/span&gt;}catch(Exception e){&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;   &lt;/span&gt;System.err.println("unable to find a free port");&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;   &lt;/span&gt;return null;&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;  &lt;/span&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;  &lt;/span&gt;return port;&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
We do not need to call a &lt;i&gt;server.close()&lt;/i&gt; since Java 7 does that automatically for us as we used the new &lt;a href="http://www.javacodegeeks.com/2011/07/java-7-try-with-resources-explained.html"&gt;try-catch block with resources&lt;/a&gt; declaration&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1859167416855250911-8020890941984335951?l=groglogs.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/9GZgqMqn_o3uk0bdvq1tYw5zW2w/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/9GZgqMqn_o3uk0bdvq1tYw5zW2w/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/9GZgqMqn_o3uk0bdvq1tYw5zW2w/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/9GZgqMqn_o3uk0bdvq1tYw5zW2w/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;</description><link>http://feedproxy.google.com/~r/groglogs/~3/IS7DgpBEw3E/java-find-free-port.html</link><author>noreply@blogger.com (Stefano Ghio)</author><thr:total>0</thr:total><feedburner:origLink>http://groglogs.blogspot.com/2012/02/java-find-free-port.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1859167416855250911.post-6932644925484834783</guid><pubDate>Fri, 03 Feb 2012 19:19:00 +0000</pubDate><atom:updated>2012-02-03T20:27:37.699+01:00</atom:updated><title>[Java] Access MySQL with Hibernate</title><description>&lt;span style="font-family: Arial, Helvetica, sans-serif;"&gt;In this&amp;nbsp;post we will give a fair example on how to access a &lt;a href="http://www.mysql.com/"&gt;MySQL&lt;/a&gt; database via &lt;a href="http://www.hibernate.org/"&gt;Hibernate&lt;/a&gt; in Java.&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: Arial, Helvetica, sans-serif;"&gt;For this example we will be using MySQL server 5.5, &lt;a href="http://docs.jboss.org/hibernate/orm/3.3/reference/en/html/"&gt;Hibernate 3.3&lt;/a&gt;&amp;nbsp;and the Eclipse IDE.&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: Arial, Helvetica, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: Arial, Helvetica, sans-serif;"&gt;&lt;/span&gt;&lt;br /&gt;
&lt;a name='more'&gt;&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-family: Arial, Helvetica, sans-serif;"&gt;&lt;a href="http://digilander.libero.it/otacoconvention/source/hibernate.zip"&gt;Download here the example's source code&lt;/a&gt;.&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: Arial, Helvetica, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: Arial, Helvetica, sans-serif;"&gt;&lt;a href="http://www.blogger.com/blogger.g?blogID=1859167416855250911"&gt;Suppose&lt;/a&gt; we have access to a database,&lt;em&gt;test&lt;/em&gt;, with a table, &lt;em&gt;testtable&lt;/em&gt;:&lt;/span&gt;&lt;br /&gt;
&lt;table border="1"&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;span style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"&gt;Column name&lt;/span&gt;&lt;/td&gt;
&lt;td&gt;&lt;span style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"&gt;Column type&lt;/span&gt;&lt;/td&gt;
&lt;td&gt;&lt;span style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"&gt;Constraints&lt;/span&gt;&lt;/td&gt;
&lt;td&gt;&lt;span style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"&gt;Description&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;span style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"&gt;id&lt;/span&gt;&lt;/td&gt;
&lt;td&gt;&lt;span style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"&gt;int&lt;/span&gt;&lt;/td&gt;
&lt;td&gt;&lt;span style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"&gt;AUTO_INCREMENT&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"&gt;PRIMARY KEY&lt;/span&gt;&lt;/td&gt;
&lt;td&gt;&lt;span style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"&gt;The object's ID&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;span style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"&gt;column1&lt;/span&gt;&lt;/td&gt;
&lt;td&gt;&lt;span style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"&gt;varchar(20)&lt;/span&gt;&lt;/td&gt;
&lt;td&gt;&lt;span style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"&gt;UNIQUE&lt;/span&gt;&lt;/td&gt;
&lt;td&gt;&lt;span style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"&gt;A unique String for this object&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;span style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"&gt;column2&lt;/span&gt;&lt;/td&gt;
&lt;td&gt;&lt;span style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"&gt;int&lt;/span&gt;&lt;/td&gt;
&lt;td&gt;&lt;span style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"&gt;NOT NULL&lt;/span&gt;&lt;/td&gt;
&lt;td&gt;&lt;span style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"&gt;A mandatory numeric field for this object&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;span style="font-family: Arial, Helvetica, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: Arial, Helvetica, sans-serif;"&gt;Created with the following SQL code:&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: ari;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;code&gt;create table testtable(id int AUTO_INCREMENT, column1 varchar(20) unique, column2 int not null, primary key(id));&lt;/code&gt; 
&lt;br /&gt;
&lt;code&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;
&lt;span style="font-family: Arial, Helvetica, sans-serif;"&gt;And a Java class, &lt;em&gt;PersistentObject&lt;/em&gt;, defining an object to be made persistent in said table:&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: ari;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;code&gt;package it.eng.test.hibernate.persistentobject;&lt;/code&gt;&lt;br /&gt;
&lt;code&gt;import java.io.Serializable;&lt;/code&gt;&lt;br /&gt;
&lt;code&gt;import javax.persistence.Column;&lt;br /&gt;import javax.persistence.Entity;&lt;br /&gt;import javax.persistence.GeneratedValue;&lt;br /&gt;import javax.persistence.GenerationType;&lt;br /&gt;import javax.persistence.Id;&lt;br /&gt;import javax.persistence.NamedQueries;&lt;br /&gt;import javax.persistence.NamedQuery;&lt;br /&gt;import javax.persistence.Table;&lt;br /&gt;import javax.persistence.Transient;&lt;/code&gt;&lt;br /&gt;
&lt;code&gt;@Entity&lt;br /&gt;@Table(name = "testtable")&lt;br /&gt;@NamedQueries(value = {&lt;br /&gt;&amp;nbsp;&amp;nbsp;@NamedQuery(name = "getItem", query = "select i from PersistentObject i where i.column1 = ?"),&lt;br /&gt;&amp;nbsp;&amp;nbsp;@NamedQuery(name = "getItems", query = "select i from PersistentObject i"),&lt;br /&gt;&amp;nbsp;&amp;nbsp;@NamedQuery(name = "deleteItem", query = "delete from PersistentObject i where i.column2 = ?")&lt;br /&gt;&amp;nbsp;&amp;nbsp;})&lt;br /&gt;public class PersistentObject implements Serializable{&lt;br /&gt;&amp;nbsp;&amp;nbsp;private static final long serialVersionUID = -2853745324178701257L;&lt;br /&gt;&amp;nbsp;&amp;nbsp;/*Required for Hibernate*/&lt;br /&gt;&amp;nbsp;&amp;nbsp;@Id&lt;br /&gt;&amp;nbsp;&amp;nbsp;@GeneratedValue(strategy = GenerationType.AUTO)&lt;br /&gt;&amp;nbsp;&amp;nbsp;@Column(name = "id")&lt;br /&gt;&amp;nbsp;&amp;nbsp;private Long id;&lt;br /&gt;&amp;nbsp;&amp;nbsp;/*Our columns*/&lt;br /&gt;&amp;nbsp;&amp;nbsp;@Column(name = "column1")&lt;br /&gt;&amp;nbsp;&amp;nbsp;private String column1;&lt;br /&gt;&amp;nbsp;&amp;nbsp;@Column(name = "column2")&lt;br /&gt;&amp;nbsp;&amp;nbsp;private int column2;&lt;br /&gt;&amp;nbsp;&amp;nbsp;/*This field is part of our PersistentObject but will not be stored on the DB*/&lt;br /&gt;&amp;nbsp;&amp;nbsp;@Transient&lt;br /&gt;&amp;nbsp;&amp;nbsp;private Object nonPersistent;&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;/*Getters &amp;amp; Setters, every persistent field must have one for Hibernate*/&lt;br /&gt;&amp;nbsp;&amp;nbsp;public Long getID(){&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;return id;&lt;br /&gt;&amp;nbsp;&amp;nbsp;}&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;public String getColumn1() {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;return column1;&lt;br /&gt;&amp;nbsp;&amp;nbsp;}&lt;/code&gt;&lt;br /&gt;
&lt;code&gt;&amp;nbsp;&amp;nbsp;public void setColumn1(String column1) {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;this.column1 = column1;&lt;br /&gt;&amp;nbsp;&amp;nbsp;}&lt;/code&gt;&lt;br /&gt;
&lt;code&gt;&amp;nbsp;&amp;nbsp;public int getColumn2() {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;return column2;&lt;br /&gt;&amp;nbsp;&amp;nbsp;}&lt;/code&gt;&lt;br /&gt;
&lt;code&gt;&amp;nbsp;&amp;nbsp;public void setColumn2(int column2) {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;this.column2 = column2;&lt;br /&gt;&amp;nbsp;&amp;nbsp;}&lt;/code&gt;&lt;br /&gt;
&lt;code&gt;&amp;nbsp;&amp;nbsp;public void setId(Long id) {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;this.id = id;&lt;br /&gt;&amp;nbsp;&amp;nbsp;}&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;public Object getNonPersistent() {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;return nonPersistent;&lt;br /&gt;&amp;nbsp;&amp;nbsp;}&lt;/code&gt;&lt;br /&gt;
&lt;code&gt;&amp;nbsp;&amp;nbsp;public void setNonPersistent(Object nonPersistent) {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;this.nonPersistent = nonPersistent;&lt;br /&gt;&amp;nbsp;&amp;nbsp;}&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;/*Required for Hibernate*/&lt;br /&gt;&amp;nbsp;&amp;nbsp;public PersistentObject(){&lt;br /&gt;&amp;nbsp;&amp;nbsp;}&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;/*Our own constructor*/&lt;br /&gt;&amp;nbsp;&amp;nbsp;public PersistentObject(String column1, int column2, Object nonPersistent){&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;this.column1 = column1;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;this.column2 = column2;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;this.nonPersistent = nonPersistent;&lt;br /&gt;&amp;nbsp;&amp;nbsp;}&lt;br /&gt;}&lt;/code&gt;&lt;br /&gt;
&lt;code&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;
&lt;span style="font-family: Arial, Helvetica, sans-serif;"&gt;&amp;nbsp;By using Java annotations, we are able to easily mark which class fields we want to make persistent and which queries we are going to create for our object:&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: ari;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;code&gt;@Entity&lt;/code&gt;&lt;br /&gt;
&lt;code&gt;@Table(name = "testtable")&lt;/code&gt;&lt;br /&gt;
&lt;code&gt;@NamedQueries(value = { @NamedQuery(name = "getItem", query = "select i from PersistentObject i where i.column1 = ?"), &lt;/code&gt;&lt;br /&gt;
&lt;code&gt;@NamedQuery(name = "getItems", query = "select i from PersistentObject i"), &lt;/code&gt;&lt;br /&gt;
&lt;code&gt;@NamedQuery(name = "deleteItem", query = "delete from PersistentObject i where i.column2 = ?") })&lt;/code&gt;&lt;br /&gt;
&lt;code&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;
&lt;span style="font-family: Arial, Helvetica, sans-serif;"&gt;With this, we are saying that there is a table called &lt;em&gt;testtable&lt;/em&gt; in our database on which the queries listed afterwards should operate. We wrote them in &lt;a href="http://docs.jboss.org/hibernate/orm/3.3/reference/en/html/queryhql.html"&gt;HQL&lt;/a&gt;, a modified version on SQL by Hibernate.&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: Arial, Helvetica, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: Arial, Helvetica, sans-serif;"&gt;The first query for example is the equivalent of:&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: ari;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: ari;"&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: ari;"&gt;&lt;code&gt;SELECT * FROM testtable WHERE column1 = VALUE;&lt;/code&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: ari;"&gt;&lt;code&gt;&lt;br /&gt;&lt;/code&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-family: Arial, Helvetica, sans-serif;"&gt;and by executing it, we are returned the matching PersistentObject object(s).&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: Arial, Helvetica, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: Arial, Helvetica, sans-serif;"&gt;The&lt;strong&gt; PRIMARY KEY&lt;/strong&gt; is specified as required for Hibernate as an AUTO_INCREMENT integer:&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: ari;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;@Id &lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;@GeneratedValue(strategy = GenerationType.AUTO) @Column(name = "id")&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: 'Courier New', Courier, monospace;"&gt;private Long id;&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: 'Courier New';"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: Arial, Helvetica, sans-serif;"&gt;Note that our class can also include fields which will not be stored; to define so, we simply mark them as &lt;strong&gt;@Transient&lt;/strong&gt;.&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: Arial, Helvetica, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: Arial, Helvetica, sans-serif;"&gt;Hibernate also requires us to create an empty constructor and getter and setter methods for each persistent field.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-family: Arial, Helvetica, sans-serif;"&gt;Now we need to create two more classes in order for Hibernate to function properly:&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: ari;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: 'Courier New';"&gt;package it.eng.test.hibernate;&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: 'Courier New';"&gt;import javax.persistence.EntityManager;&lt;br /&gt;import javax.persistence.EntityManagerFactory;&lt;br /&gt;import javax.persistence.Persistence;&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: 'Courier New';"&gt;public class HibernateServiceUtil {&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: 'Courier New';"&gt;&amp;nbsp;private static EntityManagerFactory emf;&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; private static EntityManager em;&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; /*The name of our PERSISTENCE_UNIT, as specified in the META-INF/persistence.xml file*/&lt;br /&gt;&amp;nbsp;private static final String PERSISTENCE_UNIT = "TEST"; &lt;br /&gt;&lt;br /&gt;&amp;nbsp;/*Initialize our DB connection*/&lt;br /&gt;&amp;nbsp;public static EntityManager initEntityManager() {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (emf == null) {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;/*&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; * If we want to set those properties via code rather than write them in the XML file:&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; * &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;Map addedOrOverridenProperties = new HashMap();&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;addedOrOverridenProperties.put("hibernate.connection.password", PWD);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;addedOrOverridenProperties.put("hibernate.connection.url", URL);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;addedOrOverridenProperties.put("hibernate.connection.username", USERNAME);&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;emf = Persistence.createEntityManagerFactory(PERSISTENCE_UNIT, addedOrOverridenProperties);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;*/&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;emf = Persistence.createEntityManagerFactory(PERSISTENCE_UNIT);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; em = emf.createEntityManager();&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return em;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public void cleanup() {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; em.clear();&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;emf.close();&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: 'Courier New';"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: Arial, Helvetica, sans-serif;"&gt;With this, we define a way to initialize Hibernate's &lt;em&gt;Entity Manager&lt;/em&gt; for our &lt;em&gt;persistence units&lt;/em&gt;. We are also required to create an XML file called &lt;em&gt;persistence.xml&lt;/em&gt; and put it under the &lt;em&gt;META-INF/&lt;/em&gt; folder of our project:&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: ari;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: 'Courier New';"&gt;&amp;lt;?xml version="1.0" encoding="UTF-8"?&amp;gt;&lt;br /&gt;&amp;lt;persistence version="1.0"&lt;br /&gt;&amp;nbsp;xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"&lt;br /&gt;&amp;nbsp;xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;lt;persistence-unit name="TEST" transaction-type="RESOURCE_LOCAL"&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;lt;class&amp;gt;it.eng.test.hibernate.persistentobject.PersistentObject&amp;lt;/class&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;lt;properties&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;property name="hibernate.archive.autodetection" value="class, hbm" /&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;property name="hibernate.show_sql" value="true" /&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver" /&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;!-- We can set those via code in the HibernateServiceUtil class --&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;property name="hibernate.connection.password" value="12345" /&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;property name="hibernate.connection.url" value="jdbc:mysql://127.0.0.1/test" /&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;property name="hibernate.connection.username" value="root" /&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;!-- *** --&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect" /&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;property name="hibernate.c3p0.min_size" value="5" /&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;property name="hibernate.c3p0.max_size" value="20" /&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;property name="hibernate.c3p0.timeout" value="300" /&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;property name="hibernate.c3p0.max_statements" value="50" /&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;property name="hibernate.c3p0.idle_test_period" value="3000" /&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;lt;/properties&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;lt;/persistence-unit&amp;gt;&lt;br /&gt;&amp;lt;/persistence&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: 'Courier New';"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: Arial, Helvetica, sans-serif;"&gt;Where we define, among other things, the connection parameters for the database containing the table for our &lt;em&gt;PersistentObject&lt;/em&gt; objects:&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: ari;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: 'Courier New';"&gt;&amp;lt;property name="hibernate.connection.password" value="PWD" /&amp;gt; &lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: 'Courier New';"&gt;&amp;lt;property name="hibernate.connection.url" value="jdbc:mysql://URL/test" /&amp;gt; &lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: 'Courier New';"&gt;&amp;lt;property name="hibernate.connection.username" value="USERNAME" /&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: 'Courier New';"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: Arial, Helvetica, sans-serif;"&gt;Alternatively, we could set those parameters at runtime by using the following code inside the &lt;em&gt;HibernateServiceUtil&lt;/em&gt; class:&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: ari;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: 'Courier New';"&gt;Map addedOrOverridenProperties = new HashMap(); &lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: 'Courier New';"&gt;addedOrOverridenProperties.put("hibernate.connection.password", PWD); &lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: 'Courier New';"&gt;addedOrOverridenProperties.put("hibernate.connection.url", URL); &lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: 'Courier New';"&gt;addedOrOverridenProperties.put("hibernate.connection.username", USERNAME); &lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: 'Courier New';"&gt;emf = Persistence.createEntityManagerFactory(PERSISTENCE_UNIT, addedOrOverridenProperties);&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-family: Arial, Helvetica, sans-serif;"&gt;We also need a &lt;em&gt;PersistentObjectHibernateUtil&lt;/em&gt; class where to code our queries in Java to perform at least the basic CRUD operations:&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: ari;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;code&gt;package it.eng.test.hibernate.persistentobject;&lt;/code&gt;&lt;br /&gt;
&lt;code&gt;import java.util.List;&lt;/code&gt;&lt;br /&gt;
&lt;code&gt;import it.eng.test.hibernate.HibernateServiceUtil;&lt;/code&gt;&lt;br /&gt;
&lt;code&gt;import javax.persistence.EntityManager;&lt;br /&gt;import javax.persistence.Query;&lt;/code&gt;&lt;br /&gt;
&lt;code&gt;public class PersistentObjectHibernateUtil {&lt;/code&gt;&lt;br /&gt;
&lt;code&gt;&amp;nbsp;private static EntityManager entityManager;&lt;/code&gt;&lt;br /&gt;
&lt;code&gt;&amp;nbsp;public static void initPersistentObjectHibernateUtil() {&lt;br /&gt;&amp;nbsp;&amp;nbsp;entityManager = HibernateServiceUtil.initEntityManager();&lt;br /&gt;&amp;nbsp;}&lt;/code&gt;&lt;br /&gt;
&lt;code&gt;&amp;nbsp;/*Create and store our object on the DB*/&lt;br /&gt;&amp;nbsp;public static PersistentObject savePersistentObject(String column1, int column2, Object nonPersistent) {&lt;br /&gt;&amp;nbsp;&amp;nbsp;entityManager.getTransaction().begin();&lt;br /&gt;&amp;nbsp;&amp;nbsp;PersistentObject p = new PersistentObject();&lt;br /&gt;&amp;nbsp;&amp;nbsp;p.setColumn1(column1);&lt;br /&gt;&amp;nbsp;&amp;nbsp;p.setColumn2(column2);&lt;br /&gt;&amp;nbsp;&amp;nbsp;p.setNonPersistent(nonPersistent);&lt;br /&gt;&amp;nbsp;&amp;nbsp;entityManager.persist(p);&lt;br /&gt;&amp;nbsp;&amp;nbsp;entityManager.getTransaction().commit();&lt;br /&gt;&amp;nbsp;&amp;nbsp;return p;&lt;br /&gt;&amp;nbsp;}&lt;br /&gt;&lt;br /&gt;&amp;nbsp;/*Store an already existing object on the DB*/&lt;br /&gt;&amp;nbsp;public static void savePersistentObject(PersistentObject p) {&lt;br /&gt;&amp;nbsp;&amp;nbsp;entityManager.getTransaction().begin();&lt;br /&gt;&amp;nbsp;&amp;nbsp;entityManager.persist(p);&lt;br /&gt;&amp;nbsp;&amp;nbsp;entityManager.getTransaction().commit();&lt;br /&gt;&amp;nbsp;}&lt;/code&gt;&lt;br /&gt;
&lt;code&gt;&amp;nbsp;/*Implementation of our NamedQueries*/&lt;br /&gt;&lt;br /&gt;&amp;nbsp;public static PersistentObject getItem(String column1){&lt;br /&gt;&amp;nbsp;&amp;nbsp;try{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;Query query = entityManager.createNamedQuery("getItem");&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;/*place this value where the first ? appeared in the query*/&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;query.setParameter(1, column1);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;PersistentObject result = (PersistentObject) query.getSingleResult();&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;return result;&lt;br /&gt;&amp;nbsp;&amp;nbsp;}catch(Exception e){&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;System.err.println("unable to get PersistentObject "+column1+" from DB");&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;return null;&lt;br /&gt;&amp;nbsp;&amp;nbsp;}&lt;br /&gt;&amp;nbsp;}&lt;br /&gt;&lt;br /&gt;&amp;nbsp;@SuppressWarnings("unchecked")&lt;br /&gt;&amp;nbsp;public static List&amp;lt;PersistentObject&amp;gt; getItems(){&lt;br /&gt;&amp;nbsp;&amp;nbsp;try{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;Query query = entityManager.createNamedQuery("getItems");&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;return query.getResultList();&lt;br /&gt;&amp;nbsp;&amp;nbsp;}catch(Exception e){&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;System.err.println("unable to get PersistentObjects from DB");&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;return null;&lt;br /&gt;&amp;nbsp;&amp;nbsp;}&lt;br /&gt;&amp;nbsp;}&lt;br /&gt;&lt;br /&gt;&amp;nbsp;public static void deleteItem(int column2){&lt;br /&gt;&amp;nbsp;&amp;nbsp;try{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;Query query = entityManager.createNamedQuery("deleteItem");&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;/*place this value where the first ? appeared in the query*/&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;query.setParameter(1, column2);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;query.executeUpdate();&lt;br /&gt;&amp;nbsp;&amp;nbsp;}catch(Exception e){&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;System.err.println("unable to delete PersistentObject "+column2+" from DB "+e.getMessage());&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;e.printStackTrace();&lt;br /&gt;&amp;nbsp;&amp;nbsp;}&lt;br /&gt;&amp;nbsp;}&lt;br /&gt;&lt;br /&gt;&amp;nbsp;/*We can also overload those methods*/&lt;br /&gt;&amp;nbsp;public static void deleteItem(PersistentObject p){&lt;br /&gt;&amp;nbsp;&amp;nbsp;try{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;entityManager.getTransaction().begin();&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;Query query = entityManager.createNamedQuery("deleteItem");&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;query.setParameter(1, p.getColumn2());&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;query.executeUpdate();&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;entityManager.getTransaction().commit();&lt;br /&gt;&amp;nbsp;&amp;nbsp;}catch(Exception e){&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;System.err.println("unable to delete PersistentObject "+p.getColumn2()+" from DB "+e.getMessage());&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;e.printStackTrace();&lt;br /&gt;&amp;nbsp;&amp;nbsp;}&lt;br /&gt;&amp;nbsp;}&lt;br /&gt;&lt;br /&gt;&amp;nbsp;/*Updates an object already stored*/&lt;br /&gt;&amp;nbsp;public static void updatePersistentObject(PersistentObject p){&lt;br /&gt;&amp;nbsp;&amp;nbsp;try{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;if (p == null){&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;System.err.println("cannot update PersistentObject because it is NULL");&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;entityManager.getTransaction().begin();&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;entityManager.merge(p);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;entityManager.getTransaction().commit();&lt;br /&gt;&amp;nbsp;&amp;nbsp;}catch(Exception e){&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;System.err.println("unable to update PersistentObject "+p.getColumn1()+" on DB");&lt;br /&gt;&amp;nbsp;&amp;nbsp;}&lt;br /&gt;&amp;nbsp;}&lt;/code&gt;&lt;br /&gt;
&lt;code&gt;}&lt;/code&gt;&lt;br /&gt;
&lt;span style="font-family: Arial, Helvetica, sans-serif;"&gt;As you can see, for every &lt;em&gt;namedQuery&lt;/em&gt; previously defined and for basic operations, we define a method which tells Hibernate what to perform for us. For example, for the &lt;em&gt;getItem&lt;/em&gt; query previously defined we use:&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: ari;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: 'Courier New';"&gt;Query query = entityManager.createNamedQuery("getItem");&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: 'Courier New';"&gt;query.setParameter(1, VALUE);&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: 'Courier New';"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: Arial, Helvetica, sans-serif;"&gt;to tell Hibernate to replace the first "?" in the query HQL with VALUE before executing it.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-family: Arial, Helvetica, sans-serif;"&gt;Finally, we are required to put an additional XML file, called &lt;em&gt;hibernate.cfg.xml&lt;/em&gt; under our project's root:&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: ari;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: 'Courier New';"&gt;&amp;lt;?xml version="1.0" encoding="UTF-8"?&amp;gt;&lt;br /&gt;&amp;lt;!DOCTYPE hibernate-configuration PUBLIC&lt;br /&gt;&amp;nbsp;&amp;nbsp;"-//Hibernate/Hibernate Configuration DTD 3.0//EN"&lt;br /&gt;&amp;nbsp;&amp;nbsp;"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"&amp;gt;&lt;br /&gt;&amp;lt;hibernate-configuration&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;session-factory&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;property name="hibernate.connection.driver_class"&amp;gt;com.mysql.jdbc.Driver&amp;lt;/property&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;property name="hibernate.connection.password"&amp;gt;12345&amp;lt;/property&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;property name="hibernate.connection.url"&amp;gt;jdbc:mysql://127.0.0.1/test&amp;lt;/property&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;property name="hibernate.connection.username"&amp;gt;root&amp;lt;/property&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;property name="hibernate.default_schema"&amp;gt;test&amp;lt;/property&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;property name="hibernate.dialect"&amp;gt;org.hibernate.dialect.MySQLDialect&amp;lt;/property&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;!-- JDBC connection pool (use the built-in) --&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;lt;property name="connection.pool_size"&amp;gt;1&amp;lt;/property&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;lt;!-- Enable Hibernate's automatic session context management --&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;lt;property name="current_session_context_class"&amp;gt;thread&amp;lt;/property&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;lt;!-- Disable the second-level cache --&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;lt;property name="cache.provider_class"&amp;gt;org.hibernate.cache.NoCacheProvider&amp;lt;/property&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;lt;!-- Echo all executed SQL to stdout --&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;lt;property name="show_sql"&amp;gt;true&amp;lt;/property&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/session-factory&amp;gt;&lt;br /&gt;&amp;lt;/hibernate-configuration&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: 'Courier New';"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: Arial, Helvetica, sans-serif;"&gt;where we define some Hibernate configuration parameters.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-family: Arial, Helvetica, sans-serif;"&gt;You can then export the project as a &lt;strong&gt;Runnable JAR&lt;/strong&gt; from Eclipse or &lt;a href="https://skydrive.live.com/redir.aspx?cid=19468fe08387b566&amp;amp;resid=19468FE08387B566!15312&amp;amp;parid=19468FE08387B566!3289&amp;amp;authkey=!ACC4Ud0kMynqBUI"&gt;download here the already packaged and ready-to-go demo&lt;/a&gt;.&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1859167416855250911-6932644925484834783?l=groglogs.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/hpdbfrMnZgDkrP9QDQEH5O-SaV4/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/hpdbfrMnZgDkrP9QDQEH5O-SaV4/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/hpdbfrMnZgDkrP9QDQEH5O-SaV4/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/hpdbfrMnZgDkrP9QDQEH5O-SaV4/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;</description><link>http://feedproxy.google.com/~r/groglogs/~3/vfRx_hjVQis/java-access-mysql-with-hibernate.html</link><author>noreply@blogger.com (Stefano Ghio)</author><thr:total>0</thr:total><feedburner:origLink>http://groglogs.blogspot.com/2012/02/java-access-mysql-with-hibernate.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1859167416855250911.post-2596136720044455760</guid><pubDate>Wed, 01 Feb 2012 16:39:00 +0000</pubDate><atom:updated>2012-02-01T18:14:18.757+01:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">HowTo</category><category domain="http://www.blogger.com/atom/ns#">Source code</category><title>ECF remote OSGi DS Declarative Services example</title><description>&lt;span style="font-family: Arial;"&gt;In this post we will give a fair example of the workings of the &lt;a href="http://groglogs.blogspot.com/2012/01/osgi-ds-declarative-services-example.html"&gt;OSGi DS Declarative Services&lt;/a&gt; remoted with &lt;a href="http://www.eclipse.org/ecf/"&gt;ECF&lt;/a&gt;.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;&lt;span style="font-family: Arial;"&gt;For this example we will be using the Eclipse IDE for Java with the &lt;a href="http://wiki.eclipse.org/EIG:Add_to_Target_Platform"&gt;ECF Remote Services Target Components&lt;/a&gt;  plug-in, the &lt;a href="http://eclipse.org/equinox/"&gt;Equinox&lt;/a&gt; framework and &lt;a href="http://zookeeper.apache.org/releases.html"&gt;ZooKeeper&lt;/a&gt; as a service discovery provider.&lt;/span&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;a name='more'&gt;&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;&lt;span style="font-family: Arial;"&gt;Suppose we have a service: &lt;em&gt;HelloService&lt;/em&gt;, its interface: &lt;em&gt;IHello &lt;/em&gt;and a client: &lt;em&gt;HelloConsumer &lt;/em&gt;who declares a dependency on the service by pointing to its interface using the DS method. He would also like to be able to remotely access it.&lt;/span&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;pre&gt;&lt;span style="font-family: Arial;"&gt;When a component declares it provides a service, the OSGi framework stores that information in its internal registry.&lt;/span&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;pre&gt;&lt;span style="font-family: Arial;"&gt;&lt;a href="http://digilander.libero.it/otacoconvention/source/osgi/ecf_ds.zip"&gt;Download here the example's source code&lt;/a&gt;&lt;/span&gt;&lt;span style="font-family: Arial;"&gt;. You should be able to import everything inside Eclipse as-is. Inside you will find:&lt;/span&gt;&lt;/pre&gt;
&lt;ul&gt;
&lt;li&gt;&lt;span style="font-family: Arial;"&gt;Interface - &lt;strong&gt;IHello.java&lt;/strong&gt;:&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;span style="font-family: 'Courier New';"&gt;package it.eng.test.remote.ds.hello;&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: 'Courier New';"&gt;public interface IHello {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public String greet(String to);&lt;br /&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;&lt;span style="font-family: Arial;"&gt;Implementation - &lt;strong&gt;HelloService.java&lt;/strong&gt;:&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;span style="font-family: 'Courier New';"&gt;package it.eng.test.remote.ds.helloservice;&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: 'Courier New';"&gt;import it.eng.test.remote.ds.hello.IHello;&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: 'Courier New';"&gt;public class HelloService implements IHello{&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: 'Courier New';"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public String greet(String to){&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return "Greetings "+to;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&amp;nbsp; &lt;br /&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;&lt;span style="font-family: Arial;"&gt;As we can see, the service offers a single, simple method which returns a String.&lt;/span&gt;&lt;/pre&gt;
&lt;ul&gt;
&lt;li&gt;&lt;span style="font-family: Arial;"&gt;Client - &lt;b&gt;HelloConsumer.java&lt;/b&gt;:&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;span style="font-family: 'Courier New';"&gt;package it.eng.test.remote.ds.helloconsumer;&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: 'Courier New';"&gt;import it.eng.test.remote.ds.hello.IHello;&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: 'Courier New';"&gt;public class HelloConsumer {&amp;nbsp; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public void bindHello(IHello proxy) {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; System.out.println("Got proxy IHello="+proxy);&amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; System.out.println(proxy.greet(proxy.toString()));&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&amp;nbsp; &lt;br /&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;&lt;span style="font-family: Arial;"&gt;The consumer declares the dependency on the service by requiring its interfaces and has a single method, &lt;em&gt;bindHello&lt;/em&gt;, which prints something on standard output as soon as the required remote service becomes available to the consumer.&lt;/span&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;pre&gt;&lt;span style="font-family: Arial;"&gt;The framework knows that &lt;em&gt;HelloConsumer&lt;/em&gt; needs that particular services since he declared it in his XML configuration which must be put under the &lt;em&gt;OSGI-INF/&lt;/em&gt; folder:&lt;/span&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;span style="font-family: 'Courier New';"&gt;&amp;lt;?xml version="1.0" encoding="UTF-8"?&amp;gt;&lt;br /&gt;&amp;lt;scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" name="it.eng.test.remote.ds.helloconsumer"&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;lt;implementation class="it.eng.test.remote.ds.helloconsumer.HelloConsumer"/&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;lt;reference bind="bindHello" cardinality="0..n" interface="it.eng.test.remote.ds.hello.IHello" name="IHello" policy="dynamic"/&amp;gt;&lt;br /&gt;&amp;lt;/scr:component&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;&lt;span style="font-family: Arial;"&gt;Here the bundle is saying that the class &lt;em&gt;it.eng.test.remote.ds.helloconsumer.HelloConsumer&lt;/em&gt; dynamically and optionally depends on one of the possible &lt;em&gt;it.eng.test.remote.ds.hello.IHello&lt;/em&gt; interface implementations and that when one of them becomes available inside the framework, its &lt;em&gt;bindHappy&lt;/em&gt; method should be called.&lt;/span&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;&lt;span style="font-family: Arial;"&gt;The &lt;em&gt;dynamically&lt;/em&gt; &lt;strong&gt;policy&lt;/strong&gt; attribute means that the bundle is able to work properly even when the services are dynamically switched; the alternative would be &lt;em&gt;static&lt;/em&gt;, which would require the DS to deactivate the component and create a new instance each time the required service changes.&lt;/span&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;pre&gt;&lt;span style="font-family: Arial;"&gt;The dependency is optional since the &lt;strong&gt;cardinality&lt;/strong&gt; was set to &lt;em&gt;0..N&lt;/em&gt;, meaning the component can be started even if that particular dependency is not currently available and it requires the DS to invoke the associated method multiple times, one for each service instance currently available in the registry. &lt;em&gt;1..1&lt;/em&gt; would mean instead that the dependency is mandatory. Another alternative would be &lt;em&gt;0..1&lt;/em&gt;.&lt;/span&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;pre&gt;&lt;span style="font-family: Arial;"&gt;Furthermore, the name of the &lt;em&gt;bind* &lt;/em&gt;method can be changed as pleased as long as it reflects the one written in the java code.&lt;/span&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;pre&gt;&lt;span style="font-family: Arial;"&gt;On its side, the service must declare its own XML configuration, listing the interface implementations offered, the classes implementing them, and a series of parameters used to make the service remotable.&lt;/span&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;span style="font-family: 'Courier New';"&gt;&amp;lt;?xml version="1.0" encoding="UTF-8"?&amp;gt;&lt;br /&gt;&amp;lt;scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" name="it.eng.test.remote.ds.helloservice"&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;lt;implementation class="it.eng.test.remote.ds.helloservice.HelloService"/&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;lt;property name="service.exported.interfaces" type="String" value="*"/&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;lt;property name="service.exported.configs" type="String" value="ecf.generic.server"/&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;lt;property name="ecf.exported.containerfactoryargs" type="String" value="ecftcp://192.168.23.28:6666/hello"/&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;lt;service&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;provide interface="it.eng.test.remote.ds.hello.IHello"/&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;lt;/service&amp;gt;&lt;br /&gt;&amp;lt;/scr:component&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;&lt;span style="font-family: Arial;"&gt;This line indicates that all methods described in the service interface are to be made remotable:&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;   &amp;lt;property name="service.exported.interfaces" type="String" value="*"/&amp;gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style="font-family: Arial;"&gt;This value is linked to the OSGi framework implementation we used (Equinox + ECF) and indicates that the service should be exposed as a Web Service:&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style="font-family: Arial;"&gt;   &lt;/span&gt;&amp;lt;property name="service.exported.configs" type="String" value="ecf.generic.server"/&amp;gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style="font-family: Arial;"&gt;located here:&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;   &amp;lt;property name="ecf.exported.containerfactoryargs" type="String" value="ecftcp://192.168.23.28:6666/hello"/&amp;gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style="font-family: Arial;"&gt;If we do not set the previous property, the service will be published by ZooKeeper as remotable anyway but it will use a random port, the machine hostname instead of its IP and a auto-generated folder name. Currently there is no way to have it use the IP in any case.&lt;/span&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;pre&gt;&lt;span style="font-family: Arial;"&gt;As you can see by looking at the source code, nowhere is written where to publish or locate a service (assume we did not set the last of the above properties). However, since magic happens only in movies, there must be some place where to define those properties, else nothing will work.&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style="font-family: Arial;"&gt;
&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style="font-family: Arial;"&gt;In our setup, using ZooKeeper allows us to configure the service discovery protocol in &lt;a href="http://wiki.eclipse.org/Zookeeper_Based_ECF_Discovery"&gt;multiple ways&lt;/a&gt;:&lt;/span&gt;&lt;/pre&gt;
&lt;ul&gt;
&lt;li&gt;&lt;span style="font-family: Arial;"&gt;&lt;strong&gt;standalone&lt;/strong&gt;: each framework's ZooKeeper instance must know the exact IP of the others in order to communicate with it. If a new client appears, there is no way to make it join the network without having to reconfigure and restart every instance;&lt;/span&gt;&lt;/li&gt;
&lt;br /&gt;
&lt;li&gt;&lt;span style="font-family: Arial;"&gt;&lt;strong&gt;centralized&lt;/strong&gt;: a central ZooKeeper instance acts as a server with which other instances register. When a new client appears it must know the central ZooKeeper's IP in order to koin the network. All services are shared through the one and only central instance, if it goes down, the entire network crashes;&lt;/span&gt;&lt;/li&gt;
&lt;br /&gt;
&lt;li&gt;&lt;span style="font-family: Arial;"&gt;&lt;strong&gt;replicated&lt;/strong&gt;: a group of servers is configured to communicate, perform leader elections and manage the service discovery routine. The group servers IPs must still be known by every peer, but this allows for more flexibility.&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;pre&gt;&lt;span style="font-family: Arial;"&gt;we chose the &lt;em&gt;standalone&lt;/em&gt; one which means we configure the Java VM at launch time with the needed information.&lt;/span&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;pre&gt;&lt;span style="font-family: Arial;"&gt;Before being able to export our applications from Eclipse or run them within it, we shall follow additional steps to effectively create &lt;em&gt;Eclipse Applications&lt;/em&gt; from our code.&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style="font-family: Arial;"&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;&lt;span style="font-family: Arial;"&gt;Lars Vogel wrote a good tutorial about &lt;a href="http://www.vogella.de/articles/EclipseRCP/article.html"&gt;Eclipse RCP Applications&lt;/a&gt;. We can follow it, but keep in mind we are not exactly going to deploy an Eclipse application, instead we will be using those mechanics to successfully export our OSGi bundles along with all necessary dependencies and configuration.&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style="font-family: Arial;"&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;&lt;span style="font-family: Arial;"&gt;We must thus add a class implementing the &lt;em&gt;IApplication&lt;/em&gt; interface in both service and client along an XML configuration file which shall go under the project's root folder.&lt;/span&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;pre&gt;&lt;span style="font-family: Arial;"&gt;Service - &lt;strong&gt;HelloApp.java&lt;/strong&gt;:&lt;/span&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;span style="font-family: 'Courier New';"&gt;package it.eng.test.remote.ds.helloservice;&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: 'Courier New';"&gt;import org.eclipse.equinox.app.IApplication;&lt;br /&gt;import org.eclipse.equinox.app.IApplicationContext;&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: 'Courier New';"&gt;public class HelloApp implements IApplication {&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: 'Courier New';"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; boolean done = false;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Object appLock = new Object();&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: 'Courier New';"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public Object start(IApplicationContext context) throws Exception {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // We just wait...everything is done by DS and HelloComponent&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; synchronized (appLock) {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; while (!done) {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; try {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; appLock.wait();&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; } catch (InterruptedException e) {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // do nothing&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return IApplication.EXIT_OK;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: 'Courier New';"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public void stop() {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; synchronized (appLock) {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; done = true;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; appLock.notifyAll();&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: 'Courier New';"&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;&lt;span style="font-family: Arial;"&gt;with this XML configuration:&lt;/span&gt;&lt;/pre&gt;
&lt;span style="font-family: 'Courier New';"&gt;&amp;lt;?xml version="1.0" encoding="UTF-8"?&amp;gt;&lt;br /&gt;&amp;lt;?eclipse version="3.7"?&amp;gt;&lt;br /&gt;&amp;lt;plugin&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;lt;extension&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; id="HelloServiceTest"&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; point="org.eclipse.core.runtime.applications"&amp;gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;application&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cardinality="*"&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; thread="any"&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; visible="true"&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;run&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;class="it.eng.test.remote.ds.helloservice.HelloApp"&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/run&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/application&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;lt;/extension&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: 'Courier New';"&gt;&amp;lt;/plugin&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;&lt;span style="font-family: Arial;"&gt;Client - &lt;strong&gt;HelloCApp.java&lt;/strong&gt;:&lt;/span&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;span style="font-family: 'Courier New';"&gt;package it.eng.test.remote.ds.helloconsumer;&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: 'Courier New';"&gt;import org.eclipse.equinox.app.IApplication;&lt;br /&gt;import org.eclipse.equinox.app.IApplicationContext;&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: 'Courier New';"&gt;public class HelloCApp implements IApplication {&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: 'Courier New';"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; boolean done = false;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Object appLock = new Object();&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: 'Courier New';"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public Object start(IApplicationContext context) throws Exception {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // We just wait...everything is done by DS and HelloComponent&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; synchronized (appLock) {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; while (!done) {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; try {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; appLock.wait();&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; } catch (InterruptedException e) {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // do nothing&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return IApplication.EXIT_OK;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: 'Courier New';"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public void stop() {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; synchronized (appLock) {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; done = true;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; appLock.notifyAll();&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: 'Courier New';"&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;&lt;span style="font-family: Arial;"&gt;with this XML configuration :&lt;/span&gt;&lt;/pre&gt;
&lt;span style="font-family: 'Courier New';"&gt;&amp;lt;?xml version="1.0" encoding="UTF-8"?&amp;gt;&lt;br /&gt;&amp;lt;?eclipse version="3.4"?&amp;gt;&lt;br /&gt;&amp;lt;plugin&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;lt;extension&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; id="HelloConsumerTest"&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; point="org.eclipse.core.runtime.applications"&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;application&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cardinality="*"&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; thread="any"&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; visible="true"&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;run&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;class="it.eng.test.remote.ds.helloconsumer.HelloCApp"&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/run&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/application&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;lt;/extension&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: 'Courier New';"&gt;&amp;lt;/plugin&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;&lt;span style="font-family: Arial;"&gt;We have hence defined for both service and client two methods: &lt;em&gt;start&lt;/em&gt; and &lt;em&gt;stop&lt;/em&gt; which, guess what, are called when the application is started or stopped.&lt;/span&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;&lt;span style="font-family: Arial;"&gt;In the plugin.xml configuration we say that our applications shall be visible for the user; for example, some applications may provide features to other applications but nothing directly to the user, in this case the application should not be revealed to the user to start it individually. They may run in any thread instead of only the main one and that an unlimited number of instances can be active at the same time.&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style="font-family: Arial;"&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;&lt;span style="font-family: Arial;"&gt;Now, before successfully launch them, we must configure ZooKeeper to properly do its job. We can do this by changing the application launch parameters to include all necessary dependencies (including &lt;em&gt;org.apache.hadoop.zookeeper&lt;/em&gt; and &lt;em&gt;org.eclipse.ecf.provider.zookeeper&lt;/em&gt;) and the following Java VM arguments inside the &lt;em&gt;Run configuration&lt;/em&gt;:&lt;/span&gt;&lt;/pre&gt;
&lt;code&gt;-Dzoodiscovery.dataDir=bla -Dzoodiscovery.flavor=zoodiscovery.flavor.standalone=192.168.23.28:3030;clientPort=3031&lt;/code&gt;
&lt;br /&gt;
&lt;pre&gt;&lt;span style="font-family: Arial;"&gt;for the service, and:&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;-Dzoodiscovery.autoStart=true; -Dzoodiscovery.flavor=zoodiscovery.flavor.standalone=192.168.23.28:3031;clientPort=3030&lt;/pre&gt;
&lt;pre&gt;&lt;span style="font-family: Arial;"&gt;for the client.&lt;/span&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;pre&gt;&lt;span style="font-family: Arial;"&gt;With that we are saying that the service's ZooKeeper component should use the &lt;em&gt;bla/&lt;/em&gt; directory to store its temporary files and publish the service in a standalone configuration at the specified &lt;em&gt;IP:PORT&lt;/em&gt; using &lt;em&gt;clientPort&lt;/em&gt; for incoming connections; the client's ZooKeeper component on its side should instead automatically scan the network for other ZooKeeper instances at startup time connecting to the one at the specified address in order to share services between the two involved frameworks (in our case they are on the same host but cannot be inside the same framework - how would configure ZooKeeper then?).&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style="font-family: Arial;"&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;&lt;span style="font-family: Arial;"&gt;Eclipse allows us to create from the previously generated &lt;em&gt;Run configurations&lt;/em&gt; the &lt;em&gt;Product configurations &lt;/em&gt;for our applications and store them in particular XML files called &lt;em&gt;product&lt;/em&gt; files, usually stored under the &lt;em&gt;product/&lt;/em&gt; folder. These files also include the OSGi framework's required plug-ins in order for every component to work:&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style="font-family: Arial;"&gt;
&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style="font-family: Arial;"&gt;Service - &lt;strong&gt;helloservicezookeeper.product&lt;/strong&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;span style="font-family: 'Courier New';"&gt;&amp;lt;?xml version="1.0" encoding="UTF-8"?&amp;gt;&lt;br /&gt;&amp;lt;?pde version="3.5"?&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: 'Courier New';"&gt;&amp;lt;product application="it.eng.test.remote.ds.helloservice.HelloServiceTest" useFeatures="false" includeLaunchers="true"&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: 'Courier New';"&gt;&amp;nbsp;&amp;nbsp; &amp;lt;configIni use="default"&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;lt;/configIni&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: 'Courier New';"&gt;&amp;nbsp;&amp;nbsp; &amp;lt;launcherArgs&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;programArgs&amp;gt;-consoleLog -console&amp;lt;/programArgs&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;vmArgs&amp;gt;-Declipse.ignoreApp=true -Dosgi.noShutdown=true -Dzoodiscovery.dataDir=bla&lt;br /&gt;    -Dzoodiscovery.flavor=zoodiscovery.flavor.standalone=192.168.23.28:3030;clientPort=3031&amp;lt;/vmArgs&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;vmArgsMac&amp;gt;-XstartOnFirstThread -Dorg.eclipse.swt.internal.carbon.smallFonts&amp;lt;/vmArgsMac&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;lt;/launcherArgs&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: 'Courier New';"&gt;&amp;nbsp;&amp;nbsp; &amp;lt;launcher&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;solaris/&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;win useIco="false"&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;bmp/&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/win&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;lt;/launcher&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: 'Courier New';"&gt;&amp;nbsp;&amp;nbsp; &amp;lt;vm&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;lt;/vm&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: 'Courier New';"&gt;&amp;nbsp;&amp;nbsp; &amp;lt;plugins&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;plugin id="it.eng.test.remote.ds.hello"/&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;plugin id="it.eng.test.remote.ds.helloservice"/&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;plugin id="javax.transaction" fragment="true"/&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;plugin id="org.apache.hadoop.zookeeper"/&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;plugin id="org.apache.log4j"/&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;plugin id="org.eclipse.core.contenttype"/&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;plugin id="org.eclipse.core.jobs"/&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;plugin id="org.eclipse.core.runtime"/&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;plugin id="org.eclipse.core.runtime.compatibility.registry" fragment="true"/&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;plugin id="org.eclipse.ecf"/&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;plugin id="org.eclipse.ecf.discovery"/&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;plugin id="org.eclipse.ecf.identity"/&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;plugin id="org.eclipse.ecf.osgi.services.distribution"/&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;plugin id="org.eclipse.ecf.osgi.services.remoteserviceadmin"/&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;plugin id="org.eclipse.ecf.osgi.services.remoteserviceadmin.proxy"/&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;plugin id="org.eclipse.ecf.provider"/&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;plugin id="org.eclipse.ecf.provider.remoteservice"/&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;plugin id="org.eclipse.ecf.provider.zookeeper"/&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;plugin id="org.eclipse.ecf.remoteservice"/&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;plugin id="org.eclipse.ecf.sharedobject"/&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;plugin id="org.eclipse.ecf.ssl" fragment="true"/&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;plugin id="org.eclipse.equinox.app"/&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;plugin id="org.eclipse.equinox.common"/&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;plugin id="org.eclipse.equinox.concurrent"/&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;plugin id="org.eclipse.equinox.ds"/&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;plugin id="org.eclipse.equinox.preferences"/&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;plugin id="org.eclipse.equinox.registry"/&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;plugin id="org.eclipse.equinox.util"/&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;plugin id="org.eclipse.equinox.weaving.hook" fragment="true"/&amp;gt;&lt;br /&gt;    &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;plugin id="org.eclipse.osgi"/&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;plugin id="org.eclipse.osgi.services"/&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;plugin id="org.eclipse.osgi.services.remoteserviceadmin"/&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;plugin id="org.eclipse.persistence.jpa.equinox.weaving" fragment="true"/&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;lt;/plugins&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: 'Courier New';"&gt;&amp;lt;/product&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;pre&gt;&lt;span style="font-family: Arial;"&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;&lt;span style="font-family: Arial;"&gt;Client - &lt;strong&gt;helloconsumerzookeeper.product&lt;/strong&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;span style="font-family: 'Courier New';"&gt;&amp;lt;?xml version="1.0" encoding="UTF-8"?&amp;gt;&lt;br /&gt;&amp;lt;?pde version="3.5"?&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: 'Courier New';"&gt;&amp;lt;product application="it.eng.test.remote.ds.helloconsumer.HelloConsumerTest" useFeatures="false" includeLaunchers="true"&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: 'Courier New';"&gt;&amp;nbsp;&amp;nbsp; &amp;lt;configIni use="default"&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;lt;/configIni&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: 'Courier New';"&gt;&amp;nbsp;&amp;nbsp; &amp;lt;launcherArgs&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;programArgs&amp;gt;-consoleLog -console -clean&amp;lt;/programArgs&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;vmArgs&amp;gt;-Declipse.ignoreApp=true -Dosgi.noShutdown=true -Dzoodiscovery.autoStart=true; -Dzoodiscovery.flavor=zoodiscovery.flavor.standalone=192.168.23.28:3031;clientPort=3030&amp;lt;/vmArgs&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;vmArgsMac&amp;gt;-XstartOnFirstThread -Dorg.eclipse.swt.internal.carbon.smallFonts&amp;lt;/vmArgsMac&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;lt;/launcherArgs&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: 'Courier New';"&gt;&amp;nbsp;&amp;nbsp; &amp;lt;launcher&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;solaris/&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;win useIco="false"&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;bmp/&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/win&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;lt;/launcher&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: 'Courier New';"&gt;&amp;nbsp;&amp;nbsp; &amp;lt;vm&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;lt;/vm&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: 'Courier New';"&gt;&amp;nbsp;&amp;nbsp; &amp;lt;plugins&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;plugin id="it.eng.test.remote.ds.hello"/&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;plugin id="it.eng.test.remote.ds.helloconsumer"/&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;plugin id="javax.transaction" fragment="true"/&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;plugin id="org.apache.hadoop.zookeeper"/&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;plugin id="org.apache.log4j"/&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;plugin id="org.eclipse.core.contenttype"/&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;plugin id="org.eclipse.core.jobs"/&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;plugin id="org.eclipse.core.runtime"/&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;plugin id="org.eclipse.core.runtime.compatibility.registry" fragment="true"/&amp;gt;&lt;br /&gt;    &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;plugin id="org.eclipse.ecf"/&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;plugin id="org.eclipse.ecf.discovery"/&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;plugin id="org.eclipse.ecf.identity"/&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;plugin id="org.eclipse.ecf.osgi.services.distribution"/&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;plugin id="org.eclipse.ecf.osgi.services.remoteserviceadmin"/&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;plugin id="org.eclipse.ecf.osgi.services.remoteserviceadmin.proxy"/&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;plugin id="org.eclipse.ecf.provider"/&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;plugin id="org.eclipse.ecf.provider.remoteservice"/&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;plugin id="org.eclipse.ecf.provider.zookeeper"/&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;plugin id="org.eclipse.ecf.remoteservice"/&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;plugin id="org.eclipse.ecf.sharedobject"/&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;plugin id="org.eclipse.ecf.ssl" fragment="true"/&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;plugin id="org.eclipse.equinox.app"/&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;plugin id="org.eclipse.equinox.common"/&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;plugin id="org.eclipse.equinox.concurrent"/&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;plugin id="org.eclipse.equinox.ds"/&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;plugin id="org.eclipse.equinox.preferences"/&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;plugin id="org.eclipse.equinox.registry"/&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;plugin id="org.eclipse.equinox.util"/&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;plugin id="org.eclipse.equinox.weaving.hook" fragment="true"/&amp;gt;&lt;br /&gt;    &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;plugin id="org.eclipse.osgi"/&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;plugin id="org.eclipse.osgi.services"/&amp;gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;lt;plugin id="org.eclipse.osgi.services.remoteserviceadmin"/&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;plugin id="org.eclipse.persistence.jpa.equinox.weaving" fragment="true"/&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;lt;/plugins&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: 'Courier New';"&gt;&amp;lt;/product&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;pre&gt;&lt;span style="font-family: Arial;"&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;&lt;span style="font-family: Arial;"&gt;After exporting the applications as &lt;em&gt;Eclipse products&lt;/em&gt; we are left with two folders with an executable file in them. Do not even bother to try to run it as id will not work, instead open a terminal and browse to the &lt;em&gt;exported_application_folder/plugins&lt;/em&gt; folder; here you will find all the required OSGi plug-ins for your application. You can run the service by typing:&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;java -Dzoodiscovery.dataDir=bla -Dzoodiscovery.flavor=zoodiscovery.flavor.standalone=192.168.23.28:3030;clientPort=3031 -jar org.eclipse.osgi.jar -configuration ../configuration -console&lt;/pre&gt;
&lt;pre&gt;&lt;span style="font-family: Arial;"&gt;and the client with:&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;java -Dzoodiscovery.autoStart=true; -Dzoodiscovery.flavor=zoodiscovery.flavor.standalone=192.168.23.28:3031;clientPort=3030 -jar org.eclipse.osgi.jar -configuration ../configuration -console&lt;/pre&gt;
&lt;pre&gt;&lt;span style="font-family: Arial;"&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;&lt;span style="font-family: Arial;"&gt;Now if you start your bundles inside their respective frameworks, you should see, along ZooKeeper's infos, "Got proxy IHello=OSGi_PROXY_NAME" and "Greetings PROXY_NAME". You can download the already exported and ready-to-go &lt;a href="https://skydrive.live.com/redir.aspx?cid=19468fe08387b566&amp;amp;resid=19468FE08387B566!15309&amp;amp;parid=19468FE08387B566!3289&amp;amp;authkey=!AP58M-Mg-mhpC3Q"&gt;service and client applications here&lt;/a&gt;.&lt;/span&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1859167416855250911-2596136720044455760?l=groglogs.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/Hs_FLMHFGzQgbPpnO__6R5LqvjY/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/Hs_FLMHFGzQgbPpnO__6R5LqvjY/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/Hs_FLMHFGzQgbPpnO__6R5LqvjY/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/Hs_FLMHFGzQgbPpnO__6R5LqvjY/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;</description><link>http://feedproxy.google.com/~r/groglogs/~3/DcNvXbHBYMc/ecf-remote-osgi-ds-declarative-services.html</link><author>noreply@blogger.com (Stefano Ghio)</author><thr:total>0</thr:total><feedburner:origLink>http://groglogs.blogspot.com/2012/02/ecf-remote-osgi-ds-declarative-services.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1859167416855250911.post-9085522264475983813</guid><pubDate>Tue, 31 Jan 2012 15:24:00 +0000</pubDate><atom:updated>2012-01-31T16:27:40.428+01:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">HowTo</category><category domain="http://www.blogger.com/atom/ns#">Source code</category><title>r-OSGi remote OSGi example</title><description>&lt;pre&gt;&lt;span style="font-family: Arial;"&gt;In this post we will give a fair example of the workings of the &lt;a href="http://www.vogella.de/articles/OSGi/article.html"&gt;OSGi services&lt;/a&gt; remoted through &lt;a href="http://r-osgi.sourceforge.net/"&gt;r-OSGi&lt;/a&gt;.&lt;/span&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;&lt;span style="font-family: Arial;"&gt;In order for the example to work, we must have an OSGi framework with the r-OSGi extension. Also, make sure the 9278 port on your system is free as r-OSGi uses it for its purposes.&lt;/span&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;a name='more'&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;
&lt;pre&gt;&lt;span style="font-family: Arial;"&gt;Suppose we have a remotable service: HelloService, its interface: IHello and a client who declares a dependency on the service by pointing to its interfaces. It would also like to be able to access it remotely.&lt;/span&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;pre&gt;&lt;span style="font-family: Arial;"&gt;When a component declares it provides a service, the OSGi framework stores that information in its internal registry.&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style="font-family: Arial;"&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;&lt;span style="font-family: Arial;"&gt;&lt;a href="http://digilander.libero.it/otacoconvention/source/osgi/rosgi.zip"&gt;Download here the example's source code&lt;/a&gt;&lt;/span&gt;&lt;span style="font-family: Arial;"&gt;. You should be able to import everything inside Eclipse as-is. Inside you will find:&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style="font-family: Arial;"&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;&lt;span style="font-family: Arial;"&gt;Interface - &lt;strong&gt;IHello.java&lt;/strong&gt;:&lt;/span&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;span style="font-family: 'Courier New';"&gt;package it.eng.test.remote.hello;&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: 'Courier New';"&gt;public interface IHello {&amp;nbsp; &amp;nbsp;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public String sayHello(String from);&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: 'Courier New';"&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;&lt;pre&gt;&lt;span style="font-family: Arial;"&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;span style="font-family: Arial;"&gt;Implementation - &lt;strong&gt;HelloService.java&lt;/strong&gt;:&lt;/span&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;span style="font-family: 'Courier New';"&gt;package it.eng.test.remote.helloservice;&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: 'Courier New';"&gt;import it.eng.test.remote.hello.IHello;&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: 'Courier New';"&gt;public class HelloService implements IHello{&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: 'Courier New';"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public String sayHello(String from){&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return "Hello from "+from;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;pre&gt;&lt;span style="font-family: Arial;"&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;&lt;span style="font-family: Arial;"&gt;As we can see, the service offers a single, simple method which returns a String.&lt;/span&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;pre&gt;&lt;span style="font-family: Arial;"&gt;The service also uses a &lt;em&gt;BundleActivator&lt;/em&gt; to register the service as remotable on the framework:&lt;/span&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;span style="font-family: 'Courier New';"&gt;package it.eng.test.remote.helloservice;&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: 'Courier New';"&gt;import it.eng.test.remote.hello.IHello;&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: 'Courier New';"&gt;import java.util.Hashtable;&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: 'Courier New';"&gt;import org.osgi.framework.BundleActivator;&lt;br /&gt;import org.osgi.framework.BundleContext;&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: 'Courier New';"&gt;import ch.ethz.iks.r_osgi.RemoteOSGiService;&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: 'Courier New';"&gt;public class Activator implements BundleActivator {&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: 'Courier New';"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; private BundleContext context;&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: 'Courier New';"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public BundleContext getContext() {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return context;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; @SuppressWarnings({ "rawtypes", "unchecked" })&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public void start(final BundleContext context) throws Exception {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; final Hashtable properties = new Hashtable();&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; properties.put(RemoteOSGiService.R_OSGi_REGISTRATION, Boolean.TRUE);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; context.registerService(IHello.class.getName(), new HelloService(), properties);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; System.out.println("Service registered.");&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&amp;nbsp; &amp;nbsp;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public void stop(BundleContext bundleContext) throws Exception {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; context = null;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: 'Courier New';"&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;pre&gt;&lt;span style="font-family: Arial;"&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;&lt;span style="font-family: Arial;"&gt;The client is, for simplicity only, composed just by the &lt;em&gt;BundleActivator&lt;/em&gt;. When started it connects to the remote framework through its r-OSGi component to browse the available services and connect to the one it is interested in.&lt;/span&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;span style="font-family: 'Courier New';"&gt;package it.eng.test.remote.helloconsumer;&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: 'Courier New';"&gt;import it.eng.test.remote.hello.IHello;&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: 'Courier New';"&gt;import org.osgi.framework.BundleActivator;&lt;br /&gt;import org.osgi.framework.BundleContext;&lt;br /&gt;import org.osgi.framework.ServiceReference;&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: 'Courier New';"&gt;import ch.ethz.iks.r_osgi.RemoteOSGiService;&lt;br /&gt;import ch.ethz.iks.r_osgi.RemoteServiceReference;&lt;br /&gt;import ch.ethz.iks.r_osgi.URI;&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: 'Courier New';"&gt;public class Activator implements BundleActivator {&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: 'Courier New';"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; private BundleContext context;&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: 'Courier New';"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public BundleContext getContext() {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return context;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public void start(final BundleContext context) throws Exception {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; final ServiceReference serviceRef = context.getServiceReference(RemoteOSGiService.class.getName());&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (serviceRef == null) {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; System.out.println("R-OSGi service not found!");&lt;br /&gt;    &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; } else {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; final RemoteOSGiService remote = (RemoteOSGiService) context.getService(serviceRef);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; try {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; remote.connect(new URI("r-osgi://192.168.23.96:9278"));&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: 'Courier New';"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; final RemoteServiceReference[] references = remote.getRemoteServiceReferences(&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; new URI("r-osgi://192.168.23.96:9278"), IHello.class.getName(), null);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (references == null) {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; System.out.println("Service not found!");&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; } else {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; final IHello hello = (IHello) remote.getRemoteService(references[0]);&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; System.out.println(hello.sayHello(System.getProperty("os.name")));&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; } finally {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; context.ungetService(serviceRef);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public void stop(BundleContext bundleContext) throws Exception {&lt;br /&gt;    &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; context = null;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: 'Courier New';"&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;&lt;span style="font-family: Arial;"&gt;The consumer firstly checks for the r-OSGi component presence, then uses it to connect to another r-OSGi enabled framework located at the address hardcoded in the Activator itself.&lt;/span&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;&lt;span style="font-family: Arial;"&gt;After the connection is established, he browses the remote framework's services to find the &lt;em&gt;IHello&lt;/em&gt; implementation; if it is there, he attaches to it and prints "Hello from OS\_NAME" on standard output before unbinding from the service.&lt;/span&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1859167416855250911-9085522264475983813?l=groglogs.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/CGW7FvsknKWZQGZqnCv261zRxIM/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/CGW7FvsknKWZQGZqnCv261zRxIM/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/CGW7FvsknKWZQGZqnCv261zRxIM/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/CGW7FvsknKWZQGZqnCv261zRxIM/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;</description><link>http://feedproxy.google.com/~r/groglogs/~3/hiCSmvBDn0s/r-osgi-remote-osgi-example.html</link><author>noreply@blogger.com (Stefano Ghio)</author><thr:total>0</thr:total><feedburner:origLink>http://groglogs.blogspot.com/2012/01/r-osgi-remote-osgi-example.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1859167416855250911.post-897553157721109064</guid><pubDate>Tue, 31 Jan 2012 14:38:00 +0000</pubDate><atom:updated>2012-01-31T16:29:57.929+01:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">HowTo</category><category domain="http://www.blogger.com/atom/ns#">Source code</category><title>DOSGi DS Distributed OSGi Declarative Services example</title><description>&lt;pre&gt;&lt;span style="font-family: arial;"&gt;In this post we will give a fair example of the workings of the &lt;a href="http://groglogs.blogspot.com/2012/01/osgi-ds-declarative-services-example.html"&gt;OSGi DS Declarative Services&lt;/a&gt; remoted with &lt;a href="http://cxf.apache.org/dosgi-releases.html"&gt;DOSGi&lt;/a&gt;.&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style="font-family: arial;"&gt;
&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style="font-family: arial;"&gt;We can use either one of the following frameworks:&lt;/span&gt;&lt;/pre&gt;
&lt;ul&gt;
&lt;li&gt;&lt;span style="font-family: Arial;"&gt;&lt;a href="http://camel.apache.org/using-osgi-blueprint-with-camel.html"&gt;Apache Camel&lt;/a&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style="font-family: Arial;"&gt;&lt;a href="http://aries.apache.org/modules/blueprint.html"&gt;Apache Aries&lt;/a&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style="font-family: Arial;"&gt;&lt;a href="http://cxf.apache.org/download.html"&gt;Apache CXF&lt;/a&gt;&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;pre&gt;&lt;span style="font-family: arial;"&gt;and the &lt;/span&gt;&lt;a href="http://www.eclipse.org/downloads/"&gt;&lt;span style="font-family: arial;"&gt;Eclipse IDE&lt;/span&gt;&lt;/a&gt;&lt;span style="font-family: arial;"&gt; (for Java). The code can be launched either inside Eclipse or from a standalone OSGi framework.&lt;/span&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;&lt;span style="font-family: arial;"&gt;&lt;a name='more'&gt;&lt;/a&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;&lt;span style="font-family: arial;"&gt;&lt;strong&gt;NOTE:&lt;/strong&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;pre&gt;&lt;span style="font-family: Arial;"&gt;Using DS with DOSGi requires the developer to use the "old school" &lt;em&gt;BundleActivator&lt;/em&gt; else, even if programming following the DS specification, it will not be possible to attach to the desired service due to a &lt;a href="https://issues.apache.org/jira/browse/DOSGI-73?page=com.atlassian.jira.plugin.system.issuetabpanels\%3Aall-tabpanel\#issue-tabs"&gt;bug&lt;/a&gt; currently not fixed yet, which prevents the target framework to register the proxy service on demand.&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style="font-family: arial;"&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;&lt;span style="font-family: arial;"&gt;Interfaces, implementations and clients should all reside in their own package, meaning you should create a new &lt;strong&gt;Plug-in project&lt;/strong&gt;, without &lt;em&gt;template&lt;/em&gt;&lt;strong&gt; &lt;/strong&gt;inside Eclipse (with the &lt;a href="http://wiki.eclipse.org/index.php/Rich_Client_Platform"&gt;RCP Plug-in developer resources plugin&lt;/a&gt; installed) for each of them.&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style="font-family: arial;"&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;&lt;span style="font-family: arial;"&gt;Suppose we have a service: &lt;i&gt;HelloService&lt;/i&gt;, its interface: &lt;i&gt;IHello&lt;/i&gt; and a client: &lt;i&gt;HelloCunsomer&lt;/i&gt; who declares a dependency on the service by pointing to its interfaces using the DS method.&lt;/span&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;&lt;span style="font-family: arial;"&gt;When a component declares it provides a service, the OSGi framework stores that information in its internal registry.&lt;/span&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;&lt;span style="font-family: arial;"&gt;&lt;a href="http://digilander.libero.it/otacoconvention/source/osgi/dosgi_ds.zip"&gt;Download here the example's source code&lt;/a&gt;&lt;/span&gt;&lt;span style="font-family: arial;"&gt;. You should be able to import everything inside Eclipse as-is. Inside you will find:&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;ul&gt;
&lt;li&gt;&lt;span style="font-family: arial;"&gt;Interface – &lt;b&gt;IHello.java&lt;/b&gt;&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/pre&gt;
&lt;span style="font-family: 'Courier New';"&gt;package it.eng.test.dosgi.hello;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-family: 'Courier New';"&gt;public interface IHello {&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-family: 'Courier New';"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public String sayHello(String from);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;pre&gt;&lt;ul&gt;
&lt;li&gt;&lt;span style="font-family: arial;"&gt;Implementation – &lt;b&gt;HelloService.java&lt;/b&gt;&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/pre&gt;
&lt;br /&gt;
&lt;span style="font-family: 'Courier New';"&gt;package it.eng.test.dosgi.helloservice;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-family: 'Courier New';"&gt;import it.eng.test.dosgi.hello.IHello;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-family: 'Courier New';"&gt;public class HelloService implements IHello{&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-family: 'Courier New';"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public String sayHello(String from){&lt;br /&gt;    &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; System.out.println("REMOTE CALL");&lt;br /&gt;    &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return "Hello from "+from;&lt;br /&gt;    &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&amp;nbsp; &lt;br /&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;    &lt;/b&gt;&lt;span style="font-family: arial;"&gt;If you inspect it, you will see that the it offer a single, simple method which returns a String.&lt;/span&gt;&lt;br /&gt;
&lt;pre&gt;&lt;ul&gt;
&lt;li&gt;&lt;span style="font-family: arial;"&gt;Client – &lt;b&gt;HelloConsumer.java&lt;/b&gt;&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/pre&gt;
&lt;br /&gt;
&lt;span style="font-family: 'Courier New';"&gt;package it.eng.test.dosgi.helloconsumer;&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: 'Courier New';"&gt;import org.osgi.service.component.ComponentContext;&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: 'Courier New';"&gt;import it.eng.test.dosgi.hello.IHello;&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: 'Courier New';"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: 'Courier New';"&gt;public class HelloConsumer {&amp;nbsp; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; private IHello hello;&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: 'Courier New';"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: 'Courier New';"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public void bindHello(IHello h) {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; hello = h;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; System.out.println("binded");&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: 'Courier New';"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: 'Courier New';"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public void unbindHello(IHello h) {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; hello = null;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; System.out.println("unbinded");&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-family: 'Courier New';"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public void start(ComponentContext bc) {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; System.out.println("started");&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;System.out.println(hello.sayHello(System.getProperty("os.name")));&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-family: Arial;"&gt;The consumer declares the dependency on the service by requiring its interface and has some methods of his own:&lt;/span&gt;&lt;br /&gt;
&lt;ul&gt;&lt;br /&gt;
&lt;li&gt;&lt;span style="font-family: Arial;"&gt;&lt;em&gt;start&lt;/em&gt;: this method is called as soon as the component is started;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style="font-family: Arial;"&gt;&lt;em&gt;bind*&lt;/em&gt;: this method is called when the required *Service becomes available;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style="font-family: Arial;"&gt;&lt;em&gt;unbind*&lt;/em&gt;: this method is called when the required *Service becomes unavailable.&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;pre&gt;&lt;span style="font-family: Arial;"&gt;It also requires a &lt;em&gt;BundleActivator&lt;/em&gt;:&lt;/span&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;span style="font-family: 'Courier New';"&gt;package it.eng.test.dosgi.helloconsumer;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-family: 'Courier New';"&gt;import it.eng.test.dosgi.hello.IHello;&lt;br /&gt;import org.osgi.framework.BundleActivator;&lt;br /&gt;import org.osgi.framework.BundleContext;&lt;br /&gt;import org.osgi.util.tracker.ServiceTracker;&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: 'Courier New';"&gt;&lt;br /&gt;public class Activator implements BundleActivator {&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; private ServiceTracker tracker;&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: 'Courier New';"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: 'Courier New';"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public void start(BundleContext context) throws Exception {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; tracker = new ServiceTracker(context, IHello.class.getName(), null);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; tracker.open();&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-family: 'Courier New';"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public void stop(BundleContext context) throws Exception {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; tracker.close();&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;pre&gt;&lt;span style="font-family: Arial;"&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;&lt;span style="font-family: Arial;"&gt;With the activator, the bundle declares a &lt;em&gt;ServiceTracker&lt;/em&gt; as a workaround for that bug.&lt;/span&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;pre&gt;&lt;span style="font-family: Arial;"&gt;The framework knows that &lt;em&gt;Consumer&lt;/em&gt; needs that particular service since he declared it in his XML configuration which must be put under the &lt;em&gt;OSGI-INF/&lt;/em&gt; folder:&lt;/span&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;span style="font-family: Arial;"&gt;&amp;lt;?xml version="1.0" encoding="UTF-8"?&amp;gt;&lt;br /&gt;&amp;lt;scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" activate="start" name="it.eng.test.dosgi.helloconsumer"&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;lt;implementation class="it.eng.test.dosgi.helloconsumer.HelloConsumer"/&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;lt;reference bind="bindHello" cardinality="1..1" interface="it.eng.test.dosgi.hello.IHello" name="IHello" policy="static" unbind="unbindHello"/&amp;gt;&lt;br /&gt;&amp;lt;/scr:component&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;&lt;span style="font-family: Arial;"&gt;Here the bundle is saying that the class &lt;em&gt;it.eng.test.dosgi.helloconsumer.HelloConsumer&lt;/em&gt; statically and necessarily depends on one of the possible &lt;em&gt;it.eng.test.dosgi.hello.IHello&lt;/em&gt; interface implementations and that when one of them becomes available or unavailable inside the framework, its &lt;em&gt;bindHello&lt;/em&gt; or &lt;em&gt;unbindHello&lt;/em&gt; method should be called.&lt;/span&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;&lt;span style="font-family: Arial;"&gt;The &lt;em&gt;static&lt;/em&gt; &lt;strong&gt;policy&lt;/strong&gt; attribute means that the DS is required to deactivate the component and create a new instance each time the required service changes; the alternative would be &lt;strong&gt;dynamic&lt;/strong&gt; which means that the bundle is able to work properly even when the services are dynamically switched.&lt;/span&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;&lt;span style="font-family: Arial;"&gt;The dependency is mandatory since the &lt;strong&gt;cardinality&lt;/strong&gt; was set to &lt;em&gt;1..1&lt;/em&gt;, meaning the component cannot be started until that particular dependency is currently available, contrarily to &lt;em&gt;0..1&lt;/em&gt; which means instead that it is optional. Another alternative would be 0..N, which would require the DS to invoke the associated method multiple times, one for each service instance currently available in the registry.&lt;/span&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;&lt;span style="font-family: Arial;"&gt;Furthermore, the name of the &lt;em&gt;bind*&lt;/em&gt; and &lt;em&gt;unbind*&lt;/em&gt; methods can be changed as pleased as long as it reflects the ones written in the java code.&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style="font-family: Arial;"&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;&lt;span style="font-family: Arial;"&gt;Additionally, the client must specify an additional configuration indicating to the framework where to look for remote services; this XML must be put under the &lt;em&gt;OSGI-INF/remote-service&lt;/em&gt; folder and must be compiled for every host to connect to:&lt;/span&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;span style="font-family: 'Courier New';"&gt;&amp;lt;endpoint-descriptions xmlns="http://www.osgi.org/xmlns/rsa/v1.0.0"&amp;gt;&lt;br /&gt;&amp;nbsp; &amp;lt;endpoint-description&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;property name="objectClass"&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;array&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;value&amp;gt;it.eng.test.dosgi.hello.IHello&amp;lt;/value&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/array&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/property&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;property name="endpoint.id"&amp;gt;http://localhost:9091/hello&amp;lt;/property&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;property name="service.imported.configs"&amp;gt;org.apache.cxf.ws&amp;lt;/property&amp;gt;&lt;br /&gt;&amp;nbsp; &amp;lt;/endpoint-description&amp;gt;&lt;br /&gt;&amp;lt;/endpoint-descriptions&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;pre&gt;&lt;span style="font-family: Arial;"&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;&lt;span style="font-family: Arial;"&gt;On its side, the service must declare its own XML configurations, listing the interface implementations offered, the classes implementing them, and a series of parameters used to make the service remotable.&lt;/span&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-family: 'Courier New';"&gt;&amp;lt;?xml version="1.0" encoding="UTF-8"?&amp;gt;&lt;br /&gt;&amp;lt;scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" name="it.eng.test.dosgi.helloservice"&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;lt;implementation class="it.eng.test.dosgi.helloservice.HelloService"/&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;lt;property name="service.exported.interfaces" value="*" /&amp;gt;&lt;br /&gt;&amp;nbsp; &amp;lt;property name="service.exported.configs" value="org.apache.cxf.ws" /&amp;gt;&lt;br /&gt;&amp;nbsp; &amp;lt;property name="org.apache.cxf.ws.address" value="http://localhost:9091/hello" /&amp;gt;&lt;br /&gt;    &amp;nbsp; &amp;lt;service&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;provide interface="it.eng.test.dosgi.hello.IHello"/&amp;gt;&lt;br /&gt;&amp;nbsp; &amp;lt;/service&amp;gt;&lt;br /&gt;&amp;lt;/scr:component&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;pre&gt;&lt;span style="font-family: Arial;"&gt;  &lt;/span&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;&lt;span style="font-family: Arial;"&gt;This line indicates that all methods described in the service interface are to be made remotable:&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style="font-family: Arial;"&gt;
&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&amp;lt;property name="service.exported.interfaces" value="*" /&amp;gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;&lt;span style="font-family: Arial;"&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;&lt;span style="font-family: Arial;"&gt;This value is linked to the OSGi framework implementation we used (Apache CXF) and indicates that the service should be exposed as a Web Service:&lt;/span&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;pre&gt;  &amp;lt;property name="service.exported.configs" value="org.apache.cxf.ws" /&amp;gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;pre&gt;&lt;span style="font-family: Arial;"&gt;located here:&lt;/span&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;pre&gt;  &amp;lt;property name="org.apache.cxf.ws.address" value="http://localhost:9091/hello" /&amp;gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style="font-family: Arial;"&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;&lt;span style="font-family: arial;"&gt;When we export our projects as &lt;strong&gt;Deployable plug-ins and fragment&lt;/strong&gt; and install all the resulting bundles inside the same OSGi framework and start them, we see that &lt;i&gt;Consumer&lt;/i&gt; prints on the standard output the string "started" right after it is starts and then, alternatively depending on their service implementation bundle's state, the strings: "binded" and "unbinded" plus "Hello from OS\_NAME".&lt;/span&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1859167416855250911-897553157721109064?l=groglogs.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/1mvRPlyz1WsZW0wwWiYzRkv-0pE/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/1mvRPlyz1WsZW0wwWiYzRkv-0pE/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/1mvRPlyz1WsZW0wwWiYzRkv-0pE/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/1mvRPlyz1WsZW0wwWiYzRkv-0pE/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;</description><link>http://feedproxy.google.com/~r/groglogs/~3/qZoFrab-q4g/dosgi-ds-declarative-services-example.html</link><author>noreply@blogger.com (Stefano Ghio)</author><thr:total>0</thr:total><feedburner:origLink>http://groglogs.blogspot.com/2012/01/dosgi-ds-declarative-services-example.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1859167416855250911.post-6113636319712249047</guid><pubDate>Mon, 30 Jan 2012 19:28:00 +0000</pubDate><atom:updated>2012-01-30T20:28:32.657+01:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">HowTo</category><category domain="http://www.blogger.com/atom/ns#">Source code</category><title>OSGi Blueprint Services example</title><description>&lt;pre&gt;&lt;span style="font-family: arial"&gt;In this post we will give a fair example of the workings of the &lt;a href="http://www.ibm.com/developerworks/opensource/library/os-osgiblueprint/"&gt;OSGi Blueprint Services&lt;/a&gt;&lt;/span&gt;&lt;span style="font-family: arial"&gt;.&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span style="font-family: arial"&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span style="font-family: arial"&gt;We can use either one of the following frameworks:&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;ul&gt;&lt;br /&gt;&lt;li&gt;&lt;a href="http://www.eclipse.org/gemini/blueprint/"&gt;&lt;font face="Arial"&gt;Eclipse Gemini&lt;/font&gt;&lt;/a&gt;&lt;font face="Arial"&gt; &lt;/font&gt;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;&lt;font face="Arial"&gt;&lt;a href="http://camel.apache.org/using-osgi-blueprint-with-camel.html"&gt;Apache Camel&lt;/a&gt;&lt;/font&gt;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;&lt;font face="Arial"&gt;&lt;a href="http://aries.apache.org/modules/blueprint.html"&gt;Apache Aries&lt;/a&gt;&lt;/font&gt;&lt;/li&gt;&lt;/ul&gt;&lt;pre&gt;&lt;span style="font-family: arial"&gt;and the &lt;/span&gt;&lt;a href="http://www.eclipse.org/downloads/"&gt;&lt;span style="font-family: arial"&gt;Eclipse IDE&lt;/span&gt;&lt;/a&gt;&lt;span style="font-family: arial"&gt; (for Java). The code can be launched either inside Eclipse or from a standalone OSGi framework.&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span style="font-family: arial"&gt;&lt;a name='more'&gt;&lt;/a&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span style="font-family: arial"&gt;Interfaces, implementations and clients should all reside in their own package, meaning you should create a new &lt;strong&gt;Plug-in project&lt;/strong&gt;, without &lt;em&gt;Activator&lt;/em&gt; or &lt;em&gt;template&lt;/em&gt;&lt;strong&gt; &lt;/strong&gt;inside Eclipse (with the &lt;a href="http://wiki.eclipse.org/index.php/Rich_Client_Platform"&gt;RCP Plug-in developer resources plugin&lt;/a&gt; installed) for each of them.&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span style="font-family: arial"&gt;&lt;/span&gt; &lt;/pre&gt;&lt;pre&gt;&lt;span style="font-family: arial"&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span style="font-family: arial"&gt;Suppose we have a service: &lt;i&gt;HelloService&lt;/i&gt;, its interface: &lt;i&gt;IHello&lt;/i&gt; and a client: &lt;i&gt;HelloCunsomer&lt;/i&gt; who declares a &lt;a href="http://en.wikipedia.org/wiki/JavaBean"&gt;Java Bean&lt;/a&gt; dependency on the service by pointing to its interfaces using the Blueprint method.&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span style="font-family: arial"&gt;When a component declares it provides a service, the OSGi framework stores that information in its internal registry.&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span style="font-family: arial"&gt;&lt;a href="http://digilander.libero.it/otacoconvention/source/osgi/osgi_blueprint.zip"&gt;Download here the example's source code&lt;/a&gt;&lt;/span&gt;&lt;span style="font-family: arial"&gt;. You should be able to import everything inside Eclipse as-is. Inside you will find:&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;ul&gt;&lt;br&gt;&lt;li&gt;&lt;span style="font-family: arial"&gt;Interface – &lt;b&gt;IHello.java&lt;/b&gt;&lt;/span&gt;&lt;br&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/pre&gt;&lt;br /&gt;&lt;p&gt;&lt;font face="Courier New"&gt;package it.eng.test.blueprint.hello;&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;font face="Courier New"&gt;public interface IHello {&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public void sayHello();&lt;br&gt;}&lt;br&gt;&lt;/font&gt;&lt;/p&gt;&lt;pre&gt;&lt;ul&gt;&lt;br&gt;&lt;li&gt;&lt;span style="font-family: arial"&gt;Implementation – &lt;b&gt;HelloService.java&lt;/b&gt;&lt;/span&gt;&lt;br&gt;&lt;/li&gt;&lt;/ul&gt;&lt;br&gt;&lt;/pre&gt;&lt;br /&gt;&lt;p&gt;&lt;font face="Courier New"&gt;package it.eng.test.blueprint.helloservice;&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;font face="Courier New"&gt;import it.eng.test.blueprint.hello.IHello;&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;font face="Courier New"&gt;public class HelloService implements IHello{&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public void sayHello(){&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; System.out.println( "Hello World!" );&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br&gt;}&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;font face="Courier New"&gt;&lt;/font&gt;&lt;b&gt;&lt;br&gt;&lt;/b&gt;&lt;span style="font-family: arial"&gt;If you inspect it, you will see that the it offer a single, simple method which prints something on standard output.&lt;/span&gt;&lt;/p&gt;&lt;pre&gt;&lt;ul&gt;&lt;br&gt;&lt;li&gt;&lt;span style="font-family: arial"&gt;Client – &lt;b&gt;HelloConsumer.java&lt;/b&gt;&lt;/span&gt;&lt;br&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/pre&gt;&lt;br /&gt;&lt;p&gt;&lt;font face="Courier New"&gt;package it.eng.test.blueprint.consumer;&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;font face="Courier New"&gt;import it.eng.test.blueprint.hello.IHello;&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;font face="Courier New"&gt;public class HelloConsumer {&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; private IHello service;&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; // Bean properties&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public IHello getService() {&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return service;&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;font face="Courier New"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public void setService(IHello service) {&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; this.service = service;&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;font face="Courier New"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public void init() {&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; System.out.println("OSGi client started.");&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (service != null) {&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; System.out.println("Calling sayHello()");&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; service.sayHello();&amp;nbsp; // Invoke the OSGi service!&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br&gt;}&lt;/font&gt;&lt;b&gt;&lt;br&gt;&lt;/b&gt;&lt;br&gt;&lt;/p&gt;&lt;pre&gt;&lt;span style="font-family: arial"&gt;The consumer declares the bean dependency on the service by requiring its interface and has some methods of his own:&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;ul&gt;&lt;br&gt;&lt;br /&gt;&lt;li&gt;&lt;span style="font-family: arial"&gt;&lt;i&gt;init&lt;/i&gt;: this method is called as soon as the requested bean is injected inside the application;&lt;/span&gt;&lt;br /&gt;&lt;li&gt;&lt;span style="font-family: arial"&gt;&lt;i&gt;get*&lt;/i&gt;: this method is called this method is called to get the * property;&lt;/span&gt;&lt;br /&gt;&lt;li&gt;&lt;span style="font-family: arial"&gt;&lt;i&gt;set*&lt;/i&gt;: this method is called this method is called to set the * property;&lt;/span&gt;&lt;/li&gt;&lt;/ul&gt;&lt;pre&gt;&lt;br&gt;&lt;span style="font-family: arial"&gt;The framework knows that &lt;i&gt;Consumer&lt;/i&gt; needs that particular service since he declared it in his XML configuration which must be put under the &lt;em&gt;OSGI-INF/blueprint&lt;/em&gt; folder. As soon as the service becomes available it is injected as a bean inside the consumer:&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span style="font-family: arial"&gt;&lt;br&gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;p&gt;&lt;font face="Courier New"&gt;&amp;lt;?xml version="1.0" encoding="UTF-8"?&amp;gt;&lt;br&gt;&amp;lt;blueprint xmlns="&lt;/font&gt;&lt;font face="Courier New"&gt;http://www.osgi.org/xmlns/blueprint/v1.0.0"&lt;/font&gt;&lt;font face="Courier New"&gt;&amp;gt;&lt;br&gt;&amp;nbsp; &lt;br&gt;&amp;nbsp; &amp;lt;reference id="helloWorld"&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; interface="it.eng.test.blueprint.hello.IHello"/&amp;gt;&lt;br&gt;&amp;nbsp; &lt;br&gt;&amp;nbsp; &amp;lt;bean id="client"&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; class="it.eng.test.blueprint.consumer.HelloConsumer"&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; init-method="init"&amp;gt;&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;property name="service" ref="helloWorld"/&amp;gt;&lt;br&gt;&amp;nbsp; &amp;lt;/bean&amp;gt;&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;font face="Courier New"&gt;&amp;lt;/blueprint&amp;gt;&lt;/font&gt;&lt;/p&gt;&lt;pre&gt;&lt;br&gt;&lt;/pre&gt;&lt;pre&gt;&lt;/pre&gt;&lt;br /&gt;&lt;p&gt;&lt;font face="Arial"&gt;Here the bundle is saying that the interface &lt;em&gt;it.eng.test.blueprint.hello.IHello&lt;/em&gt; should be referenced as &lt;em&gt;helloWorld&lt;/em&gt; and declares a bean for that reference to be injected on the property &lt;em&gt;service&lt;/em&gt; of the &lt;em&gt;it.eng.test.blueprint.consumer.HelloConsumer&lt;/em&gt; class with the init initialization method.&lt;/font&gt;&lt;br /&gt;&lt;p&gt;&lt;font face="Arial"&gt;&lt;/font&gt;&amp;nbsp;&lt;pre&gt;&lt;font face="Arial"&gt;On its side, the service must declare its own XML configurations, listing the interface implementations offered through which beans.&lt;/font&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span style="font-family: arial"&gt;&lt;br&gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;p&gt;&lt;font face="Courier New"&gt;&amp;lt;?xml version="1.0" encoding="UTF-8"?&amp;gt;&lt;br&gt;&amp;lt;blueprint xmlns="&lt;/font&gt;&lt;font face="Courier New"&gt;http://www.osgi.org/xmlns/blueprint/v1.0.0"&lt;/font&gt;&lt;font face="Courier New"&gt;&amp;gt;&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;font face="Courier New"&gt;&amp;nbsp; &amp;lt;bean id="hello" class="it.eng.test.blueprint.helloservice.HelloService"/&amp;gt;&lt;br&gt;&amp;nbsp; &lt;br&gt;&amp;nbsp; &amp;lt;service ref="hello" interface="it.eng.test.blueprint.hello.IHello"/&amp;gt;&lt;/font&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;font face="Courier New"&gt;&amp;lt;/blueprint&amp;gt;&lt;/font&gt;&lt;/p&gt;&lt;pre&gt;&lt;br&gt;&lt;/pre&gt;&lt;pre&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span style="font-family: arial"&gt;When we export our projects as &lt;strong&gt;Deployable plug-ins and fragment&lt;/strong&gt; and install all the resulting bundles inside the same OSGi framework and start them, we see that &lt;i&gt;Consumer&lt;/i&gt; prints on the standard output the string "OSGi client started." right after it is starts and then, when the required bean becomes available and injected, "Calling sayHello()" then "Hello World!".&lt;/span&gt;&lt;/pre&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1859167416855250911-6113636319712249047?l=groglogs.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/2HU0wZQ1jcAwml8ZL44ia1GlERM/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/2HU0wZQ1jcAwml8ZL44ia1GlERM/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/2HU0wZQ1jcAwml8ZL44ia1GlERM/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/2HU0wZQ1jcAwml8ZL44ia1GlERM/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;</description><link>http://feedproxy.google.com/~r/groglogs/~3/IysKxiJ20Vc/osgi-blueprint-services-example.html</link><author>noreply@blogger.com (Stefano Ghio)</author><thr:total>0</thr:total><feedburner:origLink>http://groglogs.blogspot.com/2012/01/osgi-blueprint-services-example.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1859167416855250911.post-2512255157361317541</guid><pubDate>Fri, 27 Jan 2012 17:08:00 +0000</pubDate><atom:updated>2012-01-30T20:44:39.306+01:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">HowTo</category><category domain="http://www.blogger.com/atom/ns#">Source code</category><title>OSGi DS Declarative Services example</title><description>&lt;pre&gt;&lt;span style="font-family: arial;"&gt;In this post we will give a fair example of the workings of the &lt;/span&gt;&lt;a href="http://www.osgi.org/Download/File?url=/download/r4v42/r4.cmpn.pdf"&gt;&lt;span style="font-family: arial;"&gt;OSGi DS services&lt;/span&gt;&lt;/a&gt;&lt;span style="font-family: arial;"&gt;.&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style="font-family: arial;"&gt;
&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style="font-family: arial;"&gt;I suggest you read a good &lt;a href="http://www.vogella.de/articles/OSGi/article.html"&gt;OSGi tutorial by Lars Vogel&lt;/a&gt; before moving further if you are not much confident with the &lt;a href="http://en.wikipedia.org/wiki/Osgi"&gt;OSGi&lt;/a&gt; specification.&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style="font-family: arial;"&gt;
&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style="font-family: arial;"&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style="font-family: arial;"&gt;We are working with the &lt;/span&gt;&lt;a href="http://eclipse.org/equinox/"&gt;&lt;span style="font-family: arial;"&gt;Equinox&lt;/span&gt;&lt;/a&gt;&lt;span style="font-family: arial;"&gt; OSGi framework, which is part of the &lt;/span&gt;&lt;a href="http://www.eclipse.org/downloads/"&gt;&lt;span style="font-family: arial;"&gt;Eclipse IDE&lt;/span&gt;&lt;/a&gt;&lt;span style="font-family: arial;"&gt; (for Java). The code can be launched either inside Eclipse or from a standalone OSGi framework; for the latter option, grab the following &lt;i&gt;jar&lt;/i&gt; packages from under the &lt;i&gt;plugins/&lt;/i&gt; folder of our Eclipse installation:&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;ul&gt;
&lt;li&gt;&lt;i&gt;&lt;span style="font-family: arial;"&gt;org.eclipse.osgi&lt;/span&gt;&lt;/i&gt;&lt;/li&gt;
&lt;li&gt;&lt;i&gt;&lt;span style="font-family: arial;"&gt;org.eclipse.equinox.ds&lt;/span&gt;&lt;/i&gt;&lt;/li&gt;
&lt;li&gt;&lt;i&gt;&lt;span style="font-family: arial;"&gt;org.eclipse.equinox.util&lt;/span&gt;&lt;/i&gt;&lt;/li&gt;
&lt;li&gt;&lt;i&gt;&lt;span style="font-family: arial;"&gt;org.eclipse.osgi.services&lt;/span&gt;&lt;/i&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;span style="font-family: arial;"&gt;and copy them in a folder of your choice.&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style="font-family: arial;"&gt;&lt;a name='more'&gt;&lt;/a&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style="font-family: arial, helvetica, sans-serif;"&gt;No&lt;/span&gt;&lt;span style="font-family: arial;"&gt;w open a command prompt, browse to that folder and type:&lt;/span&gt;&lt;span style="font-family: arial;"&gt;
&lt;/span&gt;
java -jar org.eclipse.osgi.jar -console&lt;/pre&gt;
&lt;pre&gt;&lt;span style="font-family: arial;"&gt;
&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style="font-family: arial;"&gt;to make the OSGi prompt appear. From here you can issue a lot of commands to the OSGi framework, some of which are:&lt;/span&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;ul&gt;&lt;br /&gt;
&lt;li&gt;&lt;i&gt;&lt;span style="font-family: arial;"&gt;help&lt;/span&gt;&lt;/i&gt; &lt;/li&gt;
&lt;li&gt;&lt;span style="font-family: arial;"&gt;&lt;i&gt;ss&lt;/i&gt; - shows the current status of the installed bundles&lt;/span&gt; &lt;/li&gt;
&lt;li&gt;&lt;span style="font-family: arial;"&gt;&lt;i&gt;install file:&lt;/i&gt;&lt;/span&gt;&lt;span style="font-family: arial;"&gt;&lt;i&gt;path&lt;/i&gt; - installs the bundle available at the specified &lt;i&gt;path&lt;/i&gt;. It will be given an unique numeric ID&lt;/span&gt; &lt;/li&gt;
&lt;li&gt;&lt;i&gt;&lt;span style="font-family: arial;"&gt;uninstall ID&lt;/span&gt;&lt;/i&gt; &lt;/li&gt;
&lt;li&gt;&lt;i&gt;&lt;span style="font-family: arial;"&gt;start ID&lt;/span&gt;&lt;/i&gt; &lt;/li&gt;
&lt;li&gt;&lt;i&gt;&lt;span style="font-family: arial;"&gt;stop ID&lt;/span&gt;&lt;/i&gt; &lt;/li&gt;
&lt;li&gt;&lt;span style="font-family: arial;"&gt;&lt;i&gt;refresh&lt;/i&gt; - forces a framework refresh and update of the bundles state&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;pre&gt;&lt;span style="font-family: arial;"&gt;The bundles can be in only one of the following states at a time:&lt;/span&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;ul&gt;&lt;br /&gt;
&lt;li&gt;&lt;pre&gt;&lt;span style="font-family: arial;"&gt;&lt;b&gt;INSTALLED&lt;/b&gt;: the bundle has been successfully installed on the platform;&lt;/span&gt;&lt;/pre&gt;
&lt;/li&gt;
&lt;li&gt;&lt;pre&gt;&lt;span style="font-family: arial;"&gt;&lt;b&gt;RESOLVED&lt;/b&gt;: all of the bundle's dependencies are currently available, the bundle is ready to be started or it has just been stopped;&lt;/span&gt;&lt;/pre&gt;
&lt;/li&gt;
&lt;li&gt;&lt;pre&gt;&lt;span style="font-family: arial;"&gt;&lt;b&gt;STARTING&lt;/b&gt;: the bundle is starting, it is waiting for the method which takes care of the necessary start operations to return;&lt;/span&gt;&lt;/pre&gt;
&lt;/li&gt;
&lt;li&gt;&lt;pre&gt;&lt;span style="font-family: arial;"&gt;&lt;b&gt;ACTIVE&lt;/b&gt;: the bundle is up and running;&lt;/span&gt;&lt;/pre&gt;
&lt;/li&gt;
&lt;li&gt;&lt;span style="font-family: arial;"&gt;&lt;b&gt;STOPPING&lt;/b&gt;: the bundle is stopping, it is waiting for the method which takes care of the necessary stop operations to return.&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;pre&gt;&lt;span style="font-family: arial;"&gt;There exists an additional state, &lt;b&gt;UNINSTALLED&lt;/b&gt;, but it will never be shown by the framework.&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style="font-family: arial;"&gt;In order for the DS component to work properly, you must install and start all the bundles copied before (&lt;i&gt;org.eclipse.osgi &lt;/i&gt;excluded) inside the framework. &lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style="font-family: arial;"&gt;&lt;/span&gt;&amp;nbsp;&lt;/pre&gt;
&lt;pre&gt;&lt;span style="font-family: arial;"&gt;Now we can begin our example.&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style="font-family: arial;"&gt;&lt;/span&gt;&amp;nbsp;&lt;/pre&gt;
&lt;pre&gt;&lt;span style="font-family: arial;"&gt;Interfaces, implementations and clients should all reside in their own package, meaning you should create a new &lt;strong&gt;Plug-in project&lt;/strong&gt;, without &lt;em&gt;Activator&lt;/em&gt; or &lt;em&gt;template&lt;/em&gt;&lt;strong&gt; &lt;/strong&gt;inside Eclipse (with the &lt;a href="http://wiki.eclipse.org/index.php/Rich_Client_Platform"&gt;RCP Plug-in developer resources plugin&lt;/a&gt; installed) for each of them.&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style="font-family: arial;"&gt;&lt;/span&gt;&amp;nbsp;&lt;/pre&gt;
&lt;pre&gt;&lt;span style="font-family: arial;"&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style="font-family: arial;"&gt;Suppose we have two services: &lt;i&gt;HappyService&lt;/i&gt; and &lt;i&gt;SadService&lt;/i&gt;, their interfaces: &lt;i&gt;IHappy&lt;/i&gt; and &lt;i&gt;ISad&lt;/i&gt; and a client: &lt;i&gt;Customer&lt;/i&gt; who declares a dependency on the services by pointing to their interfaces using the DS method.&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style="font-family: arial;"&gt;When a component declares it provides a service, the OSGi framework stores that information in its internal registry.&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;a href="http://digilander.libero.it/otacoconvention/source/osgi/osgi_ds.zip"&gt;&lt;span style="font-family: arial;"&gt;Download here the example's source code&lt;/span&gt;&lt;/a&gt;&lt;span style="font-family: arial;"&gt;. You should be able to import everything inside Eclipse as-is. Inside you will find:&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;ul&gt;
&lt;li&gt;&lt;span style="font-family: arial;"&gt;Interface - &lt;b&gt;IHappy.java&lt;/b&gt;&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
package it.eng.test.ds.happy;

public interface IHappy {
 public void imHappy();
}&lt;ul&gt;
&lt;li&gt;&lt;span style="font-family: arial;"&gt;Interface - &lt;b&gt;ISad.java&lt;/b&gt;&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
package it.eng.test.ds.sad;

public interface ISad {
 public void imSad();
}&lt;ul&gt;
&lt;li&gt;&lt;span style="font-family: arial;"&gt;Implementation - &lt;b&gt;HappyService.java&lt;/b&gt;&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
package it.eng.test.ds.happyservice;

import it.eng.test.ds.happy.IHappy;

public class HappyService implements IHappy{
 public void imHappy(){
  System.out.println("I'm happy :)");
 }
}&lt;ul&gt;
&lt;li&gt;&lt;span style="font-family: arial;"&gt;Implementation - &lt;b&gt;SadService.java&lt;/b&gt;&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
package it.eng.test.ds.sadservice;

import it.eng.test.ds.sad.ISad;

public class SadService implements ISad{
 public void imSad(){
  System.out.println("I'm sad :(");
 }
}&lt;/pre&gt;
&lt;pre&gt;&lt;b&gt;
&lt;/b&gt;&lt;span style="font-family: arial;"&gt;If you inspect them, you will see that the two services offer a single, simple method which prints something on standard output.&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;ul&gt;
&lt;li&gt;&lt;span style="font-family: arial;"&gt;Client - &lt;b&gt;Consumer.java&lt;/b&gt;&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
package it.eng.test.ds.consumer;

import it.eng.test.ds.happy.IHappy;
import it.eng.test.ds.sad.ISad;

public class Consumer {
 private IHappy happy;
 private ISad sad;
 
 public synchronized void bindHappy(IHappy happy){
  this.happy = happy;
  happy.imHappy();
 }
 
 public synchronized void unbindHappy(IHappy happy){
  this.happy = null;
  sad.imSad();
 }
 
 public synchronized void bindSad(ISad sad){
  this.sad = sad;
  sad.imSad();
 }
 
 public synchronized void unbindSad(ISad sad){
  this.sad = null;
  happy.imHappy();
 }
 
 public void activate(){
  System.out.println("I'm here");
 }
 
}&lt;/pre&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;br /&gt;
&lt;pre&gt;&lt;span style="font-family: arial;"&gt;The consumer declares the dependency on the two services by requiring their interfaces and has some methods of his own:&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;ul&gt;
&lt;li&gt;&lt;span style="font-family: arial;"&gt;&lt;i&gt;activate&lt;/i&gt;: this method is called as soon as the client bundle is started;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style="font-family: arial;"&gt;&lt;i&gt;bind*&lt;/i&gt;: this method is called immediately after the required *Service becomes available on the framework;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style="font-family: arial;"&gt;&lt;i&gt;unbind*&lt;/i&gt;: this method is called immediately after the required *Service becomes unavailable on the framework.&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;span style="font-family: arial;"&gt;The framework knows that &lt;i&gt;Consumer&lt;/i&gt; needs those particular services since he declared it in his XML configuration which must be put under the &lt;i&gt;OSGI-INF/&lt;/i&gt; folder:&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style="font-family: arial;"&gt;
&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&amp;lt;?xml version="1.0" encoding="UTF-8"?&amp;gt;
&amp;lt;scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" name="it.eng.test.ds.consumer"&amp;gt;
   &amp;lt;implementation class="it.eng.test.ds.consumer.Consumer"/&amp;gt;
   &amp;lt;reference bind="bindHappy" cardinality="0..1" interface="it.eng.test.ds.happy.IHappy" name="IHappy" policy="dynamic" unbind="unbindHappy"/&amp;gt;
   &amp;lt;reference bind="bindSad" cardinality="0..1" interface="it.eng.test.ds.sad.ISad" name="ISad" policy="dynamic" unbind="unbindSad"/&amp;gt;
&amp;lt;/scr:component&amp;gt;&lt;/pre&gt;
&lt;pre&gt;
&lt;/pre&gt;
&lt;pre&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style="font-family: arial;"&gt;In there the bundle is saying that the class &lt;i&gt;it.eng.test.ds.consumer.Consumer&lt;/i&gt; dynamically and optionally depends on one of the possible &lt;i&gt;it.eng.test.ds.happy.IHappy&lt;/i&gt; interface implementations and that when one of them becomes available or unavailable inside the framework, its &lt;i&gt;bindHappy&lt;/i&gt; or &lt;i&gt;unbindHappy&lt;/i&gt; method should be called.&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style="font-family: arial;"&gt;
&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style="font-family: arial;"&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style="font-family: arial;"&gt;The &lt;i&gt;dynamically&lt;/i&gt; &lt;b&gt;policy&lt;/b&gt; attribute means that the bundle is able to work properly even when the services are dynamically switched; the alternative would be &lt;i&gt;static&lt;/i&gt;, which would require the DS to deactivate the component and create a new instance each time the required service changes.&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style="font-family: arial;"&gt;
&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style="font-family: arial;"&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style="font-family: arial;"&gt;The dependency is optional since the &lt;b&gt;cardinality&lt;/b&gt; was set to &lt;i&gt;0..1&lt;/i&gt;, meaning the component can be started even if that particular dependency is not currently available, contrarily to &lt;i&gt;1..1&lt;/i&gt; which means instead that it is mandatory. Another alternative would be &lt;i&gt;0..N&lt;/i&gt;, which would require the DS to invoke the associated method multiple times, one for each service instance currently available in the registry.&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style="font-family: arial;"&gt;
&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style="font-family: arial;"&gt;Furthermore, the name of the &lt;i&gt;bind*&lt;/i&gt; and &lt;i&gt;unbind*&lt;/i&gt; methods can be changed as pleased as long as it reflects the ones written in the java code.&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style="font-family: arial;"&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style="font-family: arial;"&gt;On their side, the two services must declare their own XML configurations, listing the interface implementations offered and the classes implementing them:&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style="font-family: arial;"&gt;
&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style="font-family: arial;"&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style="font-family: arial;"&gt;&lt;b&gt;HappyService XML&lt;/b&gt;:&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style="font-family: arial;"&gt;
&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&amp;lt;?xml version="1.0" encoding="UTF-8"?&amp;gt;
&amp;lt;scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" name="it.eng.test.ds.happyservice"&amp;gt;
   &amp;lt;implementation class="it.eng.test.ds.happyservice.HappyService"/&amp;gt;
   &amp;lt;service&amp;gt;
      &amp;lt;provide interface="it.eng.test.ds.happy.IHappy"/&amp;gt;
   &amp;lt;/service&amp;gt;
&amp;lt;/scr:component&amp;gt;&lt;/pre&gt;
&lt;pre&gt;
&lt;/pre&gt;
&lt;pre&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style="font-family: arial;"&gt;&lt;b&gt;SadService XML&lt;/b&gt;:&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style="font-family: arial;"&gt;
&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&amp;lt;?xml version="1.0" encoding="UTF-8"?&amp;gt;
&amp;lt;scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" name="it.eng.test.ds.sadservice"&amp;gt;
   &amp;lt;implementation class="it.eng.test.ds.sadservice.SadService"/&amp;gt;
   &amp;lt;service&amp;gt;
      &amp;lt;provide interface="it.eng.test.ds.sad.ISad"/&amp;gt;
   &amp;lt;/service&amp;gt;
&amp;lt;/scr:component&amp;gt;&lt;/pre&gt;
&lt;pre&gt;
&lt;/pre&gt;
&lt;pre&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style="font-family: arial;"&gt;When we export our projects as &lt;strong&gt;Deployable plug-ins and fragment&lt;/strong&gt; and install all the resulting bundles inside the same OSGi framework and start them, we see that &lt;i&gt;Consumer&lt;/i&gt; prints on the standard output the string "I'm here" right after it is starts and then, alternatively depending on their service implementation bundle's state, the strings: "I'm happy :)" and "I'm sad :(".&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1859167416855250911-2512255157361317541?l=groglogs.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/eXg8yOXyRFRliFI-Lxg2yZguX3A/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/eXg8yOXyRFRliFI-Lxg2yZguX3A/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/eXg8yOXyRFRliFI-Lxg2yZguX3A/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/eXg8yOXyRFRliFI-Lxg2yZguX3A/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;</description><link>http://feedproxy.google.com/~r/groglogs/~3/QRUq8Ljyu6g/osgi-ds-declarative-services-example.html</link><author>noreply@blogger.com (Stefano Ghio)</author><thr:total>0</thr:total><feedburner:origLink>http://groglogs.blogspot.com/2012/01/osgi-ds-declarative-services-example.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1859167416855250911.post-1416007736725604982</guid><pubDate>Sun, 15 Jan 2012 10:04:00 +0000</pubDate><atom:updated>2012-01-15T11:04:40.501+01:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Publications</category><title>Why beer is good for the brain</title><description>Well ya see, Norm, it's like this. A herd of buffalo can only move as fast as the slowest buffalo. And when the herd is hunted, it is the slowest and weakest ones at the back that are killed first.&lt;br /&gt;
This natural selection is good for the herd as a whole, because the general speed and health of the whole group keeps improving by the regular killing of the weakest members.&lt;br /&gt;
&lt;br /&gt;
In much the same way, the human brain can only operate as fast as the slowest brain cells. Excessive intake of alcohol, as we know, kills brain cells. But naturally, it attacks the slowest and weakest brain cells first. In this way, regular consumption of beer eliminates the weaker brain cells, making the brain a faster and more efficient machine.&lt;br /&gt;
That's why you always feel smarter after a few beers.&lt;br /&gt;
&lt;br /&gt;
&lt;div style="text-align: right;"&gt;
&lt;a href="http://www.imdb.com/title/tt0083399/quotes?qt=qt0461693"&gt;Cheers, 1982&lt;/a&gt;&lt;/div&gt;
&lt;div style="text-align: right;"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style="text-align: left;"&gt;
&lt;/div&gt;
&lt;a name='more'&gt;&lt;/a&gt;&lt;b&gt;ITALIANO:&lt;/b&gt;&lt;br /&gt;
&lt;div style="text-align: left;"&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div style="text-align: left;"&gt;
Beh vedi, Norm, funziona cosi'. Una mandria di bufali puo' muoversi al piu' velocemente come il bufalo piu' lento. E quando la mandria viene cacciata, sono i piu' lenti e deboli rimasti indietro ad essere uccisi per primi.&lt;/div&gt;
&lt;div style="text-align: left;"&gt;
Questa selezione naturale giova alla mandria stessa, perche' la salute e la velocita' generale di tutto il gruppo continua a migliorare grazie all'eliminazione costante dei membri piu' deboli.&lt;/div&gt;
&lt;div style="text-align: left;"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style="text-align: left;"&gt;
Quasi allo stesso modo, il cervello umano puo' operare al piu' velocemente come le piu' lente cellule cerebrali. Un'assunzione eccessiva di alcool, come sappiamo, uccide le cellule cerebrali. Ma naturalmente, attacca le piu' lente e deboli per prime. In questo modo, un'assunzione regolare di birra elimina le cellule cerebrali piu' deboli, rendendo il cervello una macchina piu' rapida ed efficiente.&lt;/div&gt;
&lt;div style="text-align: left;"&gt;
Ecco perche' ti senti sempre piu' furbo dopo un paio di birre.&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1859167416855250911-1416007736725604982?l=groglogs.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/etDoJtejQmxj3tWSWMv-tv0BpLU/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/etDoJtejQmxj3tWSWMv-tv0BpLU/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/etDoJtejQmxj3tWSWMv-tv0BpLU/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/etDoJtejQmxj3tWSWMv-tv0BpLU/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;</description><link>http://feedproxy.google.com/~r/groglogs/~3/MGUNE6mPo4Y/why-beer-is-good-for-brain.html</link><author>noreply@blogger.com (Stefano Ghio)</author><thr:total>0</thr:total><feedburner:origLink>http://groglogs.blogspot.com/2012/01/why-beer-is-good-for-brain.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1859167416855250911.post-6189979051565104234</guid><pubDate>Tue, 08 Nov 2011 17:46:00 +0000</pubDate><atom:updated>2011-11-08T18:46:53.238+01:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Music</category><title>[Sheet music] Take me home, country roads piano</title><description>This version is the one from the movie &lt;a href="http://www.imdb.com/title/tt0113824/"&gt;Whispers of the heart&lt;/a&gt; and it's based on the John Denver's original one.&lt;br /&gt;
&lt;br /&gt;
Questa versione e' del film &lt;a href="http://www.imdb.com/title/tt0113824/"&gt;Whispers of the heart&lt;/a&gt; ed e' basata sull'originale di John Denver.&lt;br /&gt;
&lt;br /&gt;
&lt;a href="http://digilander.libero.it/otacoconvention/sheet/mimi-o-sumaseba-country-roads.pdf"&gt;Scarica lo spartito/Download sheet music.&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1859167416855250911-6189979051565104234?l=groglogs.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/MRVSuHOZXblNKRuBKQnCEwcixcU/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/MRVSuHOZXblNKRuBKQnCEwcixcU/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/MRVSuHOZXblNKRuBKQnCEwcixcU/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/MRVSuHOZXblNKRuBKQnCEwcixcU/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;</description><link>http://feedproxy.google.com/~r/groglogs/~3/4vPapA8d5es/sheet-music-take-me-home-country-roads.html</link><author>noreply@blogger.com (Stefano Ghio)</author><thr:total>0</thr:total><feedburner:origLink>http://groglogs.blogspot.com/2011/11/sheet-music-take-me-home-country-roads.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1859167416855250911.post-7275467689068276862</guid><pubDate>Tue, 08 Nov 2011 17:42:00 +0000</pubDate><atom:updated>2011-11-08T18:42:46.189+01:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Music</category><title>[Sheet music] Starcraft Terran theme piano</title><description>&lt;a href="http://digilander.libero.it/otacoconvention/sheet/Starcraft%20-%20Terran%20Theme.pdf"&gt;Scarica lo spartito/Download sheet music.&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1859167416855250911-7275467689068276862?l=groglogs.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/kOvBKvdDQ6LmHJfIsbUrE4VYUGg/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/kOvBKvdDQ6LmHJfIsbUrE4VYUGg/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/kOvBKvdDQ6LmHJfIsbUrE4VYUGg/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/kOvBKvdDQ6LmHJfIsbUrE4VYUGg/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;</description><link>http://feedproxy.google.com/~r/groglogs/~3/s5Wd4WJchlI/sheet-music-starcraft-terran-theme.html</link><author>noreply@blogger.com (Stefano Ghio)</author><thr:total>0</thr:total><feedburner:origLink>http://groglogs.blogspot.com/2011/11/sheet-music-starcraft-terran-theme.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1859167416855250911.post-2572314860583208869</guid><pubDate>Tue, 08 Nov 2011 17:41:00 +0000</pubDate><atom:updated>2011-11-08T18:41:58.493+01:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Music</category><title>[Sheet music] Murder, she wrote piano theme - La signora in giallo</title><description>&lt;a href="http://digilander.libero.it/otacoconvention/sheet/Murder%20she%20wrote%20%28La%20Signora%20in%20Giallo%29.pdf"&gt;Scarica lo spartito/Download sheet music.&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1859167416855250911-2572314860583208869?l=groglogs.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/BvuS_D_uthH3VflL9e-kbpLy_uo/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/BvuS_D_uthH3VflL9e-kbpLy_uo/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/BvuS_D_uthH3VflL9e-kbpLy_uo/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/BvuS_D_uthH3VflL9e-kbpLy_uo/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;</description><link>http://feedproxy.google.com/~r/groglogs/~3/07jeaWQWTiM/sheet-music-murder-she-wrote-piano.html</link><author>noreply@blogger.com (Stefano Ghio)</author><thr:total>0</thr:total><feedburner:origLink>http://groglogs.blogspot.com/2011/11/sheet-music-murder-she-wrote-piano.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1859167416855250911.post-7317167047008795834</guid><pubDate>Tue, 27 Sep 2011 18:34:00 +0000</pubDate><atom:updated>2012-01-30T20:34:49.680+01:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Web</category><category domain="http://www.blogger.com/atom/ns#">HowTo</category><title>How to contact Facebook or delete your account</title><description>Contacting Facebook can really be a pain, but definitely deleting your account is even harder. Since they rely on your data to survive, they will hang on to it as long as possible.&lt;br /&gt;
&lt;br /&gt;
Luckily, &lt;a href="http://www.marismith.com/how-to-contact-facebook-a-directory-of-120-forms/"&gt;Mary Smith&lt;/a&gt; gathered all possible ways to contact Facebook and receive support. Feature requests, suggestions, bug reports and &lt;a href="https://www.facebook.com/help/contact.php?show_form=delete_account"&gt;account deletion&lt;/a&gt; can all be found there.&lt;br /&gt;
&lt;br /&gt;
You can even&lt;a href="https://www.facebook.com/help/contact.php?show_form=data_requests"&gt; request Facebook to send you a CD copy of all the data they have about you&lt;/a&gt; accordingly with your country's privacy laws.&lt;br /&gt;
&lt;br /&gt;
By the way, good luck at getting Facebook to reply to you, especially with the data request. If they don't answer, insist since they MUST satisfy your request within a limited time.&lt;br /&gt;
&lt;br /&gt;
UPDATE: An anonymous user pointed out that more information about that is available at&amp;nbsp;&lt;a href="http://www.webmarketing-conseil.fr/blog/1-derniers-articles-webmarketing/213-how-to-contact-facebook.html"&gt;&amp;nbsp;webmarketing-conseil&lt;/a&gt;.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1859167416855250911-7317167047008795834?l=groglogs.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/iktba6RA2lYX24b-QBGaNMxEty0/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/iktba6RA2lYX24b-QBGaNMxEty0/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/iktba6RA2lYX24b-QBGaNMxEty0/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/iktba6RA2lYX24b-QBGaNMxEty0/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;</description><link>http://feedproxy.google.com/~r/groglogs/~3/WqPXAnYy-SY/how-to-contact-facebook-or-delete-your.html</link><author>noreply@blogger.com (Stefano Ghio)</author><thr:total>2</thr:total><feedburner:origLink>http://groglogs.blogspot.com/2011/09/how-to-contact-facebook-or-delete-your.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1859167416855250911.post-4762571828675312740</guid><pubDate>Tue, 13 Sep 2011 14:34:00 +0000</pubDate><atom:updated>2011-09-17T23:36:35.080+02:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">HowTo</category><category domain="http://www.blogger.com/atom/ns#">Games</category><title>Legend of Dragoon fix disc 2 freeze after Lenus &amp; Regole battle</title><description>&lt;div style="text-align: justify;"&gt;
&lt;b&gt;ENGLISH&lt;/b&gt;: please refer to &lt;a href="http://www.supercheats.com/playstation/questions/thelegendofdragoon/55266/On-Disc-2-after-I-defeat-Lenus.htm"&gt;supercheats&lt;/a&gt;, quick summary: &lt;b&gt;beat the battle without ever going Dragoon&lt;/b&gt;&lt;br/&gt;&lt;br/&gt;&lt;/div&gt;
&lt;div style="text-align: justify;"&gt;
&lt;b&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div style="text-align: justify;"&gt;
&lt;b&gt;ITALIANO&lt;/b&gt;:&lt;/div&gt;
&lt;div style="text-align: justify;"&gt;
&lt;a href="http://en.wikipedia.org/wiki/The_Legend_of_Dragoon"&gt;The Legend of Dragoon&lt;/a&gt; é uno di quei giochi che non risentono dell’etá. Purtroppo, se si prova a giocarlo su una qualsiasi console che non sia la ormai rara PlayStation 1 (PS2, PS3, PSP o usando&amp;nbsp; l’emulatore PSX), per qualche motivo dopo la &lt;a href="http://www.youtube.com/watch?v=qXaN2smjneY"&gt;battaglia contro Lenus e Regole verso la fine del disco 2&lt;/a&gt;, lo schermo diventa nero ed il gioco va in freeze senza possibilitá di recupero.&lt;/div&gt;
&lt;div style="text-align: justify;"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style="text-align: justify;"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;a name='more'&gt;&lt;/a&gt;&lt;div style="text-align: justify;"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style="text-align: justify;"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style="text-align: justify;"&gt;
Fortunatamente (grazie &lt;a href="http://www.google.it/search?q=legend+dragoon+disc+2+lenus+regole+freeze"&gt;Google search&lt;/a&gt; e &lt;a href="http://www.supercheats.com/playstation/questions/thelegendofdragoon/55266/On-Disc-2-after-I-defeat-Lenus.htm"&gt;supercheats&lt;/a&gt;!), esiste una soluzione: &lt;b&gt;terminare la battaglia senza mai trasformare alcun personaggio in Dragone&lt;/b&gt;.&amp;nbsp; La cosa non é poi cosí impossibile come sembra, basta seguire alcuni accorgimenti:&lt;/div&gt;
&lt;ul style="text-align: justify;"&gt;
&lt;li style="text-align: justify;"&gt;avere il party ad un livello di almeno 20&lt;/li&gt;
&lt;li style="text-align: justify;"&gt;inserire Meru nel party poiché, essendo dello stesso elemento (acqua) dei due boss, riceve meno danni dai loro attacchi e gli oggetti magici d’attacco usati da lei sono piú efficaci&lt;/li&gt;
&lt;li style="text-align: justify;"&gt;inserire Shana nel party poiché gli oggetti magici d’attacco usati da lei sono piú efficaci&lt;/li&gt;
&lt;li style="text-align: justify;"&gt;fare grande scorta di oggetti d’attacco come Incenerimento (bersaglio singolo) e Magma sgorgante (bersagli multipli), molto efficaci specie se utilizzati da Dart, Meru o Shana&lt;/li&gt;
&lt;li style="text-align: justify;"&gt;puó aiutare equipaggiare Dart con la Lama Rovente perché aggiunge attacco fuoco a cui sono deboli i due boss&lt;/li&gt;
&lt;li style="text-align: justify;"&gt;evitare di inserire Kongol o Albert nel party per via della loro scarsa difesa magica e lentezza&lt;/li&gt;
&lt;li style="text-align: justify;"&gt;in alternativa a Shana, inserire Rose o Haschel nel party con il compito di utilizzare oggetti di recupero ed attaccare fisicamente Lenus verso la fine della battaglia quando non si hanno piú oggetti d’attacco&lt;/li&gt;
&lt;li style="text-align: justify;"&gt;puó aiutare equipaggiare con l’Anello del Bandito il membro piú lento del party, equipaggiare con l’Anello Lenitivo il membro del party che sará addetto alla cura e con l’Anello Fisico il membro del party con meno PF&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1859167416855250911-4762571828675312740?l=groglogs.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/7vUbkf1USMEiUYw1mcNT-1eno6A/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/7vUbkf1USMEiUYw1mcNT-1eno6A/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/7vUbkf1USMEiUYw1mcNT-1eno6A/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/7vUbkf1USMEiUYw1mcNT-1eno6A/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;</description><link>http://feedproxy.google.com/~r/groglogs/~3/SOtWwOUQL1c/legend-of-dragoon-fix-disc-2-freeze.html</link><author>noreply@blogger.com (Stefano Ghio)</author><thr:total>0</thr:total><feedburner:origLink>http://groglogs.blogspot.com/2011/09/legend-of-dragoon-fix-disc-2-freeze.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1859167416855250911.post-8653654047364744362</guid><pubDate>Wed, 10 Aug 2011 06:20:00 +0000</pubDate><atom:updated>2011-09-17T23:36:51.777+02:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Pictures</category><title>Portugal.. como un Jarro</title><description>Ci sono un Irlandese, un Portoghese e due Italiani in Portogallo con un &lt;i&gt;jarro&lt;/i&gt; in mano.. &lt;a href="http://cid-19468fe08387b566.photos.live.com/browse.aspx/Portugal%20como%20un%20Jarro"&gt;Scopri come va a finire guardando le foto&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;img border="0" height="533" src="https://sn2files.storage.live.com/y1p5PZy6bI_7AG2C4YPAJz43cpn_R6vau2LdSdlLwecrspI6IOdO-zn6nOF2rGvU6kYsht1RC-tfJc/IMG_1291.JPG" width="400" /&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;a name='more'&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="https://sn2files.storage.live.com/y1pZwyWtSbV7BjPZxH__E7EGeUK1oZegMUlYXhmxXthGr7f9owxLI5ZygZTixRTyBOpADvmU_WWZEY/IMG_1292.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="533" src="https://sn2files.storage.live.com/y1pZwyWtSbV7BjPZxH__E7EGeUK1oZegMUlYXhmxXthGr7f9owxLI5ZygZTixRTyBOpADvmU_WWZEY/IMG_1292.JPG" width="400" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Ps: If anyone knows who's the girl in the background, please say it in a comment!&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1859167416855250911-8653654047364744362?l=groglogs.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/b2t_5gXON9t1E07EGIK4G7LY_f4/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/b2t_5gXON9t1E07EGIK4G7LY_f4/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/b2t_5gXON9t1E07EGIK4G7LY_f4/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/b2t_5gXON9t1E07EGIK4G7LY_f4/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;</description><link>http://feedproxy.google.com/~r/groglogs/~3/1EPfCYiqFkc/portugal-como-un-jarro.html</link><author>noreply@blogger.com (Stefano Ghio)</author><thr:total>0</thr:total><feedburner:origLink>http://groglogs.blogspot.com/2011/08/portugal-como-un-jarro.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1859167416855250911.post-7571722208748181902</guid><pubDate>Sun, 31 Jul 2011 21:41:00 +0000</pubDate><atom:updated>2011-09-17T23:21:49.116+02:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">HowTo</category><category domain="http://www.blogger.com/atom/ns#">Linux</category><title>GNOME 3 add applications taskbar/panel</title><description>GNOME 3 does not have, like GNOME 2, two taskbars: one for the applications and one for the system tray. It is possible to add the application taskbar (which includes a system tray panel too) manually with the project &lt;a href="http://code.google.com/p/tint2/wiki/Install"&gt;tint2&lt;/a&gt;. All instructions for installing under different distros are available directly on the developers website.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;ITALIANO:&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;/b&gt;&lt;br /&gt;
&lt;a name='more'&gt;&lt;/a&gt;&lt;b&gt;&amp;nbsp;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
GNOME 3 non ha, a differenza di GNOME 2, due taskbar: una per le applicazioni e una per la system tray. É possibile aggiungere la barra delle applicazioni (che include anche un pannello di tray) manualmente tramite il progetto &lt;a href="http://code.google.com/p/tint2/wiki/Install"&gt;tint2&lt;/a&gt;. Tutte le istruzioni per l’installazione sotto differenti distribuzioni sono disponibili direttamente sul sito degli sviluppatori.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1859167416855250911-7571722208748181902?l=groglogs.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/uuX0hn9fKeeZ0ih2KY3rpn7uJtM/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/uuX0hn9fKeeZ0ih2KY3rpn7uJtM/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/uuX0hn9fKeeZ0ih2KY3rpn7uJtM/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/uuX0hn9fKeeZ0ih2KY3rpn7uJtM/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;</description><link>http://feedproxy.google.com/~r/groglogs/~3/44JMJDpCRhE/gnome-3-add-applications-taskbarpanel.html</link><author>noreply@blogger.com (Stefano Ghio)</author><thr:total>0</thr:total><feedburner:origLink>http://groglogs.blogspot.com/2011/07/gnome-3-add-applications-taskbarpanel.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1859167416855250911.post-7395306415083893571</guid><pubDate>Sun, 31 Jul 2011 21:32:00 +0000</pubDate><atom:updated>2011-09-17T23:22:32.455+02:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">HowTo</category><category domain="http://www.blogger.com/atom/ns#">Linux</category><title>GNOME 3 enable right click on desktop and show icons</title><description>GNOME 3 by default doen’t show any icon on the desktop and does not allow right-clicking it. You could change this behaviour manually:&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;run &lt;code&gt;yum install dconf-editor&lt;/code&gt; as root or install it via &lt;i&gt;add/remove software&lt;/i&gt; and launch it when it’s ready &lt;/li&gt;
&lt;li&gt;navigate the menus through org –&amp;gt; GNOME –&amp;gt; Desktop –&amp;gt; Background&lt;/li&gt;
&lt;li&gt;search for the &lt;i&gt;show-desktop-icons&lt;/i&gt; entry and chek its checkbox&lt;/li&gt;
&lt;/ul&gt;
&lt;b&gt;ITALIANO:&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;/b&gt;&lt;br /&gt;
&lt;a name='more'&gt;&lt;/a&gt;GNOME 3 di base non mostra alcuna icona sul desktop e non permette il click destro. Si puo’ modificare questo comportamento manualmente:&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;lanciate &lt;code&gt;yum install dconf-editor&lt;/code&gt; da root o installatelo via &lt;i&gt;add/remove software&lt;/i&gt; ed avviatelo al termine &lt;/li&gt;
&lt;li&gt;navigate i menu attraverso org –&amp;gt; GNOME –&amp;gt; Desktop –&amp;gt; Background &lt;/li&gt;
&lt;li&gt;cercate la voce &lt;i&gt;show-desktop-icons &lt;/i&gt;e selezionate la checkbox associata&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1859167416855250911-7395306415083893571?l=groglogs.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/-Ijmssi42FeGcSKcnBt4DQc0GVE/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/-Ijmssi42FeGcSKcnBt4DQc0GVE/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/-Ijmssi42FeGcSKcnBt4DQc0GVE/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/-Ijmssi42FeGcSKcnBt4DQc0GVE/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;</description><link>http://feedproxy.google.com/~r/groglogs/~3/1IA0YdpL4C4/gnome-3-enable-right-click-on-desktop.html</link><author>noreply@blogger.com (Stefano Ghio)</author><thr:total>1</thr:total><feedburner:origLink>http://groglogs.blogspot.com/2011/07/gnome-3-enable-right-click-on-desktop.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1859167416855250911.post-237543862519630938</guid><pubDate>Sun, 31 Jul 2011 21:24:00 +0000</pubDate><atom:updated>2011-09-17T23:22:46.627+02:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">HowTo</category><category domain="http://www.blogger.com/atom/ns#">Linux</category><title>GNOME 3 add minimize and restore buttons to windows</title><description>GNOME 3 by default shows only the “close” button on windows. You could add the other two (minimize and restore/maximize) manually:&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;run &lt;code&gt;yum install gconf-editor&lt;/code&gt; as root or install it via &lt;i&gt;add/remove software&lt;/i&gt; and launch it when it’s ready &lt;/li&gt;
&lt;li&gt;navigate the menus through Desktop –&amp;gt; GNOME –&amp;gt; Shell –&amp;gt; Windows &lt;/li&gt;
&lt;li&gt;search for the &lt;i&gt;button_layout&lt;/i&gt; entry and edit its value to &lt;code&gt;:minimize,maximize,close&lt;/code&gt; (colon included!)&lt;/li&gt;
&lt;li&gt;restart nautilus or log out and in again to see the changes take effect &lt;/li&gt;
&lt;/ul&gt;
&lt;br /&gt;
&lt;b&gt;ITALIANO:&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;a name='more'&gt;&lt;/a&gt;&lt;br /&gt;
GNOME 3 di base mostra solo il bottone “chiudi” sulle finestre. Si possono aggiungere gli altri due (minimizza e ripristina) manualmente:&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;lanciate &lt;code&gt;yum install gconf-editor&lt;/code&gt; da root o installatelo via &lt;i&gt;add/remove software&lt;/i&gt; ed avviatelo al termine &lt;/li&gt;
&lt;li&gt;navigate i menu attraverso Desktop –&amp;gt; GNOME –&amp;gt; Shell –&amp;gt; Windows &lt;/li&gt;
&lt;li&gt;cercate la voce &lt;i&gt;button_layout&lt;/i&gt; e modificate il suo valore a &lt;code&gt;:minimize,maximize,close&lt;/code&gt; (due punti inclusi!)&lt;/li&gt;
&lt;li&gt;riavviate nautilus o fate log out e log in di nuovo per vedere il cambiamento in azione&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1859167416855250911-237543862519630938?l=groglogs.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/NueC50OxF3zcblA4UeC2Tro72ng/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/NueC50OxF3zcblA4UeC2Tro72ng/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/NueC50OxF3zcblA4UeC2Tro72ng/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/NueC50OxF3zcblA4UeC2Tro72ng/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;</description><link>http://feedproxy.google.com/~r/groglogs/~3/McYqR3IsB_g/gnome-3-add-minimize-and-restore.html</link><author>noreply@blogger.com (Stefano Ghio)</author><thr:total>0</thr:total><feedburner:origLink>http://groglogs.blogspot.com/2011/07/gnome-3-add-minimize-and-restore.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1859167416855250911.post-4477686110220347633</guid><pubDate>Sun, 31 Jul 2011 21:05:00 +0000</pubDate><atom:updated>2011-07-31T23:07:29.458+02:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">HowTo</category><category domain="http://www.blogger.com/atom/ns#">Linux</category><title>Realtek wireless on Fedora</title><description>&lt;p&gt;This article applies to the &lt;a href="http://www.realtek.com/downloads/searchView.aspx?keyword=8191"&gt;819x Realtek wireless cards&lt;/a&gt; series like models 8191SEvB, 8191SEvA2, 8192SE, …&lt;/p&gt;  &lt;p&gt;Main reference site is &lt;a href="http://cz.linkedin.com/pub/stanislaw-gruszka/b/5b5/96b"&gt;Stanislaw Gruszka&lt;/a&gt;’s &lt;a href="http://people.redhat.com/sgruszka/compact_wireless.html"&gt;compact wireless website&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;You can either try the &lt;a href="http://people.redhat.com/sgruszka/compat-wireless/"&gt;-stable&lt;/a&gt; version or the &lt;a href="http://people.redhat.com/sgruszka/compat-wireless-next/"&gt;–next&lt;/a&gt;. Both have different kernel requirements, the –next version, though more unstable, is compiled against the latest kernel version so you should run &lt;code&gt;yum update kernel&lt;/code&gt; as root before installing the appropriate package for your system.&lt;/p&gt;  &lt;p&gt;After installation you will have to reboot the system before being able to use and control your wireless card through NetworkManager.&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;ITALIANO:&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;Questo articolo si applica ai modelli di schede &lt;a href="http://www.realtek.com/downloads/searchView.aspx?keyword=8191"&gt;wireless Realtek serie 819x&lt;/a&gt; quali 8191SEvB, 8191SEvA2, 8192SE, …&lt;/p&gt;  &lt;p&gt;Il sito di riferimento é &lt;a href="http://people.redhat.com/sgruszka/compact_wireless.html"&gt;compact wireless&lt;/a&gt; di &lt;a href="http://cz.linkedin.com/pub/stanislaw-gruszka/b/5b5/96b"&gt;Stanislaw Gruszka&lt;/a&gt;. &lt;/p&gt;  &lt;p&gt;Potete provare sia la versione &lt;a href="http://people.redhat.com/sgruszka/compat-wireless/"&gt;-stable&lt;/a&gt; che la &lt;a href="http://people.redhat.com/sgruszka/compat-wireless-next/"&gt;–next&lt;/a&gt;. Entrambe hanno differenti requisiti di kernel, la versione –next, sebbene piú instabile, é compilata per l’ultima versione del kernel supportata dal sistema per cui é sufficiente lanciare &lt;code&gt;yum update kernel&lt;/code&gt; da root prima di installare il pacchetto corretto per il proprio sistema.&lt;/p&gt;  &lt;p&gt;Al termine dell’installazione sará necessario riavviare il sistema prima di poter usare e controllare la propria scheda wireless attraverso il NetworkManager.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1859167416855250911-4477686110220347633?l=groglogs.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/XK9xiB4MlBXPlzPO2HiOGGGLlT8/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/XK9xiB4MlBXPlzPO2HiOGGGLlT8/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/XK9xiB4MlBXPlzPO2HiOGGGLlT8/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/XK9xiB4MlBXPlzPO2HiOGGGLlT8/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;</description><link>http://feedproxy.google.com/~r/groglogs/~3/M9ILzTcYBto/realtek-wireless-on-fedora.html</link><author>noreply@blogger.com (Stefano Ghio)</author><thr:total>0</thr:total><feedburner:origLink>http://groglogs.blogspot.com/2011/07/realtek-wireless-on-fedora.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1859167416855250911.post-2213697597942068080</guid><pubDate>Wed, 20 Jul 2011 16:33:00 +0000</pubDate><atom:updated>2011-09-17T23:43:43.768+02:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Source code</category><title>[MatLab] EM – Expectation Maximization reconstruction technique implementation</title><description>&lt;p&gt;&lt;a href="http://en.wikipedia.org/wiki/Expectation_maximization"&gt;EM – Expectation Maximization&lt;/a&gt; is an &lt;a href="http://scholar.google.it/scholar?q=expectation+maximization+reconstruction+technique&amp;amp;hl=en&amp;amp;as_sdt=0&amp;amp;as_vis=1&amp;amp;oi=scholart"&gt;iterative algorithm&lt;/a&gt; used in tomographic images (as in &lt;a href="http://en.wikipedia.org/wiki/Computed_tomography"&gt;CT&lt;/a&gt;) reconstruction, very useful when the &lt;a href="http://www.owlnet.rice.edu/~elec539/Projects97/cult/node2.html"&gt;FBP – Filtered Back Projection technique&lt;/a&gt; is not applicable.&lt;/p&gt;    &lt;p&gt;Basic formula is:&lt;/p&gt;  &lt;p&gt;f_k+1 = (f_k / alpha) (At (g / (A f_k)))&lt;/p&gt;  &lt;p&gt;where:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;f_k is solution (the resulting reconstructed image) at k-th iteration, at first iteration it is our guess&lt;/li&gt;    &lt;li&gt;g is image &lt;a href="http://en.wikipedia.org/wiki/Radon_transform"&gt;sinogram&lt;/a&gt; (what we get from the scanning)&lt;/li&gt;    &lt;li&gt;A f_k is &lt;a href="http://en.wikipedia.org/wiki/Radon_transform"&gt;Radon transform&lt;/a&gt; of f_k&lt;/li&gt;    &lt;li&gt;At is inverse Radon&lt;/li&gt;    &lt;li&gt;alpha is inverse Radon of a sinogram with all values 1 which represents our scanning machine&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;&lt;a href="http://digilander.libero.it/otacoconvention/source/bi/EM.m"&gt;Get the source code here.&lt;/a&gt;&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1859167416855250911-2213697597942068080?l=groglogs.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/W_C4mHbZizQL-ZEDPMzcm1EWaFo/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/W_C4mHbZizQL-ZEDPMzcm1EWaFo/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/W_C4mHbZizQL-ZEDPMzcm1EWaFo/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/W_C4mHbZizQL-ZEDPMzcm1EWaFo/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;</description><link>http://feedproxy.google.com/~r/groglogs/~3/kmj8bEJjwHk/matlab-em-expectation-maximization.html</link><author>noreply@blogger.com (Stefano Ghio)</author><thr:total>0</thr:total><feedburner:origLink>http://groglogs.blogspot.com/2011/07/matlab-em-expectation-maximization.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1859167416855250911.post-9019378628709830452</guid><pubDate>Wed, 20 Jul 2011 16:26:00 +0000</pubDate><atom:updated>2011-09-17T23:43:43.857+02:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Source code</category><title>[MatLab] SIRT - Simultaneous Iterative Reconstruction Technique implementation</title><description>&lt;p&gt;&lt;a href="http://scholar.google.it/scholar?q=simultaneous+iterative+reconstruction+technique&amp;amp;hl=en&amp;amp;as_sdt=0&amp;amp;as_vis=1&amp;amp;oi=scholart"&gt;SIRT – Simultaneous (algebraic) Reconstruction Technique&lt;/a&gt; is an iterative algorithm used in tomographic images (as in &lt;a href="http://en.wikipedia.org/wiki/Computed_tomography"&gt;CT&lt;/a&gt;) reconstruction, very useful when the &lt;a href="http://www.owlnet.rice.edu/~elec539/Projects97/cult/node2.html"&gt;FBP – Filtered Back Projection technique&lt;/a&gt; is not applicable.&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;Basic formula is: &lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt; f_(k+1) = f_k + At (g - A f_K)  &lt;br /&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;where:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;f_k is solution (the resulting reconstructed image) at k-th iteration, at first iteration it is our guess&lt;/li&gt;    &lt;li&gt;g is image &lt;a href="http://en.wikipedia.org/wiki/Radon_transform"&gt;sinogram&lt;/a&gt; (what we get from the scanning)&lt;/li&gt;    &lt;li&gt;A f_k is &lt;a href="http://en.wikipedia.org/wiki/Radon_transform"&gt;Radon transform&lt;/a&gt; of f_k&lt;/li&gt;    &lt;li&gt;At is inverse Radon&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://digilander.libero.it/otacoconvention/source/bi/SIRT.m"&gt;Get the source code here.&lt;/a&gt;&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1859167416855250911-9019378628709830452?l=groglogs.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/Z9aVgb2TtGaAEhhsgvlCZ2R-oEc/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/Z9aVgb2TtGaAEhhsgvlCZ2R-oEc/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/Z9aVgb2TtGaAEhhsgvlCZ2R-oEc/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/Z9aVgb2TtGaAEhhsgvlCZ2R-oEc/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;</description><link>http://feedproxy.google.com/~r/groglogs/~3/iL0nB0nFZ-Q/matlab-sirt-simultaneous-iterative.html</link><author>noreply@blogger.com (Stefano Ghio)</author><thr:total>0</thr:total><feedburner:origLink>http://groglogs.blogspot.com/2011/07/matlab-sirt-simultaneous-iterative.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1859167416855250911.post-3661233516570443583</guid><pubDate>Wed, 20 Jul 2011 16:16:00 +0000</pubDate><atom:updated>2011-09-17T23:43:43.787+02:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Source code</category><title>[MatLab] Filter a tomographic image in Fourier’s space</title><description>&lt;p&gt;&lt;a href="http://www.mathworks.com/products/matlab/"&gt;MatLab&lt;/a&gt; has built-in functions to simulate acquisition and elaboration of tomographic (as in &lt;a href="https://secure.wikimedia.org/wikipedia/en/wiki/X-ray_computed_tomography"&gt;CT&lt;/a&gt;) images. When it comes to filtering the image prior to &lt;a href="http://www.owlnet.rice.edu/~elec539/Projects97/cult/node2.html"&gt;back-projecting&lt;/a&gt; it, it is possible to do it yourself without relying on the (good as in &lt;a href="http://scholar.google.com/scholar?q=shepp-logan&amp;amp;hl=en&amp;amp;as_sdt=0&amp;amp;as_vis=1&amp;amp;oi=scholart"&gt;Shepp-Logan&lt;/a&gt;) filters MatLab has.&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;We will filter our image in Fourier’s space. For each column of the &lt;a href="http://en.wikipedia.org/wiki/Radon_transform"&gt;sinogram&lt;/a&gt;, we:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt; apply the &lt;a href="http://en.wikipedia.org/wiki/Fourier_transform"&gt;Fourier transform&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;filter it&lt;/li&gt;    &lt;li&gt;apply the Fourier antitransform&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;When we reconstruct our image WITHOUT having MatLab apply any filter, we’ll see the image, filtered with our filter, as a result. &lt;a href="http://digilander.libero.it/otacoconvention/source/bi/iRadon.m"&gt;Get the source code here&lt;/a&gt;.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1859167416855250911-3661233516570443583?l=groglogs.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/3gWjcln80BackPnNLC9xatcH5TU/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/3gWjcln80BackPnNLC9xatcH5TU/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/3gWjcln80BackPnNLC9xatcH5TU/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/3gWjcln80BackPnNLC9xatcH5TU/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;</description><link>http://feedproxy.google.com/~r/groglogs/~3/omDPBZiCtPM/matlab-filter-tomographic-image-in.html</link><author>noreply@blogger.com (Stefano Ghio)</author><thr:total>0</thr:total><feedburner:origLink>http://groglogs.blogspot.com/2011/07/matlab-filter-tomographic-image-in.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1859167416855250911.post-1710706318081152833</guid><pubDate>Wed, 06 Jul 2011 14:21:00 +0000</pubDate><atom:updated>2011-09-17T23:43:43.756+02:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Web</category><category domain="http://www.blogger.com/atom/ns#">Source code</category><title>[PHP] PageRank implementation</title><description>&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-7GHTxzkU254/ThRo98CfgPI/AAAAAAAAAK8/olBNQ4v_i7I/s1600/pickmeplease.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="240" src="http://4.bp.blogspot.com/-7GHTxzkU254/ThRo98CfgPI/AAAAAAAAAK8/olBNQ4v_i7I/s320/pickmeplease.jpg" width="320" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div style="margin-bottom: 0cm;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;span style="font-size: small;"&gt;&lt;span style="font-family: Calibri,sans-serif;"&gt;There are two possible &lt;a href="http://en.wikipedia.org/wiki/Pagerank"&gt;PageRank&lt;/a&gt; implementations: the power method and the iterative method. We will describe both.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-family: Calibri,sans-serif;"&gt;&lt;span style="font-size: small;"&gt;To check the results obtained we provide a scri'pt to generate a &lt;i&gt;.gexf&lt;/i&gt; file to be opened with &lt;a href="http://gephi.org/"&gt;Gephi&lt;/a&gt;.&lt;br /&gt;
&lt;br /&gt;
Test datasets are available at the &lt;a href="http://www.cs.toronto.edu/%7Etsap/experiments/datasets/index.html"&gt;Toronto university website&lt;/a&gt;.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div style="margin-bottom: 0cm;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style="margin-bottom: 0.5cm;"&gt;&lt;span style="font-family: Calibri,sans-serif;"&gt;&lt;span style="font-size: small;"&gt;&lt;b&gt;Technologies used:&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;ul&gt;&lt;li&gt;&lt;div style="margin-bottom: 0cm;"&gt;&lt;span style="font-family: Calibri,sans-serif;"&gt;&lt;span style="font-size: small;"&gt;&lt;span style="font-weight: normal;"&gt;PHP&lt;/span&gt;  &lt;/span&gt;&lt;/span&gt;  &lt;/div&gt;&lt;/li&gt;
&lt;li&gt;&lt;div style="margin-bottom: 0cm;"&gt;&lt;span style="font-family: Calibri,sans-serif;"&gt;&lt;span style="font-size: small;"&gt;&lt;span style="font-weight: normal;"&gt;Gephi&lt;/span&gt;  &lt;/span&gt;&lt;/span&gt;  &lt;/div&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style="font-family: Calibri,sans-serif;"&gt;&lt;span style="font-size: small;"&gt;&lt;span style="font-weight: normal;"&gt;XML&lt;/span&gt;  &lt;/span&gt;&lt;/span&gt;  &lt;br /&gt;
&lt;/li&gt;
&lt;/ul&gt;&lt;div style="margin-bottom: 0cm;"&gt;&lt;/div&gt;&lt;span style="font-family: Calibri,sans-serif;"&gt;&lt;span style="font-size: small;"&gt; &lt;b&gt;1.Power method &lt;/b&gt;&lt;br /&gt;
&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: Calibri,sans-serif;"&gt;&lt;span style="font-size: small;"&gt;This method takes longer than the other one, however the result is equally right. Using a sparse matrix instead of the full one may help speed up the process.&lt;br /&gt;
&lt;br /&gt;
Method description:&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;ol&gt;&lt;li&gt;&lt;div style="margin-bottom: 0cm;"&gt;&lt;span style="font-family: Calibri,sans-serif;"&gt;&lt;span style="font-size: small;"&gt;Pick the NxN input matrix and make it stochastic, call it A&lt;/span&gt;&lt;/span&gt;  &lt;/div&gt;&lt;/li&gt;
&lt;li&gt;&lt;div style="margin-bottom: 0cm;"&gt;&lt;span style="font-family: Calibri,sans-serif;"&gt;&lt;span style="font-size: small;"&gt;Create the P" matrix as alpha*A+(1-alpha)*M with &lt;i&gt;alpha&lt;/i&gt; a factor which describes the probability of a random jump and &lt;i&gt;M &lt;/i&gt;an NxN matrix filled with values 1/N&lt;/span&gt;&lt;/span&gt;  &lt;/div&gt;&lt;/li&gt;
&lt;li&gt;&lt;div style="margin-bottom: 0cm;"&gt;&lt;span style="font-family: Calibri,sans-serif;"&gt;&lt;span style="font-size: small;"&gt;Create starting vector v_0 with length N filled with values 1/N&lt;/span&gt;&lt;/span&gt;  &lt;/div&gt;&lt;/li&gt;
&lt;li&gt;&lt;div style="margin-bottom: 0cm;"&gt;&lt;span style="font-family: Calibri,sans-serif;"&gt;&lt;span style="font-size: small;"&gt;Compute v_m = v_m-1*P" where the first time v_m-1 is exactly v_0&lt;/span&gt;&lt;/span&gt;  &lt;/div&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style="font-family: Calibri,sans-serif;"&gt;&lt;span style="font-size: small;"&gt;Compute the difference v_m - v_m-1 which should converge to 0&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style="font-family: Calibri,sans-serif;"&gt;&lt;span style="font-size: small;"&gt;When the difference doesn't vary over a certain threshold or &lt;i&gt;i&lt;/i&gt; iterations have been made, stop. v_m should contain the PageRank for every page &lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;/ol&gt;&lt;span style="font-family: Calibri,sans-serif;"&gt;&lt;span style="font-size: small;"&gt;To run the program you must have the &lt;/span&gt;&lt;/span&gt;&lt;span style="font-family: Calibri,sans-serif;"&gt;&lt;span style="font-size: small;"&gt;&lt;i&gt;nodes&lt;/i&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family: Calibri,sans-serif;"&gt;&lt;span style="font-size: small;"&gt; and &lt;/span&gt;&lt;/span&gt;&lt;span style="font-family: Calibri,sans-serif;"&gt;&lt;span style="font-size: small;"&gt;&lt;i&gt;adj_matrix&lt;/i&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family: Calibri,sans-serif;"&gt;&lt;span style="font-size: small;"&gt; files from the chosen dataset. The implementation source code is found here &lt;a href="http://digilander.libero.it/otacoconvention/source/ar2/pagerank/pagerank.php"&gt;here&lt;/a&gt;.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: Calibri,sans-serif;"&gt;&lt;span style="font-size: small;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family: Calibri,sans-serif;"&gt;&lt;span style="font-size: small;"&gt;&lt;u&gt;&lt;b&gt;NOTE:&lt;/b&gt;&lt;/u&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family: Calibri,sans-serif;"&gt;&lt;span style="font-size: small;"&gt; Due to Apache and PHP limitations, you may have to modify the &lt;i&gt;php.ini&lt;/i&gt; file to grant more memory to the scripts (if you don't want to store the matrix on filesystem like we did) by setting the &lt;/span&gt;&lt;/span&gt;&lt;span style="font-family: Calibri,sans-serif;"&gt;&lt;span style="font-size: small;"&gt;&lt;i&gt;memory_limit&lt;/i&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family: Calibri,sans-serif;"&gt;&lt;span style="font-size: small;"&gt; parameter to at least 768MB and raising the maximum script execution time to 5 minutes(300 seconds) with &lt;/span&gt;&lt;/span&gt;&lt;span style="font-family: Calibri,sans-serif;"&gt;&lt;span style="font-size: small;"&gt;&lt;i&gt;max_execution_time&lt;/i&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family: Calibri,sans-serif;"&gt;&lt;span style="font-size: small;"&gt;.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: Calibri,sans-serif;"&gt;&lt;span style="font-size: small;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family: Calibri,sans-serif;"&gt;&lt;span style="font-size: small;"&gt;&lt;b&gt;2. Iterative method - found on &lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family: Calibri,sans-serif;"&gt;&lt;span style="font-size: small;"&gt;&lt;a href="http://phpir.com/pagerank-in-php"&gt;phpir&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family: Calibri,sans-serif;"&gt;&lt;span style="font-size: small;"&gt;&lt;br /&gt;
&lt;br /&gt;
To use this method you must have the &lt;/span&gt;&lt;/span&gt;&lt;span style="font-family: Calibri,sans-serif;"&gt;&lt;span style="font-size: small;"&gt;&lt;i&gt;nodes&lt;/i&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family: Calibri,sans-serif;"&gt;&lt;span style="font-size: small;"&gt; and &lt;/span&gt;&lt;/span&gt;&lt;span style="font-family: Calibri,sans-serif;"&gt;&lt;span style="font-size: small;"&gt;&lt;i&gt;adj_list&lt;/i&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family: Calibri,sans-serif;"&gt;&lt;span style="font-size: small;"&gt; files from the chosen dataset.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: Calibri,sans-serif;"&gt;&lt;span style="font-size: small;"&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: Calibri,sans-serif;"&gt;&lt;span style="font-size: small;"&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: Calibri,sans-serif;"&gt;&lt;span style="font-size: small;"&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: Calibri,sans-serif;"&gt;&lt;span style="font-size: small;"&gt;&lt;br /&gt;
Method description:&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: Calibri,sans-serif;"&gt;&lt;span style="font-size: small;"&gt; &lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: Calibri,sans-serif;"&gt;&lt;span style="font-size: small;"&gt;Each page is given a starting PR of 1/N where N is the number of nodes in the graph. Each page then gives to every page it links a PR of current_page_PR/number_of_outbound_links.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: Calibri,sans-serif;"&gt;&lt;span style="font-size: small;"&gt;It's introduced a dampening factor alpha (0,15) which represents the probability of making a random jump while visiting the graph or when reaching a &lt;i&gt;cul de sac&lt;/i&gt;.&lt;/span&gt;&lt;span style="font-size: small;"&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family: Calibri,sans-serif;"&gt;&lt;span style="font-size: small;"&gt;&lt;br /&gt;
&lt;br /&gt;
PR_new = alpha/n + (1-alpha)*PR_old&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: Calibri,sans-serif;"&gt;&lt;span style="font-size: small;"&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: Calibri,sans-serif;"&gt;&lt;span style="font-size: small;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: Calibri,sans-serif;"&gt;&lt;span style="font-size: small;"&gt;Every PR is then normalized between 0 and 1.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: Calibri,sans-serif;"&gt;&lt;span style="font-size: small;"&gt;&lt;br /&gt;
The process keeps going until it has reached &lt;i&gt;i&lt;/i&gt; iterations or the difference between old and new PR doesn't vary over a certain threshold.&lt;br /&gt;
&lt;br /&gt;
Our implementation is available &lt;a href="http://digilander.libero.it/otacoconvention/source/ar2/pagerank/pagerank_iterative.php"&gt;here&lt;/a&gt;.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: Calibri,sans-serif;"&gt;&lt;span style="font-size: small;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family: Calibri,sans-serif;"&gt;&lt;span style="font-size: small;"&gt;&lt;b&gt;3. Gephi parser:&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family: Calibri,sans-serif;"&gt;&lt;span style="font-size: small;"&gt;&lt;br /&gt;
&lt;br /&gt;
To use the &lt;/span&gt;&lt;/span&gt;&lt;span style="font-family: Calibri,sans-serif;"&gt;&lt;span style="font-size: small;"&gt;&lt;a href="http://digilander.libero.it/otacoconvention/source/ar2/pagerank/parse_pagerank.php"&gt;parser&lt;/a&gt; &lt;/span&gt;&lt;/span&gt;&lt;span style="font-family: Calibri,sans-serif;"&gt;&lt;span style="font-size: small;"&gt; you &lt;/span&gt;&lt;/span&gt;&lt;span style="font-family: Calibri,sans-serif;"&gt;&lt;span style="font-size: small;"&gt;you must have the &lt;/span&gt;&lt;/span&gt;&lt;span style="font-family: Calibri,sans-serif;"&gt;&lt;span style="font-size: small;"&gt;&lt;i&gt;nodes&lt;/i&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family: Calibri,sans-serif;"&gt;&lt;span style="font-size: small;"&gt; and &lt;/span&gt;&lt;/span&gt;&lt;span style="font-family: Calibri,sans-serif;"&gt;&lt;span style="font-size: small;"&gt;&lt;i&gt;adj_list&lt;/i&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family: Calibri,sans-serif;"&gt;&lt;span style="font-size: small;"&gt; files from the chosen dataset. The parser outputs a &lt;i&gt;.gexf&lt;/i&gt; file to be opened with Gephi. Here is a sample &lt;/span&gt;&lt;/span&gt;&lt;span style="font-family: Calibri,sans-serif;"&gt;&lt;span style="font-size: small;"&gt;&lt;a href="http://digilander.libero.it/otacoconvention/source/ar2/pagerank/out.gexf"&gt;.gexf&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family: Calibri,sans-serif;"&gt;&lt;span style="font-size: small;"&gt; file obtained by parsing the first dataset available on the site (the one about abortion).&lt;/span&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1859167416855250911-1710706318081152833?l=groglogs.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/3zZTPbjhF3FZELlGqRimZF2g3Jg/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/3zZTPbjhF3FZELlGqRimZF2g3Jg/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/3zZTPbjhF3FZELlGqRimZF2g3Jg/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/3zZTPbjhF3FZELlGqRimZF2g3Jg/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;</description><link>http://feedproxy.google.com/~r/groglogs/~3/kCI_VJ_bblE/php-pagerank-implementation.html</link><author>noreply@blogger.com (Stefano Ghio)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://4.bp.blogspot.com/-7GHTxzkU254/ThRo98CfgPI/AAAAAAAAAK8/olBNQ4v_i7I/s72-c/pickmeplease.jpg" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://groglogs.blogspot.com/2011/07/php-pagerank-implementation.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1859167416855250911.post-1693625592349800850</guid><pubDate>Wed, 25 May 2011 13:39:00 +0000</pubDate><atom:updated>2011-09-17T23:43:43.754+02:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Web</category><title>pro-AD website: MRI analysis for prodromal Alzheimer’s assessment</title><description>&lt;p&gt;Recently I participated in the &lt;em&gt;pro-AD&lt;/em&gt;’s website development.&lt;/p&gt;  &lt;p&gt;   &lt;br /&gt;&lt;a href="http://magic5gui.ge.infn.it/tesi/"&gt;pro-AD&lt;/a&gt; is a website created at DIFI, the University of Genoa’s Department of Physics, to help medics automagically analyse MRI images for the prodromal Alzheimer's disease assessment. &lt;/p&gt;  &lt;p&gt;Registered medics can easily submit &lt;em&gt;DICOM&lt;/em&gt; or &lt;em&gt;NII&lt;/em&gt; files through the website to their private local folder via the java applet JUploader or the PHP uploader which is shown automatically when no java plugin is detected on the user's browser. They can then modify the information associated with those images: age, gender and an optional unique ID - &lt;strong&gt;no personal data about the patients is stored anywhere anytime during the process&lt;/strong&gt;.&lt;/p&gt;  &lt;p&gt;   &lt;br /&gt;Easy access for the medic's personal profile is provided through a dedicated page; if a valid e-mail address is provided, it is possible to enable e-mail notifications about processing results.&lt;/p&gt;  &lt;p&gt;   &lt;br /&gt;When one or more files are selected for processing, the server enqueues them in a multithreaded pipeline and starts the analysis. At the end, a single number which describes the patient's likelihood of being affected in the near future by the disease is returned for each file sent to processing. If the file processed was of really bad quality or was not a valid file, the process fails and an error is shown instead of the result.&lt;/p&gt;  &lt;p&gt;   &lt;br /&gt;All results are stored for easy future access and can be viewed and exported in XLS format from a dedicated page. If a file is sent to processing more times, only the latest result is stored.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1859167416855250911-1693625592349800850?l=groglogs.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/zq9I7cmLVO3TbN-8JqOMSWA0_8c/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/zq9I7cmLVO3TbN-8JqOMSWA0_8c/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/zq9I7cmLVO3TbN-8JqOMSWA0_8c/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/zq9I7cmLVO3TbN-8JqOMSWA0_8c/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;</description><link>http://feedproxy.google.com/~r/groglogs/~3/uOau-j6qSrI/pro-ad-website-mri-analysis-for.html</link><author>noreply@blogger.com (Stefano Ghio)</author><thr:total>0</thr:total><feedburner:origLink>http://groglogs.blogspot.com/2011/05/pro-ad-website-mri-analysis-for.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1859167416855250911.post-6206636736169277737</guid><pubDate>Wed, 25 May 2011 13:18:00 +0000</pubDate><atom:updated>2011-09-17T23:43:43.823+02:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Web</category><category domain="http://www.blogger.com/atom/ns#">HowTo</category><category domain="http://www.blogger.com/atom/ns#">Source code</category><title>[PHP] Create XLS document</title><description>&lt;p&gt;If you need to create XLS documents via PHP, you may need these functions:&lt;/p&gt;  &lt;p&gt;//XLS Begin of file    &lt;br /&gt;function xlsBOF() {     &lt;br /&gt;echo pack(&amp;quot;ssssss&amp;quot;, 0x809, 0x8, 0x0, 0x10, 0x0, 0x0);     &lt;br /&gt;return;     &lt;br /&gt;}     &lt;br /&gt;//XLS End of file     &lt;br /&gt;function xlsEOF() {     &lt;br /&gt;echo pack(&amp;quot;ss&amp;quot;, 0x0A, 0x00);     &lt;br /&gt;return;     &lt;br /&gt;}     &lt;br /&gt;//Writes a number in a cell     &lt;br /&gt;function xlsWriteNumber($Row, $Col, $Value) {     &lt;br /&gt;if($Value == null){     &lt;br /&gt;xlsWriteLabel($Row, $Col, $Value);     &lt;br /&gt;}     &lt;br /&gt;else{     &lt;br /&gt;echo pack(&amp;quot;sssss&amp;quot;, 0x203, 14, $Row, $Col, 0x0);     &lt;br /&gt;echo pack(&amp;quot;d&amp;quot;, $Value);     &lt;br /&gt;}     &lt;br /&gt;return;     &lt;br /&gt;}     &lt;br /&gt;//Writes a string in a cell     &lt;br /&gt;function xlsWriteLabel($Row, $Col, $Value ) {     &lt;br /&gt;$L = strlen($Value);     &lt;br /&gt;echo pack(&amp;quot;ssssss&amp;quot;, 0x204, 8 + $L, $Row, $Col, 0x0, $L);     &lt;br /&gt;echo $Value;     &lt;br /&gt;return;     &lt;br /&gt;} &lt;/p&gt;  &lt;p&gt;//Creates headers to download the file    &lt;br /&gt;function xlsWriteHeader(){     &lt;br /&gt;// Send Header     &lt;br /&gt;header(&amp;quot;Pragma: public&amp;quot;);     &lt;br /&gt;header(&amp;quot;Expires: 0&amp;quot;);     &lt;br /&gt;header(&amp;quot;Cache-Control: must-revalidate, post-check=0, pre-check=0&amp;quot;);     &lt;br /&gt;header(&amp;quot;Content-Type: application/force-download&amp;quot;);     &lt;br /&gt;header(&amp;quot;Content-Type: application/octet-stream&amp;quot;);     &lt;br /&gt;header(&amp;quot;Content-Type: application/download&amp;quot;);;     &lt;br /&gt;header(&amp;quot;Content-Disposition: attachment;filename=EXPORTNAME.xls &amp;quot;);     &lt;br /&gt;header(&amp;quot;Content-Transfer-Encoding: binary &amp;quot;);     &lt;br /&gt;}&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1859167416855250911-6206636736169277737?l=groglogs.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/89lG6lM96g4ktK3g1GZCJls7PtE/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/89lG6lM96g4ktK3g1GZCJls7PtE/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/89lG6lM96g4ktK3g1GZCJls7PtE/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/89lG6lM96g4ktK3g1GZCJls7PtE/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;</description><link>http://feedproxy.google.com/~r/groglogs/~3/lOJdScaThaE/php-create-xls-document.html</link><author>noreply@blogger.com (Stefano Ghio)</author><thr:total>0</thr:total><feedburner:origLink>http://groglogs.blogspot.com/2011/05/php-create-xls-document.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1859167416855250911.post-7436577266764902000</guid><pubDate>Wed, 25 May 2011 13:08:00 +0000</pubDate><atom:updated>2011-09-17T23:43:43.834+02:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Web</category><category domain="http://www.blogger.com/atom/ns#">HowTo</category><category domain="http://www.blogger.com/atom/ns#">Source code</category><title>[PHP] Send mail with attachment using PEAR</title><description>&lt;p&gt;If you use &lt;a href="http://pear.php.net/"&gt;PEAR&lt;/a&gt; and want to send mails with attachments via PHP, you may find this helpful.&lt;/p&gt;  &lt;p&gt;First, ensure you have installed PEAR’s &lt;a href="http://pear.php.net/package/Mail/"&gt;Mail&lt;/a&gt; and &lt;a href="http://pear.php.net/package/Mail_Mime/redirected"&gt;Mail_mime&lt;/a&gt; packages. Then, you just need a function like this:&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;function send_mail($mail, $subject, $bodytxt, $bodyhtml, $attachment){    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; require_once('Mail.php');     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; require_once('Mail/mime.php');     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; //mail parameters, this is the basic one     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; $params = array(&amp;quot;host&amp;quot;=&amp;gt;&amp;quot;YOUR_HOST&amp;quot;);     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; //creates smtp mail object     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; $mail_sender = Mail::factory(&amp;quot;smtp&amp;quot;, $params);     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; //creates mail headers     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; $headers = array(&amp;quot;From&amp;quot;=&amp;gt;&amp;quot;YOUR_ADDRESS&amp;quot;, &amp;quot;To&amp;quot;=&amp;gt;$mail, &amp;quot;Subject&amp;quot;=&amp;gt;$subject);     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; //creates attachment and body fields     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; $crlf = &amp;quot;\n&amp;quot;;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; $mime = new Mail_mime($crlf);     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; $mime-&amp;gt;setTXTBody($bodytxt);     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; $mime-&amp;gt;setHTMLBody($bodyhtml);     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; $mime-&amp;gt;addAttachment($attachment, &amp;quot;ATTACHMENT_TYPE&amp;quot;);     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; //never change these lines order     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; $body = $mime-&amp;gt;get();     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; $headers = $mime-&amp;gt;headers($headers);     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; $error=$mail_sender-&amp;gt;send($mail, $headers, $body);     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; return $error;     &lt;br /&gt;}&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;where:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;YOUR_HOST is your mail host, something like smtp.gmail.com &lt;/li&gt;    &lt;li&gt;$mail is the recipient’s mail address &lt;/li&gt;    &lt;li&gt;$bodytxt is the mail’s body in TXT format, do not use HTML markup here! &lt;/li&gt;    &lt;li&gt;ATTACHMENT_TYPE is the attachment’s &lt;a href="http://www.iana.org/assignments/media-types/index.html"&gt;MIME type as per IANA’s specifications&lt;/a&gt;, something like image/jpeg &lt;/li&gt;    &lt;li&gt;if you change the order of the last lines, the attach operation will not work &lt;/li&gt; &lt;/ul&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1859167416855250911-7436577266764902000?l=groglogs.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/cjXq5cSG132Saf4A5O46eEKAYgo/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/cjXq5cSG132Saf4A5O46eEKAYgo/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/cjXq5cSG132Saf4A5O46eEKAYgo/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/cjXq5cSG132Saf4A5O46eEKAYgo/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;</description><link>http://feedproxy.google.com/~r/groglogs/~3/teptqLxRmUs/send-mail-with-attachment-via-php-using.html</link><author>noreply@blogger.com (Stefano Ghio)</author><thr:total>0</thr:total><feedburner:origLink>http://groglogs.blogspot.com/2011/05/send-mail-with-attachment-via-php-using.html</feedburner:origLink></item></channel></rss>

