~ubuntu-branches/ubuntu/maverick/eucalyptus/maverick

« back to all changes in this revision

Viewing changes to clc/modules/msgs/src/main/java/com/eucalyptus/util/HoldMe.java

  • Committer: Bazaar Package Importer
  • Author(s): Dave Walker (Daviey)
  • Date: 2010-07-21 17:27:10 UTC
  • mfrom: (1.1.38 upstream)
  • Revision ID: james.westby@ubuntu.com-20100721172710-7xv07dmdqgivc3t9
Tags: 2.0~bzr1211-0ubuntu1
* New major upstream version merge, 2.0 (r1211).
* debian/patches/:
  - 01-wsdl-stubs.patch, debian/wsdl.md5sums: wsdl stubs updated.
  - 02-Makefile.patch: Updated to reflect new code layout.
  - 07-local_support_euca_conf-in.patch: Updated to reflect new code layout.
  - 08-ubuntu-default-networking.patch: Refreshed.
  - 09-small-128-192MB.patch: Updated to point to new location.
  - 10-disable-iscsi.patch: Refreshed.
  - 11-state-cleanup-memleakfix.patch: Removed, fixed upstream.
  - 15-fix-default-ramdisk.patch: Updated to point to new location.
  - 16-kvm_libvirt_xml_default_use_kvm.patch: Updated to reflect changes.
  - 17-fix_walrus_OOM_errors.patch: Removed, fixed upstream.
  - 18-priv_security.patch: Updated to reflect upstream changes.
  - 20-brute-force-webui.patch: Updated to reflect upstream changes. 
  - 21-eucalyptus-1.7-with-gwt-1.6.4.patch: New patch, allows 
    eucalyptus-1.7 to be built against gwt 1.6.4. Based on patch courtesy 
    of Dmitrii Zagorodnov, upstream. (LP: #597330)
* debian/eucalyptus-java-common.links: 
  - Changed symlink for groovy, point to groovy.all.jar, making compatiable 
    with groovy versions >1.7. (LP: #595421)
  - Added ant.jar & jetty-rewrite-handler.jar as they are now required.
* debian/control
  - & debian/build-jars: Added libjavassist-java and libjetty-extra-java as 
    build dependencies.
  - Added libjetty-extra-java as a dependency of eucalyptus-java-common
* The binary resulting jar's have been renamed from eucalyptus-*-1.6.2.jar
  to eucalyptus-*-main.jar:    
  - debian/eucalyptus-cc.upstart
  - debian/eucalyptus-cloud.install
  - debian/eucalyptus-common.eucalyptus.upstart
  - debian/eucalyptus-java-common.install
  - debian/eucalyptus-network.upstart
  - debian/eucalyptus-sc.install
  - debian/eucalyptus-walrus.install
* debian/eucalyptus-java-common.install: New upstream jars that have been
  installed:
  - eucalyptus-db-hsqldb-ext-main.jar
  - eucalyptus-component-main.jar
* debian/control:
  - Updated Standards Version to 3.8.4 (no change)
  - Updated the upstream Homepage to: http://open.eucalyptus.com/
  - Changed Vcs-Bzr to reflect new location of Ubuntu hosted development branch.
  - Made the Build Dependency of groovy and the binary eucalyptus-java-common
    package depend on version >=1.7.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
package com.eucalyptus.util;
2
 
 
3
 
import java.io.ByteArrayInputStream;
4
 
import java.io.InputStream;
5
 
import java.util.concurrent.TimeUnit;
6
 
import java.util.concurrent.locks.Condition;
7
 
import java.util.concurrent.locks.Lock;
8
 
import java.util.concurrent.locks.ReentrantLock;
9
 
 
10
 
import javax.xml.stream.XMLInputFactory;
11
 
import javax.xml.stream.XMLOutputFactory;
12
 
import javax.xml.stream.XMLStreamException;
13
 
import javax.xml.stream.XMLStreamReader;
14
 
 
15
 
import org.apache.axiom.om.OMAbstractFactory;
16
 
import org.apache.axiom.om.OMException;
17
 
import org.apache.axiom.om.OMFactory;
18
 
import org.apache.axiom.om.impl.builder.StAXOMBuilder;
19
 
import org.apache.axiom.om.impl.dom.DOOMAbstractFactory;
20
 
import org.apache.axiom.soap.SOAPFactory;
21
 
 
22
 
public class HoldMe implements Lock {
23
 
  public static final String  OM_FACTORY_NAME_PROPERTY          = "om.factory";
24
 
  public static final String  SOAP11_FACTORY_NAME_PROPERTY      = "soap11.factory";
25
 
  public static final String  SOAP12_FACTORY_NAME_PROPERTY      = "soap12.factory";
26
 
  private static final String DEFAULT_OM_FACTORY_CLASS_NAME     = "org.apache.axiom.om.impl.llom.factory.OMLinkedListImplFactory";
27
 
  private static final String DEFAULT_SOAP11_FACTORY_CLASS_NAME = "org.apache.axiom.soap.impl.llom.soap11.SOAP11Factory";
28
 
  private static final String DEFAULT_SOAP12_FACTORY_CLASS_NAME = "org.apache.axiom.soap.impl.llom.soap12.SOAP12Factory";
29
 
  static {
30
 
    System.setProperty("javax.xml.stream.XMLInputFactory","com.ctc.wstx.stax.WstxInputFactory");
31
 
    System.setProperty("javax.xml.stream.XMLOutputFactory","com.ctc.wstx.stax.WstxOutputFactory");
32
 
    System.setProperty("javax.xml.stream.XMLEventFactory","com.ctc.wstx.stax.WstxEventFactory");
33
 
  }
34
 
  private static XMLInputFactory xmlInputFactory = XMLInputFactory.newInstance( );
35
 
  private static XMLOutputFactory xmlOutputFactory = XMLOutputFactory.newInstance( );
36
 
 
37
 
  public static Lock          canHas                            = maybeGetLock( );
38
 
  public static boolean       reuse                             = true;
39
 
 
40
 
  @Override
41
 
  public void lock( ) {}
42
 
 
43
 
  private static Lock maybeGetLock( ) {
44
 
    if ( reuse ) {
45
 
//      return new ReentrantLock( );
46
 
      return new HoldMe( );
47
 
    } else {
48
 
      return new HoldMe( );
49
 
    }
50
 
  }
51
 
 
52
 
  @Override
53
 
  public void lockInterruptibly( ) throws InterruptedException {}
54
 
 
55
 
  @Override
56
 
  public Condition newCondition( ) {
57
 
    return null;
58
 
  }
59
 
 
60
 
  @Override
61
 
  public boolean tryLock( ) {
62
 
    return true;
63
 
  }
64
 
 
65
 
  @Override
66
 
  public boolean tryLock( long arg0, TimeUnit arg1 ) throws InterruptedException {
67
 
    return true;
68
 
  }
69
 
 
70
 
  @Override
71
 
  public void unlock( ) {}
72
 
 
73
 
  public static OMFactory getDOOMFactory( ) {
74
 
    if ( reuse ) return DOOMAbstractFactory.getOMFactory( );
75
 
    else return new org.apache.axiom.om.impl.dom.factory.OMDOMFactory( );
76
 
  }
77
 
 
78
 
  public static SOAPFactory getDOOMSOAP11Factory( ) {
79
 
    if ( reuse ) return DOOMAbstractFactory.getSOAP11Factory( );
80
 
    else return new org.apache.axiom.soap.impl.dom.soap11.SOAP11Factory( );
81
 
  }
82
 
 
83
 
  public static SOAPFactory getDOOMSOAP12Factory( ) {
84
 
    if ( reuse ) return DOOMAbstractFactory.getSOAP12Factory( );
85
 
    else return new org.apache.axiom.soap.impl.dom.soap12.SOAP12Factory( );
86
 
  }
87
 
 
88
 
  public static SOAPFactory getOMSOAP11Factory( ) {
89
 
    if ( reuse ) return OMAbstractFactory.getSOAP11Factory( );
90
 
    String omFactory;
91
 
    try {
92
 
      omFactory = System.getProperty( SOAP11_FACTORY_NAME_PROPERTY );
93
 
      if ( omFactory == null || "".equals( omFactory ) ) {
94
 
        omFactory = DEFAULT_SOAP11_FACTORY_CLASS_NAME;
95
 
      }
96
 
    } catch ( SecurityException e ) {
97
 
      omFactory = DEFAULT_SOAP11_FACTORY_CLASS_NAME;
98
 
    }
99
 
    SOAPFactory defaultSOAP11OMFactory;
100
 
    try {
101
 
      defaultSOAP11OMFactory = ( SOAPFactory ) Class.forName( omFactory ).newInstance( );
102
 
    } catch ( InstantiationException e ) {
103
 
      throw new OMException( e );
104
 
    } catch ( IllegalAccessException e ) {
105
 
      throw new OMException( e );
106
 
    } catch ( ClassNotFoundException e ) {
107
 
      throw new OMException( e );
108
 
    }
109
 
    return defaultSOAP11OMFactory;
110
 
  }
111
 
 
112
 
  public static SOAPFactory getOMSOAP12Factory( ) {
113
 
    if ( reuse ) return OMAbstractFactory.getSOAP12Factory( );
114
 
    String omFactory;
115
 
    try {
116
 
      omFactory = System.getProperty( SOAP12_FACTORY_NAME_PROPERTY );
117
 
      if ( omFactory == null || "".equals( omFactory ) ) {
118
 
        omFactory = DEFAULT_SOAP12_FACTORY_CLASS_NAME;
119
 
      }
120
 
    } catch ( SecurityException e ) {
121
 
      omFactory = DEFAULT_SOAP12_FACTORY_CLASS_NAME;
122
 
    }
123
 
 
124
 
    SOAPFactory defaultSOAP12OMFactory;
125
 
    try {
126
 
      defaultSOAP12OMFactory = ( SOAPFactory ) Class.forName( omFactory ).newInstance( );
127
 
    } catch ( InstantiationException e ) {
128
 
      throw new OMException( e );
129
 
    } catch ( IllegalAccessException e ) {
130
 
      throw new OMException( e );
131
 
    } catch ( ClassNotFoundException e ) {
132
 
      throw new OMException( e );
133
 
    }
134
 
    return defaultSOAP12OMFactory;
135
 
  }
136
 
 
137
 
  public static OMFactory getOMFactory( ) {
138
 
    if ( reuse ) return OMAbstractFactory.getOMFactory( );
139
 
    String omFactory;
140
 
    try {
141
 
      omFactory = System.getProperty( OM_FACTORY_NAME_PROPERTY );
142
 
      if ( omFactory == null || "".equals( omFactory ) ) {
143
 
        omFactory = DEFAULT_OM_FACTORY_CLASS_NAME;
144
 
      }
145
 
    } catch ( SecurityException e ) {
146
 
      omFactory = DEFAULT_OM_FACTORY_CLASS_NAME;
147
 
    }
148
 
 
149
 
    OMFactory defaultOMFactory;
150
 
    try {
151
 
      defaultOMFactory = ( OMFactory ) Class.forName( omFactory ).newInstance( );
152
 
    } catch ( InstantiationException e ) {
153
 
      throw new OMException( e );
154
 
    } catch ( IllegalAccessException e ) {
155
 
      throw new OMException( e );
156
 
    } catch ( ClassNotFoundException e ) {
157
 
      throw new OMException( e );
158
 
    }
159
 
    return defaultOMFactory;
160
 
  }
161
 
 
162
 
  public static class ThrowAwayStAXOMBuilder extends StAXOMBuilder {
163
 
 
164
 
    public ThrowAwayStAXOMBuilder( XMLStreamReader parser ) {
165
 
      super( HoldMe.getOMFactory( ), parser );
166
 
    }
167
 
 
168
 
    public ThrowAwayStAXOMBuilder( OMFactory doomFactory, XMLStreamReader parser ) {
169
 
      super( doomFactory, parser );
170
 
    }
171
 
  }
172
 
 
173
 
  public static StAXOMBuilder getStAXOMBuilder( XMLStreamReader parser ) {
174
 
    if ( reuse ) return new StAXOMBuilder( parser );
175
 
    else return new ThrowAwayStAXOMBuilder( parser );
176
 
  }
177
 
 
178
 
  public static StAXOMBuilder getStAXOMBuilder( OMFactory doomFactory, XMLStreamReader xmlStreamReader ) {
179
 
    if ( reuse ) return new StAXOMBuilder( doomFactory, xmlStreamReader );
180
 
    else return new ThrowAwayStAXOMBuilder( doomFactory, xmlStreamReader );
181
 
  }
182
 
 
183
 
  public static XMLStreamReader getXMLStreamReader( InputStream in ) throws XMLStreamException {
184
 
    return HoldMe.getXMLInputFactory( ).createXMLStreamReader( in );
185
 
  }
186
 
 
187
 
  public static XMLStreamReader getXMLStreamReader( String text ) throws XMLStreamException {
188
 
    return HoldMe.getXMLInputFactory( ).createXMLStreamReader( new ByteArrayInputStream( text.getBytes( ) ) );
189
 
  }
190
 
 
191
 
  public static XMLInputFactory getXMLInputFactory( ) {
192
 
    return reuse?xmlInputFactory:XMLInputFactory.newInstance( );
193
 
  }
194
 
 
195
 
  public static XMLOutputFactory getXMLOutputFactory( ) {
196
 
    return reuse?xmlOutputFactory:XMLOutputFactory.newInstance( );
197
 
  }
198
 
 
199
 
}