Göktürk,

Thank you! I used #2 below and it worked well.  I was able to launch the
bundle, and I saw it output the traces I had been looking for.

On the first, if I remove the contents of the metadata.xml file, how can I
use iPOJO to generate the bundle?  If I leave in the <ipojo/> element, and
I run iPOJO's "Create Bundle", I get a warning: "Neither component types,
nor instances in /Users/mcook008/Workspaces/MyEclipse
8.6/iPojoTest/metadata.xml". Start and stop are not called, although the
class is marked with @Component and @Instantiate and start/stop is marked
with @Validate/@Invalidate.

Mike



On 10/11/12 8:54 PM, "Göktürk Gezer" <[email protected]> wrote:

>Well i thought at first that you didn't specify metadata.xml but i see now
>that you did. Mixing metadata.xml and annotations for one single component
>is a mistake. For same component you must go with one of them.
>
>So there are 2 different ways for you:
>
>1- Using only annotations: Just disable the metadata.xml (easily delete it
>or comment out the content ) and leave the annotations as it is.
>2- Using only medata.xml: If you want to use metadata.xml then remove all
>annotations including @validate and @invalidate and make sure your
>metadata.xml looks like this:
>
><ipojo>
><component className="cook.michael.MyComponentImpl">
>    <callback transition="validate" method="start"/>
>    <callback transition="invalidate" method="stop"/>
></component>
><instance component="cook.michael.MyComponentImpl"/>
></ipojo>
>
>Either way should bring you where you want. Just don't mix annotation and
>metadata usage for same component.
>
>Regards,
>Gokturk
>
>
>
>On Fri, Oct 12, 2012 at 3:32 AM, Cook, Michael J. (OCTO) <
>[email protected]> wrote:
>
>> Hi Göktürk,
>>
>> OK... Tried that.  Still the same thing.  There's not much to my code,
>>so
>> I'm including it below.  Please let me know if you see anything.
>>
>> Thank you for helping me,
>> Mike
>>
>>
>> MyComponentImpl.java:
>>
>> package cook.michael;
>>
>> import java.io.BufferedWriter;
>> import java.io.File;
>> import java.io.FileWriter;
>> import java.io.IOException;
>>
>> import org.apache.felix.ipojo.annotations.Component;
>> import org.apache.felix.ipojo.annotations.Invalidate;
>> import org.apache.felix.ipojo.annotations.Validate;
>> import org.apache.felix.ipojo.annotations.Instantiate;
>>
>> @Component
>> @Instantiate
>> public class MyComponentImpl {
>>
>>     @Validate
>>     public void start() throws IOException {
>>       System.err.println("Starting: " );
>>
>>         System.out.println("I'm starting...");
>>         try{
>>            // Create file
>>            FileWriter fstream = new
>>FileWriter("/Users/mcook008/out.txt");
>>            BufferedWriter out = new BufferedWriter(fstream);
>>            out.write("Hello Java");
>>            //Close the output stream
>>            out.close();
>>            }catch (Exception e){//Catch exception if any
>>            System.err.println("Error: " + e.getMessage());
>>            }
>>         throw new IOException() ;
>>     }
>>
>>     @Invalidate
>>     public void stop() {
>>         System.out.println("I'm leaving !");
>>     }
>> }
>>
>>
>> metadata.xml:
>>
>> <ipojo>
>> <component className="cook.michael.MyComponentImpl"/>
>> <instance component="cook.michael.MyComponentImpl"/>
>> </ipojo>
>>
>>
>>
>> iPojoTest.bnd:
>>
>> Import-Package: *
>> Export-Package: *
>> #Private-Package:
>>
>>
>> Generated manefest.mf:
>>
>> Manifest-Version: 1.0
>> Export-Package: org.apache.felix.ipojo.handler.temporal,org.apache.fel
>>  ix.ipojo.transaction,org.apache.felix.ipojo.extender,org.apache.felix
>>  .ipojo.whiteboard,org.apache.felix.ipojo.handlers.event,org.apache.fe
>>  lix.ipojo.handlers.jmx,org.apache.felix.ipojo.annotations,cook.michae
>>  l
>> iPOJO-Components: component { $classname="cook.michael.MyComponentImpl
>>  " manipulation { method { $name="$init" }method { $name="start" }meth
>>  od { $name="stop" }}}instance { $component="cook.michael.MyComponentI
>>  mpl" }component { $name="cook.michael.MyComponentImpl" $classname="co
>>  ok.michael.MyComponentImpl" $public="true" org.apache.felix.ipojo.ann
>>  otations:instantiate { }callback { $transition="invalidate" $method="
>>  stop" }callback { $transition="validate" $method="start" }manipulatio
>>  n { method { $name="$init" }method { $name="start" }method { $name="s
>>  top" }}}
>> Built-By: clement
>> Tool: Bnd-0.0.249
>> Bundle-Name: Apache Felix iPOJO Annotations
>> Created-By: 1.6.0_35 (Apple Inc.) & iPOJO
>> Bundle-Vendor: The Apache Software Foundation
>> Bundle-Version: 1.8.2
>> Build-Jdk: 1.6.0_31
>> Bnd-LastModified: 1350001458935
>> Bundle-ManifestVersion: 2
>> Bundle-Description: iPOJO Annotations
>> Bundle-License: http://www.apache.org/licenses/LICENSE-2.0.txt
>> Bundle-DocURL: http://felix.apache.org/site/how-to-use-ipojo-annotatio
>>  ns.html
>> Import-Package: org.osgi.service.log;version=1.3, org.apache.felix.ipo
>>  jo.handler.temporal, org.apache.felix.ipojo.transaction, org.apache.f
>>  elix.ipojo.architecture;version=0.9.0, org.apache.felix.ipojo.extende
>>  r, org.apache.felix.ipojo.whiteboard, org.apache.felix.ipojo;version=
>>  0.9.0, org.apache.felix.ipojo.handlers.event, org.apache.felix.ipojo.
>>  handlers.jmx, org.osgi.service.cm;version=1.2, org.apache.felix.ipojo
>>  .annotations, cook.michael
>> Bundle-SymbolicName: iPojoTest
>> Originally-Created-By: Apache Maven Bundle Plugin
>>
>>
>>
>>
>> On 10/11/12 7:54 PM, "Göktürk Gezer" <[email protected]> wrote:
>>
>> >Hi,
>> >
>> >First of all @Component is mandatory.(For annotation based usage).
>> >
>> >But this only defines your component. To actually instantiate it you
>> >should
>> >do it deliberately. One way to do that is using @Instantiate
>>annotation.
>> >
>> >So your code would be like:
>> >
>> >@Component
>> >@Instantiate
>> >public class foo{
>> >
>> >  @Validate
>> >  public void start()
>> >..........
>> >..........
>> >}
>> >
>> >On Fri, Oct 12, 2012 at 1:00 AM, Cook, Michael J. (OCTO) <
>> >[email protected]> wrote:
>> >
>> >> Sorry. Just rechecked. Used @ Component on the class. And
>> >> @Invalidate/@validate on the methods. Just tried removing the
>> >>@Component.
>> >> Same result. No output.
>> >>
>> >> Mike
>> >> Michael Cook
>> >> VP Technology Innovation
>> >> Comcast
>> >> One Comcast Center
>> >> Philadelphia, PA 19103
>> >> (o) 215-286-8260
>> >> (m) 609-458-0332
>> >>
>> >> ----- Original Message -----
>> >> From: Cook, Michael J. (OCTO)
>> >> Sent: Thursday, October 11, 2012 05:47 PM
>> >> To: '[email protected]' <[email protected]>
>> >> Subject: Re: Getting Started with iPOJO
>> >>
>> >> I used @validate/@invalidate alone.
>> >>
>> >> Mike
>> >>
>> >> Michael Cook
>> >> VP Technology Innovation
>> >> Comcast
>> >> One Comcast Center
>> >> Philadelphia, PA 19103
>> >> (o) 215-286-8260
>> >> (m) 609-458-0332
>> >>
>> >> ----- Original Message -----
>> >> From: Göktürk Gezer [mailto:[email protected]]
>> >> Sent: Thursday, October 11, 2012 05:39 PM
>> >> To: [email protected] <[email protected]>
>> >> Subject: Re: Getting Started with iPOJO
>> >>
>> >> Hi,
>> >>
>> >> I need to ask this first since it's not on your code snippet: Did you
>> >>use
>> >> @Component annotation for class where you've declared your start()
>> >>stop()
>> >> methods? Or did you use @Validate,@Invalidate alone?
>> >>
>> >>
>> >> *Regards,*
>> >> *Gokturk*
>> >>
>> >> On Thu, Oct 11, 2012 at 8:13 PM, Cook, Michael J. (OCTO) <
>> >> [email protected]> wrote:
>> >>
>> >> > Hi,
>> >> >
>> >> > I can't seem to find a good article that will help me resolve the
>> >> "getting
>> >> > started" issue I am facing.
>> >> >
>> >> > I am using Eclipse Juno (4.2) on my Mac.
>> >> >
>> >> > I have downloaded and installed the iPOJO eclipse plugin, from:
>> >> > http://clement.plop-plop.net/update/
>> >> >
>> >> > I have created a sample project following the instructions at:
>> >> > http://felix.apache.org/site/ipojo-eclipse-plug-in.html
>> >> >
>> >> > I have integrated Felix into Eclipse as a project, following
>> >>instructions
>> >> > here:
>> http://felix.apache.org/site/integrating-felix-with-eclipse.html
>> >> >
>> >> > I have downloaded the following iPOJO bundle:
>> >> > org.apache.felix.ipojo-1.8.2.jar
>> >> >
>> >> > I've launched Felix in the Eclipse console and I've installed the
>> >> > org.apache.felix.ipojo-1.8.2.jar bundle and started it.
>> >> >
>> >> > I've created a test bundle using iPOJO called iPojoTest.jar and
>>I've
>> >> > installed it and started it in the OSGI console.
>> >> >
>> >> > I run bundles in the console and I get:
>> >> >
>> >> > g! bundles
>> >> >
>> >> >     0|Active     |    0|org.apache.felix.framework (3.0.7)
>> >> >
>> >> >     1|Active     |    1|org.apache.felix.bundlerepository (1.6.2)
>> >> >
>> >> >     2|Active     |    1|org.apache.felix.gogo.command (0.6.1)
>> >> >
>> >> >     3|Active     |    1|org.apache.felix.gogo.runtime (0.6.1)
>> >> >
>> >> >     4|Active     |    1|org.apache.felix.gogo.shell (0.6.1)
>> >> >
>> >> >    12|Active     |    1|iPojoTest (1.4.0)
>> >> >
>> >> >    13|Active     |    1|org.apache.felix.ipojo (1.8.2)
>> >> >
>> >> >
>> >> > So, the bundle seems to have started.
>> >> >
>> >> > But I don't get any console output from my sysoutsŠ
>> >> >
>> >> > Here are the start() and stop() methods:
>> >> >
>> >> >
>> >> >  @Validate
>> >> >
>> >> >     public void start() throws IOException {
>> >> >
>> >> >                 System.out.println("I'm starting...");
>> >> >
>> >> >         try{
>> >> >
>> >> >           // Create file
>> >> >
>> >> >                   FileWriter fstream = new
>> >> > FileWriter("/Users/mcook008/out.txt");
>> >> >
>> >> >                   BufferedWriter out = new BufferedWriter(fstream);
>> >> >
>> >> >                   out.write("Hello Java");
>> >> >
>> >> >                   //Close the output stream
>> >> >
>> >> >                   out.close();
>> >> >
>> >> >                   }catch (Exception e){//Catch exception if any
>> >> >
>> >> >                   System.err.println("Error: " + e.getMessage());
>> >> >
>> >> >                   }
>> >> >
>> >> >         throw new IOException() ;
>> >> >
>> >> >     }
>> >> >
>> >> >     @Invalidate
>> >> >
>> >> >     public void stop() {
>> >> >
>> >> >         System.out.println("I'm leaving !");
>> >> >
>> >> >     }
>> >> >
>> >> >
>> >> >
>> >> >
>> >> > I added in the file write to see if a file would be created.  There
>> >>is no
>> >> > file created.  So, while OSGi thinks the bundle is ACTIVE, the
>>start
>> >> method
>> >> > appears never have to been called.
>> >> >
>> >> >
>> >> > Can anyone tell me what I may have done wrong or provide a clue as
>>to
>> >> what
>> >> > to look at to help diagnose the problem?
>> >> >
>> >> >
>> >> > Thanks,
>> >> >
>> >> > Mike
>> >> >
>> >> >
>> >>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: [email protected]
>> For additional commands, e-mail: [email protected]
>>
>>


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to