accumulo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From e..@apache.org
Subject git commit: ACCUMULO-1295 use Property.createInstanceFromPropertyName in most Reflection calls
Date Thu, 24 Oct 2013 16:28:45 GMT
Updated Branches:
  refs/heads/master 821ecec33 -> acf81db0d


ACCUMULO-1295 use Property.createInstanceFromPropertyName in most Reflection calls


Project: http://git-wip-us.apache.org/repos/asf/accumulo/repo
Commit: http://git-wip-us.apache.org/repos/asf/accumulo/commit/acf81db0
Tree: http://git-wip-us.apache.org/repos/asf/accumulo/tree/acf81db0
Diff: http://git-wip-us.apache.org/repos/asf/accumulo/diff/acf81db0

Branch: refs/heads/master
Commit: acf81db0d636987bbe15b10f31d6c260bcf83f6b
Parents: 821ecec
Author: Eric Newton <eric.newton@gmail.com>
Authored: Thu Oct 24 12:29:00 2013 -0400
Committer: Eric Newton <eric.newton@gmail.com>
Committed: Thu Oct 24 12:29:00 2013 -0400

----------------------------------------------------------------------
 .../accumulo/server/fs/VolumeManagerImpl.java   |  6 +----
 .../apache/accumulo/server/master/Master.java   | 25 ++------------------
 .../server/master/recovery/RecoveryManager.java |  2 +-
 .../server/monitor/servlets/trace/Basic.java    |  8 +------
 .../server/security/SecurityOperation.java      |  9 +++----
 .../TabletServerResourceManager.java            | 14 +----------
 6 files changed, 9 insertions(+), 55 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/accumulo/blob/acf81db0/server/src/main/java/org/apache/accumulo/server/fs/VolumeManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/main/java/org/apache/accumulo/server/fs/VolumeManagerImpl.java b/server/src/main/java/org/apache/accumulo/server/fs/VolumeManagerImpl.java
index 6c1d956..6c26c04 100644
--- a/server/src/main/java/org/apache/accumulo/server/fs/VolumeManagerImpl.java
+++ b/server/src/main/java/org/apache/accumulo/server/fs/VolumeManagerImpl.java
@@ -66,11 +66,7 @@ public class VolumeManagerImpl implements VolumeManager {
     this.defaultVolume = defaultVolume;
     this.conf = conf;
     ensureSyncIsEnabled();
-    try {
-      chooser = (VolumeChooser) this.getClass().getClassLoader().loadClass(conf.get(Property.GENERAL_VOLUME_CHOOSER)).newInstance();
-    } catch (Exception e) {
-      throw new RuntimeException(e);
-    }
+    chooser = Property.createInstanceFromPropertyName(conf, Property.GENERAL_VOLUME_CHOOSER,
VolumeChooser.class, new RandomVolumeChooser());
   }
 
   public static org.apache.accumulo.server.fs.VolumeManager getLocal() throws IOException
{

http://git-wip-us.apache.org/repos/asf/accumulo/blob/acf81db0/server/src/main/java/org/apache/accumulo/server/master/Master.java
----------------------------------------------------------------------
diff --git a/server/src/main/java/org/apache/accumulo/server/master/Master.java b/server/src/main/java/org/apache/accumulo/server/master/Master.java
index 9089975..22ac1f4 100644
--- a/server/src/main/java/org/apache/accumulo/server/master/Master.java
+++ b/server/src/main/java/org/apache/accumulo/server/master/Master.java
@@ -426,26 +426,6 @@ public class Master implements LiveTServerSet.Listener, TableObserver,
CurrentSt
     listener.waitForEvents(ONE_SECOND);
   }
   
