List of usage examples for org.apache.commons.vfs2 FileChangeEvent getFile
public FileObject getFile()
From source file:com.wipro.ats.bdre.filemon.FileMonitor.java
@Override public void fileCreated(FileChangeEvent fileChangeEvent) throws Exception { FileObject obj = fileChangeEvent.getFile(); LOGGER.debug("File Created " + obj.getURL()); String dirPath = obj.getParent().getName().getPath(); LOGGER.debug("Full path " + obj.getName().getPath()); //Don't process anything with _archive if (dirPath.startsWith(monDir + "/" + archiveDirName)) { return;/*from w w w .ja va 2s . co m*/ } //Don't process directory if (obj.getType() == FileType.FOLDER) { return; } String fileName = obj.getName().getPath(); //Checking if the file name matches with the given pattern if (fileName.matches(filePattern)) { FileContent fc = obj.getContent(); LOGGER.debug("Matched File Pattern by " + fileName); putEligibleFileInfoInMap(fileName, fc); } }
From source file:com.wipro.ats.bdre.tdimport.FileMonitor.java
@Override public void fileCreated(FileChangeEvent fileChangeEvent) throws Exception { FileObject obj = fileChangeEvent.getFile(); LOGGER.debug("File Created " + obj.getURL()); String dirPath = obj.getParent().getName().getPath(); LOGGER.debug("Full path " + obj.getName().getPath()); //Don't process anything with _archive if (dirPath.startsWith(monDir + "/" + archiveDirName)) { return;/*from w ww. j a v a2 s . com*/ } //Don't process directory if (obj.getType() == FileType.FOLDER) { return; } String fileName = obj.getName().getPath(); //Checking if the file name matches with the given pattern if (fileName.matches(filePattern)) { FileContent fc = obj.getContent(); LOGGER.debug("Matched File Pattern by " + fileName); putEligibleFileInfoInMap(obj.getName().getBaseName(), fc); } }
From source file:io.kahu.hawaii.service.io.FileChangeListener.java
@Override public void fileChanged(FileChangeEvent fce) throws Exception { if (fce != null) { FileObject file = fce.getFile(); if (file.getContent().getSize() > maxFileLength) { logManager.error(new ServerException(ServerError.PARSER_MAX_FILESIZE_EXCEEDED, "Handler '" + handler + "', file at: " + file.getName().getPath())); } else {//w w w . j a v a2 s. co m logManager.info(CoreLoggers.SERVER, "File changed '" + fce.getFile().getName().getPath() + "'."); handler.handleFileChange(); } } }
From source file:com.carrotgarden.nexus.example.script.ScriptStorageImpl.java
@Override public void fileChanged(final FileChangeEvent e) throws Exception { if (!isScriptFile(e.getFile())) { return;/* w ww .j av a 2s .c o m*/ } updateScript(e.getFile()); }
From source file:com.carrotgarden.nexus.example.script.ScriptStorageImpl.java
@Override public void fileCreated(final FileChangeEvent e) throws Exception { if (!isScriptFile(e.getFile())) { return;/*from w w w . j a v a2 s. c o m*/ } updateScript(e.getFile()); }
From source file:com.carrotgarden.nexus.example.script.ScriptStorageImpl.java
@Override public void fileDeleted(final FileChangeEvent e) throws Exception { if (!isScriptFile(e.getFile())) { return;/*from w w w . j a v a 2s . com*/ } synchronized (scriptStore) { scriptStore.remove(getName(e.getFile().getName())); } }
From source file:com.web.server.EJBDeployer.java
@Override public void fileDeleted(FileChangeEvent arg0) throws Exception { FileObject baseFile = arg0.getFile(); if (baseFile.getName().getURI().endsWith(".jar")) { System.out.println(jarEJBMap.get(baseFile.getName().getURI())); EJBContext ejbContext = jarEJBMap.get(baseFile.getName().getURI()); if (ejbContext != null) { HashMap<String, Class> bindings = ejbContext.getRemoteBindings(); Set<String> remoteBindings = bindings.keySet(); Iterator<String> remoteBinding = remoteBindings.iterator(); while (remoteBinding.hasNext()) { String binding = (String) remoteBinding.next(); registry.unbind(binding); System.out.println("unregistering the class" + bindings.get(binding)); }/* w ww . j a v a 2s . c om*/ jarEJBMap.remove(baseFile.getName().getURI()); } ConcurrentHashMap<String, MDBContext> mdbContexts = jarMDBMap.get(baseFile.getName().getURI()); MDBContext mdbContext; if (mdbContexts != null) { Iterator<String> mdbnames = mdbContexts.keySet().iterator(); while (mdbnames.hasNext()) { String mdbname = mdbnames.next(); mdbContext = mdbContexts.get(mdbname); if (mdbContext.getConsumer() != null) { mdbContext.getConsumer().setMessageListener(null); mdbContext.getConsumer().close(); } if (mdbContext.getSession() != null) mdbContext.getSession().close(); if (mdbContext.getConnection() != null) mdbContext.getConnection().close(); mdbContexts.remove(mdbname); } jarMDBMap.remove(baseFile.getName().getURI()); } } System.out.println(baseFile.getName().getURI() + " UnDeployed"); }
From source file:com.web.server.EJBDeployer.java
@Override public void fileChanged(FileChangeEvent arg0) throws Exception { try {// ww w .ja v a 2 s . c o m FileObject baseFile = arg0.getFile(); EJBContext ejbContext; if (baseFile.getName().getURI().endsWith(".jar")) { fileDeleted(arg0); URLClassLoader classLoader = new URLClassLoader(new URL[] { new URL(baseFile.getName().getURI()) }, Thread.currentThread().getContextClassLoader()); ConfigurationBuilder config = new ConfigurationBuilder(); config.addUrls(ClasspathHelper.forClassLoader(classLoader)); config.addClassLoader(classLoader); org.reflections.Reflections reflections = new org.reflections.Reflections(config); EJBContainer container = EJBContainer.getInstance(baseFile.getName().getURI(), config); container.inject(); Set<Class<?>> cls = reflections.getTypesAnnotatedWith(Stateless.class); Set<Class<?>> clsMessageDriven = reflections.getTypesAnnotatedWith(MessageDriven.class); Object obj; System.gc(); if (cls.size() > 0) { ejbContext = new EJBContext(); ejbContext.setJarPath(baseFile.getName().getURI()); ejbContext.setJarDeployed(baseFile.getName().getBaseName()); for (Class<?> ejbInterface : cls) { //BeanPool.getInstance().create(ejbInterface); obj = BeanPool.getInstance().get(ejbInterface); System.out.println(obj); ProxyFactory factory = new ProxyFactory(); obj = UnicastRemoteObject.exportObject((Remote) factory.createWithBean(obj), servicesRegistryPort); String remoteBinding = container.getRemoteBinding(ejbInterface); System.out.println(remoteBinding + " for EJB" + obj); if (remoteBinding != null) { //registry.unbind(remoteBinding); registry.rebind(remoteBinding, (Remote) obj); ejbContext.put(remoteBinding, obj.getClass()); } //registry.rebind("name", (Remote) obj); } jarEJBMap.put(baseFile.getName().getURI(), ejbContext); } System.out.println("Class Message Driven" + clsMessageDriven); System.out.println("Class Message Driven" + clsMessageDriven); if (clsMessageDriven.size() > 0) { System.out.println("Class Message Driven"); MDBContext mdbContext; ConcurrentHashMap<String, MDBContext> mdbContexts; if (jarMDBMap.get(baseFile.getName().getURI()) != null) { mdbContexts = jarMDBMap.get(baseFile.getName().getURI()); } else { mdbContexts = new ConcurrentHashMap<String, MDBContext>(); } jarMDBMap.put(baseFile.getName().getURI(), 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("/", ".")); 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) { 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) { // TODO Auto-generated catch block e.printStackTrace(); } } } classLoader.close(); System.out.println(baseFile.getName().getURI() + " Deployed"); } } catch (Exception ex) { ex.printStackTrace(); } }
From source file:com.web.server.EJBDeployer.java
@Override public void fileCreated(FileChangeEvent arg0) throws Exception { try {/*from ww w . j a va 2 s . c o m*/ FileObject baseFile = arg0.getFile(); EJBContext ejbContext; if (baseFile.getName().getURI().endsWith(".jar")) { System.out.println(baseFile.getName().getURI()); URLClassLoader classLoader = new URLClassLoader(new URL[] { new URL(baseFile.getName().getURI()) }, Thread.currentThread().getContextClassLoader()); ConfigurationBuilder config = new ConfigurationBuilder(); config.addUrls(ClasspathHelper.forClassLoader(classLoader)); config.addClassLoader(classLoader); org.reflections.Reflections reflections = new org.reflections.Reflections(config); EJBContainer container = EJBContainer.getInstance(baseFile.getName().getURI(), config); container.inject(); Set<Class<?>> clsStateless = reflections.getTypesAnnotatedWith(Stateless.class); Set<Class<?>> clsMessageDriven = reflections.getTypesAnnotatedWith(MessageDriven.class); Object obj; System.gc(); if (clsStateless.size() > 0) { ejbContext = new EJBContext(); ejbContext.setJarPath(baseFile.getName().getURI()); ejbContext.setJarDeployed(baseFile.getName().getBaseName()); for (Class<?> ejbInterface : clsStateless) { //BeanPool.getInstance().create(ejbInterface); obj = BeanPool.getInstance().get(ejbInterface); System.out.println(obj); ProxyFactory factory = new ProxyFactory(); obj = UnicastRemoteObject.exportObject((Remote) factory.createWithBean(obj), servicesRegistryPort); String remoteBinding = container.getRemoteBinding(ejbInterface); System.out.println(remoteBinding + " for EJB" + obj); if (remoteBinding != null) { //registry.unbind(remoteBinding); registry.rebind(remoteBinding, (Remote) obj); ejbContext.put(remoteBinding, obj.getClass()); } //registry.rebind("name", (Remote) obj); } jarEJBMap.put(baseFile.getName().getURI(), ejbContext); } System.out.println("Class Message Driven" + clsMessageDriven); System.out.println("Class Message Driven" + clsMessageDriven); if (clsMessageDriven.size() > 0) { System.out.println("Class Message Driven"); MDBContext mdbContext; ConcurrentHashMap<String, MDBContext> mdbContexts; if (jarMDBMap.get(baseFile.getName().getURI()) != null) { mdbContexts = jarMDBMap.get(baseFile.getName().getURI()); } else { mdbContexts = new ConcurrentHashMap<String, MDBContext>(); } jarMDBMap.put(baseFile.getName().getURI(), 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("/", ".")); 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) { 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) { // TODO Auto-generated catch block e.printStackTrace(); } } } classLoader.close(); } System.out.println(baseFile.getName().getURI() + " Deployed"); } catch (Exception ex) { ex.printStackTrace(); } }
From source file:nl.b3p.kaartenbalie.service.MapFileListener.java
public void fileCreated(FileChangeEvent event) throws Exception { /*/*from w w w . j av a 2 s .c o m*/ * haal wms_online_resource op creer afkorting haal naam op --> roep * wmsaction aan met waardes */ File mapPath = new File(event.getFile().getURL().getFile()); if (mapPath.getName().indexOf(".map") != -1) { MapParser mapParser = new MapParser(mapPath); mapParser.parse(); Map<String, String> metadata = mapParser.getWebMetadata(); String url = metadata.get("wms_onlineresource"); String mapfilename = mapPath.getName().substring(0, mapPath.getName().indexOf(".")); mapfilename = mapfilename.replaceAll(" ", "_"); saveServiceProvider(url, mapfilename); } event.getFile().close(); }