KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tc > net > groups > GroupManagerFactory


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

5 package com.tc.net.groups;
6
7 import com.tc.util.Assert;
8 import com.tc.util.runtime.Vm;
9
10 import java.io.IOException JavaDoc;
11 import java.io.InputStream JavaDoc;
12 import java.lang.reflect.Constructor JavaDoc;
13 import java.util.logging.LogManager JavaDoc;
14
15 public class GroupManagerFactory {
16
17   public static GroupManager createGroupManager() throws GroupException {
18     // Using reflection to avoid weird 1.4 / 1.5 project dependency issues !!
19
if (Vm.isJDK15Compliant()) {
20       return createTribesGroupManager();
21     } else {
22       return new SingleNodeGroupManager();
23     }
24   }
25
26   private static GroupManager createTribesGroupManager() throws GroupException {
27     initLoggerForJuli();
28     try {
29       Class JavaDoc clazz = Class.forName("com.tc.net.groups.TribesGroupManager");
30       Constructor JavaDoc constructor = clazz.getConstructor(new Class JavaDoc[0]);
31       return (GroupManager) constructor.newInstance(new Object JavaDoc[0]);
32     } catch (Exception JavaDoc e) {
33       throw new GroupException(e);
34     }
35   }
36
37   private static void initLoggerForJuli() {
38     System.setProperty("java.util.logging.config.class", LogConfig.class.getName());
39   }
40
41   public static final class LogConfig {
42     public LogConfig() throws SecurityException JavaDoc, IOException JavaDoc {
43       InputStream JavaDoc in = GroupManagerFactory.class.getResourceAsStream("/com/tc/logging/juli.properties");
44       Assert.assertNotNull(in);
45       LogManager.getLogManager().readConfiguration(in);
46     }
47   }
48
49 }
50
Popular Tags