KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > alfresco > repo > descriptor > DescriptorStartupLog


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.descriptor;
18
19 import java.security.Principal JavaDoc;
20 import java.util.Date JavaDoc;
21 import java.util.Map JavaDoc;
22
23 import org.alfresco.service.descriptor.Descriptor;
24 import org.alfresco.service.descriptor.DescriptorService;
25 import org.alfresco.service.license.LicenseDescriptor;
26 import org.apache.commons.logging.Log;
27 import org.apache.commons.logging.LogFactory;
28 import org.springframework.context.ApplicationEvent;
29 import org.springframework.context.ApplicationListener;
30 import org.springframework.context.event.ContextRefreshedEvent;
31
32
33 /**
34  * Provide a Repository Startup Log
35  *
36  * @author davidc
37  */

38 public class DescriptorStartupLog implements ApplicationListener
39 {
40     // Logger
41
private static final Log logger = LogFactory.getLog(DescriptorService.class);
42
43     // Dependencies
44
private DescriptorService descriptorService;
45
46     /**
47      * @param descriptorService Descriptor Service
48      */

49     public void setDescriptorService(DescriptorService descriptorService)
50     {
51         this.descriptorService = descriptorService;
52     }
53     
54     
55     /**
56      * @param event
57      */

58     public void onApplicationEvent(ApplicationEvent event)
59     {
60         if (event instanceof ContextRefreshedEvent)
61         {
62             //
63
// log output of VM stats
64
//
65
Map JavaDoc properties = System.getProperties();
66             String JavaDoc version = (properties.get("java.runtime.version") == null) ? "unknown" : (String JavaDoc)properties.get("java.runtime.version");
67             long maxHeap = Runtime.getRuntime().maxMemory();
68             float maxHeapMB = maxHeap / 1024l;
69             maxHeapMB = maxHeapMB / 1024l;
70             if (logger.isInfoEnabled())
71             {
72                 logger.info(String.format("Alfresco JVM - v%s; maximum heap size %.3fMB", version, maxHeapMB));
73             }
74             if (logger.isWarnEnabled())
75             {
76                 if (version.startsWith("1.2") || version.startsWith("1.3") || version.startsWith("1.4"))
77                 {
78                     logger.warn(String.format("Alfresco JVM - WARNING - v1.5 is required; currently using v%s", version));
79                 }
80                 if (maxHeapMB < 500)
81                 {
82                     logger.warn(String.format("Alfresco JVM - WARNING - maximum heap size %.3fMB is less than recommended 512MB", maxHeapMB));
83                 }
84             }
85
86             // Log License Descriptors (if applicable)
87
LicenseDescriptor license = descriptorService.getLicenseDescriptor();
88             if (license != null && logger.isInfoEnabled())
89             {
90                 String JavaDoc subject = license.getSubject();
91                 String JavaDoc msg = "Alfresco license: " + subject;
92                 String JavaDoc holder = getHolderOrganisation(license.getHolder());
93                 if (holder != null)
94                 {
95                     msg += " granted to " + holder;
96                 }
97                 Date JavaDoc validUntil = license.getValidUntil();
98                 if (validUntil != null)
99                 {
100                     Integer JavaDoc days = license.getDays();
101                     Integer JavaDoc remainingDays = license.getRemainingDays();
102                     
103                     msg += " limited to " + days + " days expiring " + validUntil + " (" + remainingDays + " days remaining)";
104                 }
105                 else
106                 {
107                     msg += " (does not expire)";
108                 }
109                 
110                 
111                 logger.info(msg);
112             }
113             
114             // Log Repository Descriptors
115
if (logger.isInfoEnabled())
116             {
117                 Descriptor serverDescriptor = descriptorService.getServerDescriptor();
118                 Descriptor installedRepoDescriptor = descriptorService.getInstalledRepositoryDescriptor();
119                 String JavaDoc serverEdition = serverDescriptor.getEdition();
120                 String JavaDoc serverVersion = serverDescriptor.getVersion();
121                 int serverSchemaVersion = serverDescriptor.getSchema();
122                 String JavaDoc installedRepoVersion = installedRepoDescriptor.getVersion();
123                 int installedSchemaVersion = installedRepoDescriptor.getSchema();
124                 logger.info(String.format("Alfresco started (%s): Current version %s schema %d - Installed version %s schema %d",
125                    serverEdition, serverVersion, serverSchemaVersion, installedRepoVersion, installedSchemaVersion));
126             }
127         }
128     }
129     
130     
131     /**
132      * Get Organisation from Principal
133      *
134      * @param holderPrincipal
135      * @return organisation
136      */

137     private String JavaDoc getHolderOrganisation(Principal JavaDoc holderPrincipal)
138     {
139         String JavaDoc holder = null;
140         if (holderPrincipal != null)
141         {
142             holder = holderPrincipal.getName();
143             if (holder != null)
144             {
145                 String JavaDoc[] properties = holder.split(",");
146                 for (String JavaDoc property : properties)
147                 {
148                     String JavaDoc[] parts = property.split("=");
149                     if (parts[0].equals("O"))
150                     {
151                         holder = parts[1];
152                     }
153                 }
154             }
155         }
156         
157         return holder;
158     }
159     
160 }
Popular Tags