-  // TODO: maybe move this to Property? We do this in TabletServer, Master, TableLoadBalancer,
etc. - ACCUMULO-1295
-  public static <T> T createInstanceFromPropertyName(AccumuloConfiguration conf, Property
property, Class<T> base, T defaultInstance) {
-    String clazzName = conf.get(property);
-    T instance = null;
-    
-    try {
-      Class<? extends T> clazz = AccumuloVFSClassLoader.loadClass(clazzName, base);
-      instance = clazz.newInstance();
-      log.info("Loaded class : " + clazzName);
-    } catch (Exception e) {
-      log.warn("Failed to load class ", e);
-    }
-    
-    if (instance == null) {
-      log.info("Using " + defaultInstance.getClass().getName());
-      instance = defaultInstance;
-    }
-    return instance;
-  }
-  
   public Master(ServerConfiguration config, VolumeManager fs, String hostname) throws IOException
{
     this.serverConfig = config;
     this.instance = config.getInstance();
@@ -459,7 +439,7 @@ public class Master implements LiveTServerSet.Listener, TableObserver,
CurrentSt
     ThriftTransportPool.getInstance().setIdleTime(aconf.getTimeInMillis(Property.GENERAL_RPC_TIMEOUT));
     security = AuditedSecurityOperation.getInstance();
     tserverSet = new LiveTServerSet(instance, config.getConfiguration(), this);
-    this.tabletBalancer = createInstanceFromPropertyName(aconf, Property.MASTER_TABLET_BALANCER,
TabletBalancer.class, new DefaultLoadBalancer());
+    this.tabletBalancer = Property.createInstanceFromPropertyName(aconf, Property.MASTER_TABLET_BALANCER,
TabletBalancer.class, new DefaultLoadBalancer());
     this.tabletBalancer.init(serverConfig);
   }
   
