KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tc > net > core > TCCommFactory


1 /*
2  * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
3  */

4 package com.tc.net.core;
5
6 import com.tc.exception.TCInternalError;
7 import com.tc.util.runtime.IOFlavor;
8
9 import java.lang.reflect.Constructor JavaDoc;
10
11 /**
12  * Factory class for getting TCComm instances
13  *
14  * @author teck
15  */

16 public class TCCommFactory {
17
18   private static TCCommFactoryIF factory;
19
20   static {
21
22     Class JavaDoc clazz;
23     try {
24       if (IOFlavor.isNioAvailable()) {
25         clazz = Class.forName("com.tc.net.core.TCCommFactoryJDK14");
26       } else {
27         clazz = Class.forName("com.tc.net.core.TCCommFactoryJDK13");
28       }
29
30       Constructor JavaDoc cstr = clazz.getDeclaredConstructor(new Class JavaDoc[] {});
31       factory = (TCCommFactoryIF) cstr.newInstance(new Object JavaDoc[] {});
32     } catch (Exception JavaDoc e) {
33       throw new TCInternalError(e);
34     }
35   }
36
37   /**
38    * Get a new instance of a TCComm instance
39    *
40    * @param start true if <code>start()</code> should be called on the returned instance
41    * @return a new TCComm instance
42    */

43   public TCComm getInstance(boolean start) {
44     TCComm rv = factory.getInstance();
45
46     if (start) {
47       rv.start();
48     }
49
50     return rv;
51   }
52
53   /**
54    * Get a new instance of a TCComm instance that is already <code>start()</code> 'ed. This is equivalent to calling
55    * <code>TCCommFactory.getInstance(true)</code>
56    *
57    * @return a new TCComm instance
58    */

59   public TCComm getInstance() {
60     return getInstance(true);
61   }
62 }
Popular Tags