Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] Saving information from several pointcuts to an ObjectOutputStream

This sounds like a Singleton pattern me.  You could create a different class
that is a Singleton that holds the static reference to the
ObjectOutputStream.  Then just have your pointcut get the object Singleton
instance and have it write the data to the file.


On 2/19/09 6:07 PM, "baumar" <mbjava@xxxxxxxxx> wrote:

> 
> Hi,
> 
> I'm trying to save information from several pointcut. More precise: I try to
> catch method call that eventually will match some conditions, write it to a
> class called DetailedSignature implements Serializable and save that
> information in one place.
> 
> As far as I - as aspectJ-newbie  - understood, I cannot open a file for the
> whole life of an aspect, as there is no constructor. Therefore I tried to
> use an ObjectOutputStream like this:
> 
> pointcut methodWithReturnValue() : (execution(!void
> *.*(..))&&(!within(org.test.serversimulation.DetailedSignature))
> &&(!within(org.test.serversimulation.SignatureCracker))
> &&(!within(junit.*)));
> 
>     after() returning(Object o) : methodWithReturnValue() {
> 
> try {
> File testDataFile = new File("serializedTest.data");
>        FileOutputStream fout = new FileOutputStream(testDataFile,
> true);
>        ObjectOutputStream oos = new ObjectOutputStream(fout);
>        oos.writeObject(detailedSignature);
>        oos.flush();
>        oos.close();
>        
>        System.out.println("wrote detailedSignature
> "+detailedSignature.toString());
>        }
>     catch (Exception e) { e.printStackTrace(); }
> }
> 
> The program runs fine and I actually can see the data I want in the file.
> But when I try to read it, I get the exception:
> 
> java.io.StreamCorruptedException: invalid type code: AC
> 
> Now I searched and found that this always seems to happen when trying to
> append to an ObjectOutputStream multiple times
> (http://forums.sun.com/thread.jspa?threadID=5177084)
> 
> Now I'm a bit at a loss. I was thinking of trying to write kind of
> bruteforce the information to a text file and based on that read and
> recreate the object manually, but that is certainly not very flexible.
> 
> Does anyone know a way how to keep the outputstream open and pass it to
> several matches of the pointcut?
> Or would you know a more elegant strategy of saving objects from within
> several matches of a pointcut?
> 
> Thanks for help
> 
> Mark
> 
> 
> 
> 
> (start of the file with captured method
> 
> ¬í sr +org.test.serversimulation.DetailedSignature˜Ë±W„çÅ
> Z isLiteralValueL allmodifierst Ljava/lang/String;L
> callingobjectClassnameq ~ L callingobjectMethodNameq ~ L
> callingobjectPackageq ~ L callingobjectPackageAndClassq ~ L
> callingobjectParametersq ~ L  modifierst Ljava/util/ArrayList;L
> parametersq ~ L returnValueClassq ~ L returnValuePackageq ~ L
> returnValuePackageAndClassq ~ L signatureLongStringq ~
> ... all methods catched appear in the file.

Ron DiFrango       
Manager and Architect  |  CapTech Ventures
(804) 855-9196-6308  |  rdifrango@xxxxxxxxxxxxxxxxxxx



Back to the top