1 17 package org.alfresco.repo.descriptor; 18 19 import java.security.Principal ; 20 import java.util.Date ; 21 import java.util.Map ; 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 38 public class DescriptorStartupLog implements ApplicationListener 39 { 40 private static final Log logger = LogFactory.getLog(DescriptorService.class); 42 43 private DescriptorService descriptorService; 45 46 49 public void setDescriptorService(DescriptorService descriptorService) 50 { 51 this.descriptorService = descriptorService; 52 } 53 54 55 58 public void onApplicationEvent(ApplicationEvent event) 59 { 60 if (event instanceof ContextRefreshedEvent) 61 { 62 Map properties = System.getProperties(); 66 String version = (properties.get("java.runtime.version") == null) ? "unknown" : (String )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 LicenseDescriptor license = descriptorService.getLicenseDescriptor(); 88 if (license != null && logger.isInfoEnabled()) 89 { 90 String subject = license.getSubject(); 91 String msg = "Alfresco license: " + subject; 92 String holder = getHolderOrganisation(license.getHolder()); 93 if (holder != null) 94 { 95 msg += " granted to " + holder; 96 } 97 Date validUntil = license.getValidUntil(); 98 if (validUntil != null) 99 { 100 Integer days = license.getDays(); 101 Integer 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 if (logger.isInfoEnabled()) 116 { 117 Descriptor serverDescriptor = descriptorService.getServerDescriptor(); 118 Descriptor installedRepoDescriptor = descriptorService.getInstalledRepositoryDescriptor(); 119 String serverEdition = serverDescriptor.getEdition(); 120 String serverVersion = serverDescriptor.getVersion(); 121 int serverSchemaVersion = serverDescriptor.getSchema(); 122 String 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 137 private String getHolderOrganisation(Principal holderPrincipal) 138 { 139 String holder = null; 140 if (holderPrincipal != null) 141 { 142 holder = holderPrincipal.getName(); 143 if (holder != null) 144 { 145 String [] properties = holder.split(","); 146 for (String property : properties) 147 { 148 String [] 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 |