1   /*
2    * $Id: SaveCertificatesCallback.java 10790 2008-02-12 20:53:32Z dfeist $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSource, Inc.  All rights reserved.  http://www.mulesource.com
5    *
6    * The software in this package is published under the terms of the CPAL v1.0
7    * license, a copy of which has been included with this distribution in the
8    * LICENSE.txt file.
9    */
10  
11  package org.mule.transport.ssl;
12  
13  import org.mule.tck.functional.EventCallback;
14  import org.mule.api.MuleEventContext;
15  
16  import java.util.Collections;
17  import java.util.List;
18  import java.util.LinkedList;
19  
20  public class SaveCertificatesCallback implements EventCallback
21  {
22  
23      // volatile since this is a thread-safe collection (see holger)
24      private volatile List certificates;
25  
26      public SaveCertificatesCallback()
27      {
28          clear();
29      }
30  
31      public void eventReceived(MuleEventContext context, Object component) throws Exception
32      {
33          // putting a Thread.sleep here doesn't make this less reliable
34          // surely it would if it was thread scribbling?
35          Thread.sleep(100);
36          certificates.add(context.getMessage().getProperty(SslConnector.LOCAL_CERTIFICATES));
37      }
38  
39      public void clear()
40      {
41          certificates = Collections.synchronizedList(new LinkedList());
42      }
43  
44      public List getCertificates()
45      {
46          return certificates;
47      }
48  
49  }