@@ -763,8 +743,7 @@ public class Master implements LiveTServerSet.Listener, TableObserver,
CurrentSt
     
     private void updatePlugins(String property) {
       if (property.equals(Property.MASTER_TABLET_BALANCER.getKey())) {
-        TabletBalancer balancer = createInstanceFromPropertyName(instance.getConfiguration(),
Property.MASTER_TABLET_BALANCER, TabletBalancer.class,
-            new DefaultLoadBalancer());
+        TabletBalancer balancer = Property.createInstanceFromPropertyName(instance.getConfiguration(),
Property.MASTER_TABLET_BALANCER, TabletBalancer.class, new DefaultLoadBalancer());
         balancer.init(serverConfig);
         tabletBalancer = balancer;
         log.info("tablet balancer changed to " + tabletBalancer.getClass().getName());

http://git-wip-us.apache.org/repos/asf/accumulo/blob/acf81db0/server/src/main/java/org/apache/accumulo/server/master/recovery/RecoveryManager.java
----------------------------------------------------------------------
diff --git a/server/src/main/java/org/apache/accumulo/server/master/recovery/RecoveryManager.java
b/server/src/main/java/org/apache/accumulo/server/master/recovery/RecoveryManager.java
index fb3cc8f..bdaa82b 100644
--- a/server/src/main/java/org/apache/accumulo/server/master/recovery/RecoveryManager.java
+++ b/server/src/main/java/org/apache/accumulo/server/master/recovery/RecoveryManager.java
@@ -155,7 +155,7 @@ public class RecoveryManager {
         synchronized (this) {
           if (!closeTasksQueued.contains(sortId) && !sortsQueued.contains(sortId))
{
             AccumuloConfiguration aconf = master.getConfiguration().getConfiguration();
-            LogCloser closer = Master.createInstanceFromPropertyName(aconf, Property.MASTER_WALOG_CLOSER_IMPLEMETATION,
LogCloser.class, new HadoopLogCloser());
+            LogCloser closer = Property.createInstanceFromPropertyName(aconf, Property.MASTER_WALOG_CLOSER_IMPLEMETATION,
LogCloser.class, new HadoopLogCloser());
             Long delay = recoveryDelay.get(sortId);
             if (delay == null) {
               delay = master.getSystemConfiguration().getTimeInMillis(Property.MASTER_RECOVERY_DELAY);

http://git-wip-us.apache.org/repos/asf/accumulo/blob/acf81db0/server/src/main/java/org/apache/accumulo/server/monitor/servlets/trace/Basic.java
----------------------------------------------------------------------
diff --git a/server/src/main/java/org/apache/accumulo/server/monitor/servlets/trace/Basic.java
b/server/src/main/java/org/apache/accumulo/server/monitor/servlets/trace/Basic.java
index 74e6f0f..2faa9b1 100644
--- a/server/src/main/java/org/apache/accumulo/server/monitor/servlets/trace/Basic.java
+++ b/server/src/main/java/org/apache/accumulo/server/monitor/servlets/trace/Basic.java
@@ -82,13 +82,7 @@ abstract class Basic extends BasicServlet {
         props.put(entry.getKey().substring(prefixLength), entry.getValue());
       }
       
-      AuthenticationToken token;
-      try {
-        token = AccumuloClassLoader.getClassLoader().loadClass(conf.get(Property.TRACE_TOKEN_TYPE)).asSubclass(AuthenticationToken.class).newInstance();
-      } catch (Exception e) {
-        throw new AccumuloException(e);
-      }
-      
+      AuthenticationToken token = Property.createInstanceFromPropertyName(conf, Property.TRACE_TOKEN_TYPE,
AuthenticationToken.class, new PasswordToken());
       token.init(props);
       at = token;
     }

http://git-wip-us.apache.org/repos/asf/accumulo/blob/acf81db0/server/src/main/java/org/apache/accumulo/server/security/SecurityOperation.java
----------------------------------------------------------------------
diff --git a/server/src/main/java/org/apache/accumulo/server/security/SecurityOperation.java
b/server/src/main/java/org/apache/accumulo/server/security/SecurityOperation.java
index 4713a3b..670a764 100644
--- a/server/src/main/java/org/apache/accumulo/server/security/SecurityOperation.java
+++ b/server/src/main/java/org/apache/accumulo/server/security/SecurityOperation.java
@@ -84,22 +84,19 @@ public class SecurityOperation {
   }
   
   protected static Authorizor getAuthorizor(String instanceId, boolean initialize) {
-    Authorizor toRet = Master.createInstanceFromPropertyName(ServerConfiguration.getSiteConfiguration(),
Property.INSTANCE_SECURITY_AUTHORIZOR,
-        Authorizor.class, ZKAuthorizor.getInstance());
+    Authorizor toRet = Property.createInstanceFromPropertyName(ServerConfiguration.getSiteConfiguration(),
Property.INSTANCE_SECURITY_AUTHORIZOR, Authorizor.class, ZKAuthorizor.getInstance());
     toRet.initialize(instanceId, initialize);
     return toRet;
   }
   
   protected static Authenticator getAuthenticator(String instanceId, boolean initialize)
{
-    Authenticator toRet = Master.createInstanceFromPropertyName(ServerConfiguration.getSiteConfiguration(),
Property.INSTANCE_SECURITY_AUTHENTICATOR,
-        Authenticator.class, ZKAuthenticator.getInstance());
+    Authenticator toRet = Property.createInstanceFromPropertyName(ServerConfiguration.getSiteConfiguration(),
Property.INSTANCE_SECURITY_AUTHENTICATOR, Authenticator.class, ZKAuthenticator.getInstance());
     toRet.initialize(instanceId, initialize);
     return toRet;
   }
   
   protected static PermissionHandler getPermHandler(String instanceId, boolean initialize)
{
-    PermissionHandler toRet = Master.createInstanceFromPropertyName(ServerConfiguration.getSiteConfiguration(),
Property.INSTANCE_SECURITY_PERMISSION_HANDLER,
-        PermissionHandler.class, ZKPermHandler.getInstance());
+    PermissionHandler toRet = Property.createInstanceFromPropertyName(ServerConfiguration.getSiteConfiguration(),
Property.INSTANCE_SECURITY_PERMISSION_HANDLER, PermissionHandler.class, ZKPermHandler.getInstance());
     toRet.initialize(instanceId, initialize);
     return toRet;
   }

http://git-wip-us.apache.org/repos/asf/accumulo/blob/acf81db0/server/src/main/java/org/apache/accumulo/server/tabletserver/TabletServerResourceManager.java
----------------------------------------------------------------------
diff --git a/server/src/main/java/org/apache/accumulo/server/tabletserver/TabletServerResourceManager.java
b/server/src/main/java/org/apache/accumulo/server/tabletserver/TabletServerResourceManager.java
index cc456c6..94e0285 100644
--- a/server/src/main/java/org/apache/accumulo/server/tabletserver/TabletServerResourceManager.java
+++ b/server/src/main/java/org/apache/accumulo/server/tabletserver/TabletServerResourceManager.java
@@ -202,19 +202,7 @@ public class TabletServerResourceManager {
     
     fileManager = new FileManager(conf, fs, maxOpenFiles, _dCache, _iCache);
     
-    try {
-      Class<? extends MemoryManager> clazz = AccumuloVFSClassLoader.loadClass(acuConf.get(Property.TSERV_MEM_MGMT),
MemoryManager.class);
-      memoryManager = clazz.newInstance();
-      memoryManager.init(conf);
-      log.debug("Loaded memory manager : " + memoryManager.getClass().getName());
-    } catch (Exception e) {
-      log.error("Failed to find memory manger in config, using default", e);
-    }
-    
-    if (memoryManager == null) {
-      memoryManager = new LargestFirstMemoryManager();
-    }
-    
+    memoryManager = Property.createInstanceFromPropertyName(acuConf, Property.TSERV_MEM_MGMT,
MemoryManager.class, new LargestFirstMemoryManager());
     memMgmt = new MemoryManagementFramework();
   }
   


Mime
View raw message