1   /*
2    * $Id: SaveCertificateCallback.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 edu.emory.mathcs.backport.java.util.concurrent.atomic.AtomicReference;
17  import edu.emory.mathcs.backport.java.util.concurrent.atomic.AtomicBoolean;
18  
19  public class SaveCertificateCallback implements EventCallback
20  {
21  
22      private AtomicReference certificates;
23      private AtomicBoolean called;
24  
25      public SaveCertificateCallback()
26      {
27          clear();
28      }
29  
30      public void eventReceived(MuleEventContext context, Object component) throws Exception
31      {
32          // putting a Thread.sleep here doesn't make this less reliable
33          // surely it would if it was thread scribbling?
34          certificates.set(context.getMessage().getProperty(SslConnector.LOCAL_CERTIFICATES));
35          called.set(true);
36      }
37  
38      public void clear()
39      {
40          certificates = new AtomicReference();
41          called = new AtomicBoolean(false);
42      }
43  
44      public boolean isCalled()
45      {
46          return called.get();
47      }
48  
49      public Object getCertificates()
50      {
51          return certificates.get();
52      }
53  
54  }