KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > rift > coad > daemon > deployment > DeploymentDaemonImpl


1 /*
2  * Timer: The timer class
3  * Copyright (C) 2006-2007 Rift IT Contracting
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18  *
19  * DeploymentDaemonImpl.java
20  */

21
22 package com.rift.coad.daemon.deployment;
23
24 import com.rift.coad.lib.configuration.ConfigurationException;
25 import java.io.BufferedWriter JavaDoc;
26 import java.io.File JavaDoc;
27 import java.io.FileOutputStream JavaDoc;
28 import java.io.FileWriter JavaDoc;
29 import java.io.IOException JavaDoc;
30 import java.rmi.RemoteException JavaDoc;
31 import org.apache.log4j.Logger;
32
33 /**
34  * This Daemon allows users to remotely upload either Daemons or any other file
35  * to the Coadunation server.
36  *
37  * @author Glynn Chaldecott
38  */

39 public class DeploymentDaemonImpl implements DeploymentDaemon {
40     
41     protected Logger log =
42             Logger.getLogger(DeploymentDaemonImpl.class.getName());
43     
44     String JavaDoc coadLocal = "";
45     String JavaDoc coadunationTmp = "";
46     
47     /** Creates a new instance of DeploymentDaemonImpl */
48     public DeploymentDaemonImpl() throws Exception JavaDoc {
49         try {
50             com.rift.coad.lib.configuration.Configuration coadConfig =
51                     com.rift.coad.lib.configuration.ConfigurationFactory.
52                     getInstance().getConfig(com.rift.coad.daemon.deployment.
53
                    DeploymentDaemonImpl.class);
54             coadLocal = coadConfig.getString("coadunation_deploy");
55             coadunationTmp = coadConfig.getString("coadunation_temp");
56         } catch (ConfigurationException ex) {
57             log.error("Failed to set jython properties :" + ex.getMessage(),
58                     ex);
59             throw new Exception JavaDoc("Failed to set jython properties :" + ex);
60         }
61     }
62     
63     /**
64      * This method is used when a user wishes to remotely deploy a Daemon to
65      * Coadunation.
66      *
67      * @param file This is a byte[] containing the contents of the jar file.
68      * @param name This is the name of the Daemon.
69      * @param extension This is the file extension. It has to be .jar otherwise
70      * the method will throw an error.
71      */

72     public void daemonDeployer(byte[] file, String JavaDoc name)
73             throws RemoteException JavaDoc, DeploymentDaemonException {
74         try {
75             File JavaDoc temp = File.createTempFile(name, null);
76             FileOutputStream JavaDoc fos = new FileOutputStream JavaDoc(temp);
77             fos.write(file);
78             fos.close();
79             File JavaDoc supFile = new File JavaDoc(coadLocal + File.separator + name);
80             temp.renameTo(supFile);
81         } catch (IOException JavaDoc ex) {
82             log.error("Failed to copy file:" + ex, ex);
83         }
84     }
85     
86     /**
87      * This method is used when a user needs to remotely upload a file to the
88      * Coadunation server.
89      *
90      * @param file This is a byte[] containing the contents of the file.
91      * @param name This is the name of the file.
92      * @param location This is the location that the file will be stored.
93      * @param extension This is the file's extension.
94      */

95     public void copyFile(byte[] file, String JavaDoc name, String JavaDoc location)
96             throws RemoteException JavaDoc {
97         try {
98             File JavaDoc temp = File.createTempFile(name, null);
99             FileOutputStream JavaDoc fos = new FileOutputStream JavaDoc(temp);
100             fos.write(file);
101             fos.close();
102             File JavaDoc supFile = new File JavaDoc(location + File.separator + name);
103             temp.renameTo(supFile);
104         } catch (IOException JavaDoc ex) {
105             log.error("Failed to copy file:" + ex, ex);
106         }
107     }
108     
109 }
110
Popular Tags