KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mmbase > module > builders > Netfiles


1 /*
2
3 This software is OSI Certified Open Source Software.
4 OSI Certified is a certification mark of the Open Source Initiative.
5
6 The license (Mozilla version 1.0) can be read at the MMBase site.
7 See http://www.MMBase.org/license
8
9 */

10 package org.mmbase.module.builders;
11
12 import org.mmbase.module.core.*;
13 import org.mmbase.util.logging.*;
14
15 /**
16  * The Netfiles builder stores information on files that need to be transferred
17  * to other servers.
18  * It is used in the CACHE PAGE routine, that is used to cache SCAN pages.
19  * Information in NetFiles is used by a number of VWMs (i.e. PageMaster and ImageMaster), which schedules the transfer
20  * of the files.<br />
21  * Each NetFile entry contains the following information:<br />
22  * <ul>
23  * <li><code>filename</code> : the name of the file</li>
24  * <li><code>mmserver</code> : the server that should handle the file transfer</li>
25  * <li><code>service</code> : the main 'service' to be performed.
26  * Together with subservice, this determines the VWM that handles the transfer,
27  * i.e. 'pages/main' is handled by the PageMaster VWM.</li>
28  * <li><code>subservice</code> : the subservice to perform. i.e. in PageMaster, 'main' determines mirror sites and
29  * schedules tasks for mirroring (by creating netfile entries), while 'mirror'
30  * performs the actual transfer to a mirror</li>
31  * Often one VWM handles mutliple subservices, but this is not a given.</li>
32  * <li><code>filesize</code> : the size of the file. Not currently used, value is always -1</li>
33  * <li><code>ctime</code> : probably the time of creation. Currently not used (for future development). </li>
34  * <li><code>ntime</code> : probably the last change time. Currently not used (for future development).</li>
35  * <li><code>status</code> : The state of the netfile entry. This can be a {@link #STATUS_REQUEST} when a file waits to be transferred,
36  * {@link #STATUS_ON_ITS_WAY} when it is being transferred, {@link #STATUS_DONE} when
37  * the transfer was handled, {@link #STATUS_CHANGED} when a change occured in a file, (indicating it may
38  * become elligible for resending), and {@link #STATUS_CALC_PAGE} when the page needs to be recalculated
39  * (by SCAN).</li>
40  * <li><code>crc</code> : Cyclic Redundancy Check. For use in checking file validity. Currently not used (for future development)</li>
41  * </ul>
42  *
43  * @author Daniel Ockeloen
44  * @version $Id: Netfiles.java,v 1.11 2003/03/10 11:50:20 pierre Exp $
45  */

46 public class Netfiles extends MMObjectBuilder {
47     /**
48      * Status for a netfile indicating a service request
49      */

50     public static final int STATUS_REQUEST = 1;
51     /**
52      * Status for a netfile indicating its request is being handled
53      */

54     public static final int STATUS_ON_ITS_WAY = 2;
55     /**
56      * Status for a netfile indicating its request has been handled
57      */

58     public static final int STATUS_DONE = 3;
59     /**
60      * Status for a netfile indicating a change
61      */

62     public static final int STATUS_CHANGED = 4;
63     /**
64      * Status for a netfile indicating a request to be recalculated
65      */

66     public static final int STATUS_CALC_PAGE = 5;
67
68     // Logger class
69
private static Logger log = Logging.getLoggerInstance(Netfiles.class.getName());
70
71     /**
72      * Reference to the NetFileServ builder
73      */

74     NetFileSrv netfilesrv;
75
76     /**
77      * What should a GUI display for this node/field combo.
78      * For "status', it returns a description of the current netfile state.
79      * Otherwise it returns <code>null</code>.
80      * @param node The node to display
81      * @param field the name field of the field to display
82      * @return the display of the node's field as a <code>String</code>, null if not specified
83      */

84     public String JavaDoc getGUIIndicator(String JavaDoc field,MMObjectNode node) {
85         if (field.equals("status")) {
86             int val=node.getIntValue("status");
87             switch(val) {
88                 case 1: return "Verzoek"; // return "Request";
89
case 2: return "Onderweg"; // return "On Its Way";
90
case 3: return "Gedaan"; // return "Done";
91
case 4: return "Aangepast"; // return "Changed";
92
case 5: return "CalcPage"; // return "Recalculate";
93
default: return "Onbepaald"; // return "Unknown";
94
}
95         }
96         return null;
97     }
98
99     /**
100      * Called when a remote node is changed.
101      * This routine invokes the NetFileServ builder to handle the change (which involves
102      * calling the VWM that handles the service).
103      * Only active for certain servers.
104      * The check what servers support this is currently specific for the VPRO and should be changed.
105      * @param number Number of the changed node as a <code>String</code>
106      * @param builder type of the changed node
107      * @param ctype command type, 'c'=changed, 'd'=deleted', 'r'=relations changed, 'n'=new
108      * @return <code>true</code> if maintenance was performed, <code>false</code> (the default) otherwise
109      */

110     public boolean nodeRemoteChanged(String JavaDoc machine, String JavaDoc number,String JavaDoc builder,String JavaDoc ctype) {
111         super.nodeRemoteChanged(machine, number,builder,ctype);
112         // vpro-thingy, has to go
113
if (mmb.getMachineName().equals("twohigh")) {
114             log.debug("Change : "+number+" "+builder+" "+ctype);
115             if (netfilesrv==null) {
116                 netfilesrv=(NetFileSrv)mmb.getMMObject("netfilesrv");
117                 if (netfilesrv!=null) netfilesrv.fileChange(number,ctype);
118             } else {
119                 netfilesrv.fileChange(number,ctype);
120            }
121         }
122         return true;
123     }
124
125     /**
126      * Called when a local node is changed.
127      * This routine invokes the NetFileServ builder to handle the change (which involves
128      * calling the VWM that handles the service).
129      * Only active for certain servers.
130      * The check what servers support this is currently specific for the VPRO and should be changed.
131      * @param number Number of the changed node as a <code>String</code>
132      * @param builder type of the changed node
133      * @param ctype command type, 'c'=changed, 'd'=deleted', 'r'=relations changed, 'n'=new
134      * @return <code>true</code> if maintenance was performed, <code>false</code> (the default) otherwise
135      */

136     public boolean nodeLocalChanged(String JavaDoc machine, String JavaDoc number,String JavaDoc builder,String JavaDoc ctype) {
137         super.nodeLocalChanged(machine, number,builder,ctype);
138         // vpro-thingy, has to go
139
if (mmb.getMachineName().equals("twohigh")) {
140             log.debug("Change : "+number+" "+builder+" "+ctype);
141             if (netfilesrv==null) {
142                 netfilesrv=(NetFileSrv)mmb.getMMObject("netfilesrv");
143                 if (netfilesrv!=null) netfilesrv.fileChange(number,ctype);
144             } else {
145                 netfilesrv.fileChange(number,ctype);
146             }
147         }
148         return true;
149     }
150 }
151
Popular Tags