KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > alfresco > repo > importer > ImportTimerProgress


1 /*
2  * Copyright (C) 2005 Alfresco, Inc.
3  *
4  * Licensed under the Mozilla Public License version 1.1
5  * with a permitted attribution clause. You may obtain a
6  * copy of the License at
7  *
8  * http://www.alfresco.org/legal/license.txt
9  *
10  * Unless required by applicable law or agreed to in writing,
11  * software distributed under the License is distributed on an
12  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
13  * either express or implied. See the License for the specific
14  * language governing permissions and limitations under the
15  * License.
16  */

17 package org.alfresco.repo.importer;
18
19 import java.io.Serializable JavaDoc;
20 import java.util.Date JavaDoc;
21
22 import org.alfresco.service.cmr.repository.NodeRef;
23 import org.alfresco.service.cmr.security.AccessPermission;
24 import org.alfresco.service.cmr.view.ImporterProgress;
25 import org.alfresco.service.namespace.QName;
26 import org.apache.commons.logging.Log;
27 import org.apache.commons.logging.LogFactory;
28
29
30 /**
31  * Import Progress that provides import metrics.
32  *
33  * @author davidc
34  */

35 public class ImportTimerProgress implements ImporterProgress
36 {
37     private Date JavaDoc start = null;
38     private long nodeCreateCount = 0;
39     private long propCount = 0;
40     private long contentCount = 0;
41     private long nodeLinkedCount = 0;
42     private long aspectAdded = 0;
43     private long permissionCount = 0;
44     
45     private Log logger = LogFactory.getLog(ImportTimerProgress.class);;
46     
47     /**
48      * Construct
49      */

50     public ImportTimerProgress()
51     {
52     }
53
54     /**
55      * Construct
56      *
57      * @param logger
58      */

59     public ImportTimerProgress(Log logger)
60     {
61         this.logger = logger;
62     }
63     
64     /*
65      * (non-Javadoc)
66      * @see org.alfresco.service.cmr.view.ImporterProgress#started()
67      */

68     public void started()
69     {
70         start = new Date JavaDoc();
71         nodeCreateCount = 0;
72         propCount = 0;
73         contentCount = 0;
74         nodeLinkedCount = 0;
75         aspectAdded = 0;
76         permissionCount = 0;
77         
78         if (logger.isDebugEnabled())
79             logger.debug("Import started at " + start + " (" + start.getTime() + ")");
80     }
81
82     /*
83      * (non-Javadoc)
84      * @see org.alfresco.service.cmr.view.ImporterProgress#completed()
85      */

86     public void completed()
87     {
88         if (logger.isDebugEnabled())
89         {
90             Date JavaDoc end = new Date JavaDoc();
91             logger.debug("Import completed at " + end + " (" + end.getTime() + ")");
92             dumpStats(end);
93         }
94     }
95
96     /*
97      * (non-Javadoc)
98      * @see org.alfresco.service.cmr.view.ImporterProgress#error(java.lang.Throwable)
99      */

100     public void error(Throwable JavaDoc e)
101     {
102         if (logger.isDebugEnabled())
103         {
104             Date JavaDoc end = new Date JavaDoc();
105             logger.debug("Import completed at " + end + " (" + end.getTime() + ")");
106             logger.debug("Error occured at " + end + " (" + end.getTime() + ")");
107             logger.debug("Exception: " + e.toString());
108             dumpStats(end);
109         }
110     }
111
112     /*
113      * (non-Javadoc)
114      * @see org.alfresco.service.cmr.view.ImporterProgress#nodeCreated(org.alfresco.service.cmr.repository.NodeRef, org.alfresco.service.cmr.repository.NodeRef, org.alfresco.service.namespace.QName, org.alfresco.service.namespace.QName)
115      */

116     public void nodeCreated(NodeRef nodeRef, NodeRef parentRef, QName assocName, QName childName)
117     {
118         nodeCreateCount++;
119     }
120
121     /*
122      * (non-Javadoc)
123      * @see org.alfresco.service.cmr.view.ImporterProgress#nodeLinked(org.alfresco.service.cmr.repository.NodeRef, org.alfresco.service.cmr.repository.NodeRef, org.alfresco.service.namespace.QName, org.alfresco.service.namespace.QName)
124      */

125     public void nodeLinked(NodeRef nodeRef, NodeRef parentRef, QName assocName, QName childName)
126     {
127         nodeLinkedCount++;
128     }
129
130     /*
131      * (non-Javadoc)
132      * @see org.alfresco.service.cmr.view.ImporterProgress#contentCreated(org.alfresco.service.cmr.repository.NodeRef, java.lang.String)
133      */

134     public void contentCreated(NodeRef nodeRef, String JavaDoc sourceUrl)
135     {
136         contentCount++;
137     }
138
139     /*
140      * (non-Javadoc)
141      * @see org.alfresco.service.cmr.view.ImporterProgress#propertySet(org.alfresco.service.cmr.repository.NodeRef, org.alfresco.service.namespace.QName, java.io.Serializable)
142      */

143     public void propertySet(NodeRef nodeRef, QName property, Serializable JavaDoc value)
144     {
145         propCount++;
146     }
147
148     /*
149      * (non-Javadoc)
150      * @see org.alfresco.service.cmr.view.ImporterProgress#permissionSet(org.alfresco.service.cmr.repository.NodeRef, org.alfresco.service.cmr.security.AccessPermission)
151      */

152     public void permissionSet(NodeRef nodeRef, AccessPermission permission)
153     {
154         permissionCount++;
155     }
156
157     /*
158      * (non-Javadoc)
159      * @see org.alfresco.service.cmr.view.ImporterProgress#aspectAdded(org.alfresco.service.cmr.repository.NodeRef, org.alfresco.service.namespace.QName)
160      */

161     public void aspectAdded(NodeRef nodeRef, QName aspect)
162     {
163         aspectAdded++;
164     }
165
166     /**
167      * Dump statistics
168      *
169      * @param end
170      */

171     private void dumpStats(Date JavaDoc end)
172     {
173         if (logger.isDebugEnabled())
174         {
175             logger.debug("Import duration: " + (end.getTime() - start.getTime()) + " ms (Note: excluding commit time)");
176             logger.debug(" Nodes created: " + nodeCreateCount);
177             logger.debug(" Nodes linked: " + nodeLinkedCount);
178             logger.debug(" Aspects Added: " + aspectAdded);
179             logger.debug(" Properties set: " + propCount);
180             logger.debug(" Content set: " + contentCount);
181             logger.debug(" Permissions set: " + permissionCount);
182         }
183     }
184     
185 }
186
Popular Tags