List of usage examples for org.apache.commons.vfs2.impl VFSClassLoader VFSClassLoader
public VFSClassLoader(final FileObject[] files, final FileSystemManager manager, final ClassLoader parent) throws FileSystemException
From source file:com.app.server.EJBDeployer.java
public void deployEjbJar(URL url, StandardFileSystemManager manager, ClassLoader cL) { try {// w w w. ja va 2 s . c o m Vector<EJBContext> ejbContexts = null; EJBContext ejbContext; log.info(url.toURI()); ConcurrentHashMap<String, RARArchiveData> rardata = (ConcurrentHashMap<String, RARArchiveData>) mbeanServer .getAttribute(rarDeployerName, "RARArchiveDataAllAdapters"); Collection<RARArchiveData> rarcls = rardata.values(); Iterator<RARArchiveData> rarcl = rarcls.iterator(); RARArchiveData rararcdata; FileObject filetoScan = manager.resolveFile("jar:" + url.toString() + "!/"); HashSet<Class<?>>[] classes = new HashSet[] { new HashSet(), new HashSet(), new HashSet() }; VFSClassLoader jarCL; if (cL != null) { jarCL = new VFSClassLoader(new FileObject[] { filetoScan }, manager, cL); } else { jarCL = new VFSClassLoader(new FileObject[] { filetoScan }, manager, Thread.currentThread().getContextClassLoader()); } Class[] annot = new Class[] { Stateless.class, Stateful.class, MessageDriven.class }; scanJar(filetoScan, classes, annot, jarCL); Set<Class<?>> clsStateless = classes[0]; Set<Class<?>> clsStateful = classes[1]; Set<Class<?>> clsMessageDriven = classes[2]; //System.gc(); staticObjs = null; EJBContainer container = EJBContainer.getInstance(classes); container.inject(); if (clsStateless.size() > 0) { staticObjs = new Vector<Object>(); ejbContexts = new Vector<EJBContext>(); ejbContext = new EJBContext(); ejbContext.setJarPath(url.toString()); ejbContext.setJarDeployed(url.toString()); for (Class<?> ejbInterface : clsStateless) { BeanPool.getInstance().create(ejbInterface); obj = BeanPool.getInstance().get(ejbInterface); System.out.println(obj); ProxyFactory factory = new ProxyFactory(); proxyobj = factory.createWithBean(obj); staticObjs.add(proxyobj); Object unicastobj = UnicastRemoteObject.exportObject((Remote) proxyobj, 0); String remoteBinding = container.getRemoteBinding(ejbInterface); System.out.println(remoteBinding + " for EJB" + obj); if (remoteBinding != null) { // registry.unbind(remoteBinding); ic.bind("java:/" + remoteBinding, (Remote) unicastobj); ejbContext.put(remoteBinding, obj.getClass()); //registry.rebind(remoteBinding, (Remote)unicastobj); } // registry.rebind("name", (Remote) obj); } ejbContexts.add(ejbContext); jarEJBMap.put(url.toString(), ejbContexts); } if (clsStateful.size() > 0) { if (staticObjs == null) { staticObjs = new Vector<Object>(); } if (ejbContexts == null) { ejbContexts = new Vector<EJBContext>(); } ejbContext = new EJBContext(); ejbContext.setJarPath(url.toString()); ejbContext.setJarDeployed(url.toString()); StatefulBeanObject statefulBeanObject = null; for (Class<?> ejbInterface : clsStateful) { BeanPool.getInstance().create(ejbInterface); obj1 = ejbInterface.newInstance(); if (statefulBeanObject == null) { statefulBeanObject = new StatefulBeanObject(obj1, url.toString()); } else { statefulBeanObject.addStatefulSessionBeanObject(obj1); } //System.out.println(obj1); staticObjs.add(statefulBeanObject); /*Object unicastobj1 = UnicastRemoteObject.exportObject( (Remote) obj1, 0);*/ String remoteBinding = container.getRemoteBinding(ejbInterface); System.out.println(remoteBinding + " for EJB" + statefulBeanObject); if (remoteBinding != null) { // registry.unbind(remoteBinding); ic.bind("java:/" + remoteBinding, statefulBeanObject); ejbContext.put(remoteBinding, statefulBeanObject.getClass()); //registry.rebind(remoteBinding, (Remote)unicastobj1); } // registry.rebind("name", (Remote) obj); } ejbContexts.add(ejbContext); jarEJBMap.put(url.toString(), ejbContexts); } if (clsMessageDriven.size() > 0) { MDBContext mdbContext = null; ConcurrentHashMap<String, MDBContext> mdbContexts; if (jarMDBMap.get(url.toString()) != null) { mdbContexts = jarMDBMap.get(url.toString()); } else { mdbContexts = new ConcurrentHashMap<String, MDBContext>(); } jarMDBMap.put(url.toString(), mdbContexts); MDBContext mdbContextOld; for (Class<?> mdbBean : clsMessageDriven) { String classwithpackage = mdbBean.getName(); //System.out.println("class package" + classwithpackage); classwithpackage = classwithpackage.replace("/", "."); //System.out.println("classList:" // + classwithpackage.replace("/", ".")); final Class mdbBeanCls = mdbBean; try { if (!classwithpackage.contains("$")) { // System.out.println("executor class in ExecutorServicesConstruct"+executorServiceClass); // System.out.println(); if (!mdbBean.isInterface()) { Annotation[] classServicesAnnot = mdbBean.getDeclaredAnnotations(); if (classServicesAnnot != null) { Adapter adapter = null; ActivationConfigProperty[] activationConfigProp = null; for (int annotcount = 0; annotcount < classServicesAnnot.length; annotcount++) { if (classServicesAnnot[annotcount] instanceof Adapter) { adapter = (Adapter) classServicesAnnot[annotcount]; } else if (classServicesAnnot[annotcount] instanceof MessageDriven) { MessageDriven messageDrivenAnnot = (MessageDriven) classServicesAnnot[annotcount]; activationConfigProp = messageDrivenAnnot.activationConfig(); mdbContext = new MDBContext(); mdbContext.setMdbName(messageDrivenAnnot.name()); } } if (adapter != null) { /*if(rarcl.hasNext()){ rararcdata=rardata.get(rarDeployerName); rararcdata=rarcl.next(); //classLoader = new VFSClassLoader(rararcdata.getVfsClassLoader().getFileObjects(),rararcdata.getFsManager(),classLoader); FileObject[] fileObjectArray=rararcdata.getVfsClassLoader().getFileObjects(); //urlset.addAll(ClasspathHelper.forClassLoader(rararcdata.getVfsClassLoader())); for(FileObject fileObject:fileObjectArray){ fileObjects.add(fileObject.getURL()); //urlset.add(fileObject.getURL()); //System.out.println(Vfs.fromURL(fileObject.getURL()).getFiles().iterator().next().getRelativePath()); } classLoader = new URLClassLoader(fileObjects.toArray(new URL[fileObjects.size()]),Thread.currentThread().getContextClassLoader()); }*/ RARArchiveData rarArchiveData = (RARArchiveData) mbeanServer.invoke( rarDeployerName, "getRARArchiveData", new Object[] { adapter.adapterName() }, new String[] { String.class.getName() }); if (rarArchiveData == null) throw new Exception("RAR Adapter " + adapter.adapterName() + " Not found in deploy folder"); Class resourceAdapterClass = rarArchiveData.getResourceAdapterClass(); final ResourceAdapter resourceAdapter = (ResourceAdapter) resourceAdapterClass .newInstance(); Class activationSpecClass = rarArchiveData.getActivationspecclass(); final ActivationSpec activationSpec = (ActivationSpec) activationSpecClass .newInstance(); Vector<ConfigProperty> configProperties = rarArchiveData.getConfigPropery(); Integer configPropertyInteger; Long configPropertyLong; Boolean configPropertyBoolean; Method method; if (configProperties != null) { for (ConfigProperty configProperty : configProperties) { String property = configProperty.getConfigpropertyname(); property = (property.charAt(0) + "").toUpperCase() + property.substring(1); Class propertytype = Class .forName(configProperty.getConfigpropertytype()); try { method = activationSpecClass.getMethod("set" + property, propertytype); if (propertytype == String.class) { method.invoke(activationSpec, configProperty.getConfigpropertyvalue()); ConfigResourceAdapter(resourceAdapterClass, propertytype, resourceAdapter, property, configProperty); } else if (propertytype == Integer.class) { if (configProperty.getConfigpropertyvalue() != null && !configProperty.getConfigpropertyvalue() .equalsIgnoreCase("")) { configPropertyInteger = new Integer( configProperty.getConfigpropertyvalue()); try { method.invoke(activationSpec, configPropertyInteger); } catch (Exception ex) { method.invoke(activationSpec, configPropertyInteger.intValue()); } ConfigResourceAdapter(resourceAdapterClass, propertytype, resourceAdapter, property, configProperty); } } else if (propertytype == Long.class) { if (configProperty.getConfigpropertyvalue() != null && !configProperty.getConfigpropertyvalue() .equalsIgnoreCase("")) { configPropertyLong = new Long( configProperty.getConfigpropertyvalue()); method.invoke(activationSpec, configPropertyLong); ConfigResourceAdapter(resourceAdapterClass, propertytype, resourceAdapter, property, configProperty); } } else if (propertytype == Boolean.class) { if (configProperty.getConfigpropertyvalue() != null && !configProperty.getConfigpropertyvalue() .equalsIgnoreCase("")) { configPropertyBoolean = new Boolean( configProperty.getConfigpropertyvalue()); method.invoke(activationSpec, configPropertyBoolean); ConfigResourceAdapter(resourceAdapterClass, propertytype, resourceAdapter, property, configProperty); } } } catch (Exception ex) { try { if (propertytype == Integer.class) { method = activationSpecClass.getMethod("set" + property, int.class); if (configProperty.getConfigpropertyvalue() != null && !configProperty.getConfigpropertyvalue() .equalsIgnoreCase("")) { method = activationSpecClass .getMethod("set" + property, int.class); configPropertyInteger = new Integer( configProperty.getConfigpropertyvalue()); method.invoke(activationSpec, configPropertyInteger.intValue()); //ConfigResourceAdapter(resourceAdapterClass,propertytype,resourceAdapter,property,configProperty); } } else if (propertytype == Long.class) { if (configProperty.getConfigpropertyvalue() != null && !configProperty.getConfigpropertyvalue() .equalsIgnoreCase("")) { method = activationSpecClass .getMethod("set" + property, long.class); configPropertyLong = new Long( configProperty.getConfigpropertyvalue()); method.invoke(activationSpec, configPropertyLong.longValue()); //ConfigResourceAdapter(resourceAdapterClass,propertytype,resourceAdapter,property,configProperty); } } else if (propertytype == Boolean.class) { if (configProperty.getConfigpropertyvalue() != null && !configProperty.getConfigpropertyvalue() .equalsIgnoreCase("")) { method = activationSpecClass .getMethod("set" + property, boolean.class); configPropertyBoolean = new Boolean( configProperty.getConfigpropertyvalue()); method.invoke(activationSpec, configPropertyBoolean.booleanValue()); //ConfigResourceAdapter(resourceAdapterClass,propertytype,resourceAdapter,property,configProperty); } } ConfigResourceAdapter(resourceAdapterClass, propertytype, resourceAdapter, property, configProperty); } catch (Exception ex1) { ConfigResourceAdapter(resourceAdapterClass, propertytype, resourceAdapter, property, configProperty); } //log.error("Could not set Configuration for rar activation spec", ex); } } } for (ActivationConfigProperty activationConfig : activationConfigProp) { String property = activationConfig.propertyName(); property = (property.charAt(0) + "").toUpperCase() + property.substring(1); try { method = activationSpecClass.getMethod("set" + property, String.class); method.invoke(activationSpec, activationConfig.propertyValue()); } catch (Exception ex) { try { method = activationSpecClass.getMethod("set" + property, boolean.class); method.invoke(activationSpec, new Boolean(activationConfig.propertyValue())); } catch (Exception ex1) { method = activationSpecClass.getMethod("set" + property, Boolean.class); method.invoke(activationSpec, new Boolean(activationConfig.propertyValue())); } } } final Class listenerClass = rarArchiveData.getMessagelistenertype(); ClassLoader cCL = Thread.currentThread().getContextClassLoader(); Thread.currentThread() .setContextClassLoader(resourceAdapter.getClass().getClassLoader()); resourceAdapter .start(new com.app.server.connector.impl.BootstrapContextImpl()); MessageEndPointFactoryImpl messageEndPointFactoryImpl = new MessageEndPointFactoryImpl( listenerClass, mdbBeanCls.newInstance(), jarCL); resourceAdapter.endpointActivation(messageEndPointFactoryImpl, activationSpec); Thread.currentThread().setContextClassLoader(cCL); if (mdbContext != null) { mdbContext.setResourceAdapter(resourceAdapter); mdbContext.setMessageEndPointFactory(messageEndPointFactoryImpl); mdbContext.setActivationSpec(activationSpec); mdbContexts.put(mdbContext.getMdbName(), mdbContext); } /*new Thread(){ public void run(){ try { resourceAdapter.endpointActivation(new com.app.server.connector.impl.MessageEndPointFactoryImpl(listenerClass, mdbBeanCls.newInstance(),raCl), activationSpec); } catch ( Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } }.start();*/ } else { for (int annotcount = 0; annotcount < classServicesAnnot.length; annotcount++) { if (classServicesAnnot[annotcount] instanceof MessageDriven) { MessageDriven messageDrivenAnnot = (MessageDriven) classServicesAnnot[annotcount]; ActivationConfigProperty[] activationConfigProperties = messageDrivenAnnot .activationConfig(); mdbContext = new MDBContext(); mdbContext.setMdbName(messageDrivenAnnot.name()); for (ActivationConfigProperty activationConfigProperty : activationConfigProperties) { if (activationConfigProperty.propertyName() .equals(MDBContext.DESTINATIONTYPE)) { mdbContext.setDestinationType( activationConfigProperty.propertyValue()); } else if (activationConfigProperty.propertyName() .equals(MDBContext.DESTINATION)) { mdbContext.setDestination( activationConfigProperty.propertyValue()); } else if (activationConfigProperty.propertyName() .equals(MDBContext.ACKNOWLEDGEMODE)) { mdbContext.setAcknowledgeMode( activationConfigProperty.propertyValue()); } } if (mdbContext.getDestinationType().equals(Queue.class.getName())) { mdbContextOld = null; if (mdbContexts.get(mdbContext.getMdbName()) != null) { mdbContextOld = mdbContexts.get(mdbContext.getMdbName()); if (mdbContextOld != null && mdbContext.getDestination() .equals(mdbContextOld.getDestination())) { throw new Exception( "Only one MDB can listen to destination:" + mdbContextOld.getDestination()); } } mdbContexts.put(mdbContext.getMdbName(), mdbContext); Queue queue = (Queue) jms.lookup(mdbContext.getDestination()); Connection connection = connectionFactory .createConnection("guest", "guest"); connection.start(); Session session; if (mdbContext.getAcknowledgeMode() != null && mdbContext .getAcknowledgeMode().equals("Auto-Acknowledge")) { session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); } else { session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); } MessageConsumer consumer = session.createConsumer(queue); consumer.setMessageListener( (MessageListener) mdbBean.newInstance()); mdbContext.setConnection(connection); mdbContext.setSession(session); mdbContext.setConsumer(consumer); System.out.println("Queue=" + queue); } else if (mdbContext.getDestinationType() .equals(Topic.class.getName())) { if (mdbContexts.get(mdbContext.getMdbName()) != null) { mdbContextOld = mdbContexts.get(mdbContext.getMdbName()); if (mdbContextOld.getConsumer() != null) mdbContextOld.getConsumer().setMessageListener(null); if (mdbContextOld.getSession() != null) mdbContextOld.getSession().close(); if (mdbContextOld.getConnection() != null) mdbContextOld.getConnection().close(); } mdbContexts.put(mdbContext.getMdbName(), mdbContext); Topic topic = (Topic) jms.lookup(mdbContext.getDestination()); Connection connection = connectionFactory .createConnection("guest", "guest"); connection.start(); Session session; if (mdbContext.getAcknowledgeMode() != null && mdbContext .getAcknowledgeMode().equals("Auto-Acknowledge")) { session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); } else { session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); } MessageConsumer consumer = session.createConsumer(topic); consumer.setMessageListener( (MessageListener) mdbBean.newInstance()); mdbContext.setConnection(connection); mdbContext.setSession(session); mdbContext.setConsumer(consumer); System.out.println("Topic=" + topic); } } } } } } } } catch (Exception e) { log.error("Error : ", e); // TODO Auto-generated catch block //e.printStackTrace(); } } } if (staticObjs != null) { staticObjsEjbMap.put(url.toString(), staticObjs); } this.jarsDeployed.add(url.toURI().toString()); log.info(url.toString() + " Deployed"); } catch (Exception ex) { log.error("Error in deploying the jar file: " + url, ex); //ex.printStackTrace(); } finally { /*if(classLoader!=null){ try { classLoader.close(); } catch (Exception e) { log.error("error in closing the classloader", e); // TODO Auto-generated catch block //e.printStackTrace(); } ClassLoaderUtil.closeClassLoader(classLoader); }*/ } }
From source file:com.web.server.EARDeployer.java
/** * This method configures the executor services from the jar file. * //from w w w . ja va 2 s.c om * @param jarFile * @param classList * @throws FileSystemException */ public void deployExecutorServicesEar(String earFileName, FileObject earFile, StandardFileSystemManager fsManager) throws FileSystemException { try { System.out.println("EARFILE NAMEs=" + earFileName); CopyOnWriteArrayList<FileObject> fileObjects = new CopyOnWriteArrayList<FileObject>(); CopyOnWriteArrayList<FileObject> warObjects = new CopyOnWriteArrayList<FileObject>(); ConcurrentHashMap jarClassListMap = new ConcurrentHashMap(); CopyOnWriteArrayList<String> classList; obtainUrls(earFile, earFile, fileObjects, jarClassListMap, warObjects, fsManager); VFSClassLoader customClassLoaderBaseLib = new VFSClassLoader( fileObjects.toArray(new FileObject[fileObjects.size()]), fsManager, Thread.currentThread().getContextClassLoader()); VFSClassLoader customClassLoader = null; Set keys = jarClassListMap.keySet(); Iterator key = keys.iterator(); FileObject jarFileObject; ConcurrentHashMap classLoaderPath = new ConcurrentHashMap(); filesMap.put(earFileName, classLoaderPath); for (FileObject warFileObj : warObjects) { if (warFileObj.getName().getBaseName().endsWith(".war")) { //logger.info("filePath"+filePath); String filePath = scanDirectory + "/" + warFileObj.getName().getBaseName(); log.info(filePath); String fileName = warFileObj.getName().getBaseName(); WebClassLoader classLoader = new WebClassLoader(new URL[] {}); log.info(classLoader); warDeployer.deleteDir( new File(deployDirectory + "/" + fileName.substring(0, fileName.lastIndexOf(".war")))); new File(deployDirectory + "/" + fileName.substring(0, fileName.lastIndexOf(".war"))).mkdirs(); log.info(deployDirectory + "/" + fileName.substring(0, fileName.lastIndexOf(".war"))); urlClassLoaderMap.put( deployDirectory + "/" + fileName.substring(0, fileName.lastIndexOf(".war")), classLoader); classLoaderPath.put(warFileObj.getName().getBaseName(), deployDirectory + "/" + fileName.substring(0, fileName.lastIndexOf(".war"))); warDeployer.extractWar(new File(filePath), classLoader); if (exec != null) { exec.shutdown(); } new File(scanDirectory + "/" + warFileObj.getName().getBaseName()).delete(); exec = Executors.newSingleThreadScheduledExecutor(); exec.scheduleAtFixedRate(task, 0, 1000, TimeUnit.MILLISECONDS); } } for (int keyCount = 0; keyCount < keys.size(); keyCount++) { jarFileObject = (FileObject) key.next(); { classList = (CopyOnWriteArrayList<String>) jarClassListMap.get(jarFileObject); customClassLoader = new VFSClassLoader(jarFileObject, fsManager, customClassLoaderBaseLib); this.urlClassLoaderMap.put( scanDirectory + "/" + earFileName + "/" + jarFileObject.getName().getBaseName(), customClassLoader); classLoaderPath.put(jarFileObject.getName().getBaseName(), scanDirectory + "/" + earFileName + "/" + jarFileObject.getName().getBaseName()); for (int classCount = 0; classCount < classList.size(); classCount++) { String classwithpackage = classList.get(classCount).substring(0, classList.get(classCount).indexOf(".class")); classwithpackage = classwithpackage.replace("/", "."); // System.out.println("classList:"+classwithpackage.replace("/",".")); try { if (!classwithpackage.contains("$")) { /*System.out.println("EARFILE NAME="+fileName); System.out .println(scanDirectory + "/" + fileName + "/" + jarFileObject.getName() .getBaseName()); System.out.println(urlClassLoaderMap);*/ Class executorServiceClass = customClassLoader.loadClass(classwithpackage); Annotation[] classServicesAnnot = executorServiceClass.getDeclaredAnnotations(); if (classServicesAnnot != null) { for (int annotcount = 0; annotcount < classServicesAnnot.length; annotcount++) { if (classServicesAnnot[annotcount] instanceof RemoteCall) { RemoteCall remoteCall = (RemoteCall) classServicesAnnot[annotcount]; //registry.unbind(remoteCall.servicename()); System.out.println(remoteCall.servicename().trim()); try { for (int count = 0; count < 2; count++) { RemoteInterface reminterface = (RemoteInterface) UnicastRemoteObject .exportObject( (Remote) executorServiceClass.newInstance(), 0); registry.rebind(remoteCall.servicename().trim(), reminterface); } } catch (Exception ex) { ex.printStackTrace(); } } } } // System.out.println(executorServiceClass.newInstance()); // System.out.println("executor class in ExecutorServicesConstruct"+executorServiceClass); // System.out.println(); Method[] methods = executorServiceClass.getDeclaredMethods(); for (Method method : methods) { Annotation[] annotations = method.getDeclaredAnnotations(); for (Annotation annotation : annotations) { if (annotation instanceof ExecutorServiceAnnot) { ExecutorServiceAnnot executorServiceAnnot = (ExecutorServiceAnnot) annotation; ExecutorServiceInfo executorServiceInfo = new ExecutorServiceInfo(); executorServiceInfo.setExecutorServicesClass(executorServiceClass); executorServiceInfo.setMethod(method); executorServiceInfo.setMethodParams(method.getParameterTypes()); // System.out.println("serice name=" // + executorServiceAnnot // .servicename()); // System.out.println("method info=" // + executorServiceInfo); // System.out.println(method); // if(servicesMap.get(executorServiceAnnot.servicename())==null)throw // new Exception(); executorServiceMap.put(executorServiceAnnot.servicename(), executorServiceInfo); } } } } } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } } jarFileObject.close(); } for (FileObject fobject : fileObjects) { fobject.close(); } System.out.println("Channel unlocked"); earFile.close(); fsManager.closeFileSystem(earFile.getFileSystem()); // ClassLoaderUtil.closeClassLoader(customClassLoader); } catch (Exception ex) { ex.printStackTrace(); } }
From source file:org.apache.accumulo.start.classloader.vfs.AccumuloReloadingVFSClassLoader.java
public AccumuloReloadingVFSClassLoader(String uris, FileSystemManager vfs, ReloadingClassLoader parent, long monitorDelay, boolean preDelegate) throws FileSystemException { this.uris = uris; this.parent = parent; this.preDelegate = preDelegate; ArrayList<FileObject> pathsToMonitor = new ArrayList<FileObject>(); files = AccumuloVFSClassLoader.resolve(vfs, uris, pathsToMonitor); if (preDelegate) cl = new VFSClassLoader(files, vfs, parent.getClassLoader()); else// w ww .j a va 2 s . c om cl = new PostDelegatingVFSClassLoader(files, vfs, parent.getClassLoader()); monitor = new DefaultFileMonitor(this); monitor.setDelay(monitorDelay); monitor.setRecursive(false); for (FileObject file : pathsToMonitor) { monitor.addFile(file); log.debug("monitoring " + file); } monitor.start(); }
From source file:org.apache.accumulo.start.classloader.vfs.AccumuloVFSClassLoader.java
public static ClassLoader getClassLoader() throws IOException { ReloadingClassLoader localLoader = loader; while (null == localLoader) { synchronized (lock) { if (null == loader) { FileSystemManager vfs = generateVfs(); // Set up the 2nd tier class loader if (null == parent) { parent = AccumuloClassLoader.getClassLoader(); }// www .ja v a2 s . c o m FileObject[] vfsCP = resolve(vfs, AccumuloClassLoader.getAccumuloString(VFS_CLASSLOADER_SYSTEM_CLASSPATH_PROPERTY, "")); if (vfsCP.length == 0) { localLoader = createDynamicClassloader(parent); loader = localLoader; return localLoader.getClassLoader(); } // Create the Accumulo Context ClassLoader using the DEFAULT_CONTEXT localLoader = createDynamicClassloader(new VFSClassLoader(vfsCP, vfs, parent)); loader = localLoader; // An HDFS FileSystem and Configuration object were created for each unique HDFS namespace in the call to resolve above. // The HDFS Client did us a favor and cached these objects so that the next time someone calls FileSystem.get(uri), they // get the cached object. However, these objects were created not with the system VFS classloader, but the classloader above // it. We need to override the classloader on the Configuration objects. Ran into an issue were log recovery was being attempted // and SequenceFile$Reader was trying to instantiate the key class via WritableName.getClass(String, Configuration) for (FileObject fo : vfsCP) { if (fo instanceof HdfsFileObject) { String uri = fo.getName().getRootURI(); Configuration c = new Configuration(true); c.set(FileSystem.FS_DEFAULT_NAME_KEY, uri); FileSystem fs = FileSystem.get(c); fs.getConf().setClassLoader(loader.getClassLoader()); } } } } } return localLoader.getClassLoader(); }
From source file:org.apache.metron.common.utils.VFSClassloaderUtil.java
/** * Create a classloader backed by a virtual filesystem which can handle the following URI types: * * res - resource files//from www . j a va 2 s . c o m * * jar * * tar * * bz2 * * tgz * * zip * * HDFS * * FTP * * HTTP/S * * file * @param paths A set of comma separated paths. The paths are URIs or URIs with a regex pattern at the end. * @return A classloader object if it can create it * @throws FileSystemException */ public static Optional<ClassLoader> configureClassloader(String paths) throws FileSystemException { if (paths.trim().isEmpty()) { return Optional.empty(); } FileSystemManager vfs = generateVfs(); FileObject[] objects = resolve(vfs, paths); if (objects == null || objects.length == 0) { return Optional.empty(); } return Optional.of(new VFSClassLoader(objects, vfs, vfs.getClass().getClassLoader())); }