You could simply utilize serialization to perform this.  Here is a code
snippet I have in a utility class:

    public static Object deepCopy( Object incoming )
    throws java.io.IOException
    {
        try
        {
            // Serialize the incoming out to memory
            ByteArrayOutputStream serBaOut = new ByteArrayOutputStream();
            ObjectOutputStream serOut = new ObjectOutputStream( serBaOut );

            log.debug( "Starting serialization out..." );
            serOut.writeObject( incoming );
            log.debug( "Serialization out complete" );

            // Now, re-constitue the model from memory
            ByteArrayInputStream serBaIn = 
                    new ByteArrayInputStream( serBaOut.toByteArray() );
            ObjectInputStream serIn = new ObjectInputStream( serBaIn );

            log.debug( "Starting serialization in..." );
            Object outgoing = serIn.readObject();
            log.debug( "Serialization in complete" );

            return outgoing;
        }
        catch( ClassNotFoundException cnfe )
        {
            throw new java.io.IOException( "Unable to locate class on
reconstitution" );
        }
    }


-----Original Message-----
From: Damian ONeill [AePONA] [mailto:[EMAIL PROTECTED]
Sent: Tuesday, June 24, 2003 3:19 AM
To: Log4J Users List
Subject: Re: org.apache.log4j.spi.LoggingEvent


We are using log4j for logging events to an event manager via the socket 
appender.  The event manager is running in a separate process and uses a 
object input stream to build the received LoggingEvent.  The Event 
Manager has a internal event chain that event sinks can register with to 
receive the logging event.  The event sinks extend an adapter class that 
provides support for handling the event.  The adapter implements 
runnable and has a wait queue.  Each adapter is kicked off as a separate 
thread where the run method dequeues the event and passes it to an 
abstract method that the base class must implement.

I wish to clone the LoggingEvent so that each adapter sub class 
(separate thread) has its own copy of the event to do with as it wishes. 
 We invoke the Event Sinks dynamically so that the framework can be 
extended by third parties, therefore I cannot guarantee or impose 
restrictions on what the adapter class may do with the event.

Since the javadoc does not say whether the LoggingEvent is thread safe, 
the simplest way for me to guarantee no issues is to clone the event 
before I pass it to the adapter sub class.


Hope this helps,
Damian.




Ceki Gülcü wrote:

>
> Damian,
>
> LoggingEvent is not clonable and this has not been a problem this far.
> Can you please explain what you are trying to accomplish by cloning 
> LoggingEvent objects?
>
> At 04:38 PM 6/23/2003 +0000, you wrote:
>
>> Is there anyone on this list that can answer this question? or is the 
>> the developers list more suitable?
>>
>> Thanks.
>>
>> Damian ONeill [AePONA] wrote:
>>
>>> Can you please suggest the best way to clone a LoggingEvent?
>>>
>>> Thanks in advance,
>>> Damian ONeill.
>>>
>>
>> -- 
>> [EMAIL PROTECTED]
>>
>> Damian O'Neill
>> Software Engineer
>> AePONA Ltd,
>> Interpoint Building,
>> 20-24 York Street,
>> Belfast,
>> BT15 1AQ
>>
>> +44 (0) 2890 275246
>>
>> http://www.aepona.com
>>
>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: [EMAIL PROTECTED]
>> For additional commands, e-mail: [EMAIL PROTECTED]
>>
>
> -- 
> Ceki  For log4j documentation consider "The complete log4j manual"
>       ISBN: 2970036908  http://www.qos.ch/shop/products/clm_t.jsp
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>

-- 
[EMAIL PROTECTED]

Damian O'Neill
Software Engineer
AePONA Ltd,
Interpoint Building,
20-24 York Street,
Belfast,
BT15 1AQ

+44 (0) 2890 275246

http://www.aepona.com




---------------------------------------------------------------------
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