/** * Overriden superclass method. Calls super.init() and also initializes the MuleContext * * @see SpringServicesContainer#init() */ public void init() throws PlatformException { super.init(); LinkedList<String> fileNamesList = new LinkedList<String>(); // add the common Mule beans file fileNamesList.add(SedaFrameworkConstants.COMMON_MULE_CONFIG); // add the Mule configurations containing Mule service definitions File[] serviceBeansFiles = FileLocator.findFiles(SedaFrameworkConstants.MULE_CONFIG); for (File serviceBeansFile : serviceBeansFiles) { fileNamesList.add(serviceBeansFile.getAbsolutePath()); } String[] muleConfigPaths = (String[]) fileNamesList.toArray(new String[0]); try { SpringXmlConfigurationBuilder springConfigBuilder = new SpringXmlConfigurationBuilder(muleConfigPaths); springConfigBuilder.setUseDefaultConfigResource( false); // turn off using the default config resource as we have a custom config defined // in SedaFrameworkConstants.COMMON_MULE_CONFIG springConfigBuilder.setParentContext(this.servicesContext); this.muleContext = new DefaultMuleContextFactory().createMuleContext(springConfigBuilder); this.muleContext.start(); } catch (Exception e) { LOGGER.error("Fatal error loading Mule configurations : " + e.getMessage(), e); throw new PlatformException("Fatal error loading Mule configurations : " + e.getMessage(), e); } }
/** Wraps the service statistics into JMX types */ private void populateServiceStatistics(boolean clearCollectedStats) { // clear existing stats in the TabularDataSupport and re-populate it with current data extracted // from service framework classes serviceInvocationStatistics.clear(); ServiceStatistics[] stats = getStats(clearCollectedStats); for (ServiceStatistics stat : stats) { Object[] statValues = new Object[attributeNames.length]; statValues[0] = stat.getServiceName(); statValues[1] = stat.getServiceVersion(); statValues[2] = stat.getStartupTimeStamp().getTime(); statValues[3] = stat.getLastCalledTimestamp() == null ? null : stat.getLastCalledTimestamp().getTime(); statValues[4] = stat.getActiveRequestsCount(); statValues[5] = stat.getTotalRequestsCount(); statValues[6] = stat.getAverageResponseTime(); statValues[7] = stat.getMinimumResponseTime(); statValues[8] = stat.getMaximumResponseTime(); statValues[9] = stat.getLastServiceRequestResponseTime(); statValues[10] = stat.getErrorRequestsCount(); statValues[11] = stat.getSuccessRequestsCount(); CompositeData compositeData; try { compositeData = new CompositeDataSupport(compositeType, attributeNames, statValues); serviceInvocationStatistics.put(compositeData); } catch (OpenDataException e) { // ideally we should not get this exception LOGGER.error( "Error constructing JMX data type from service statistics. Error is : " + e.getMessage(), e); } } }
/** * Interface method implementation. Creates and loads a Spring ApplicationContext for each * property specified in {@link #getAllProperties()} * * @see org.trpr.platform.runtime.spi.bootstrapext.BootstrapExtension#init() */ public void init() { // Iterate through the properties to get ApplicationContext name and the corresponding file name for (String key : this.getAllProperties().keySet()) { String fileName = this.getAllProperties().get(key); try { File springBeansFile = FileLocator.findUniqueFile(fileName); // add the "file:" prefix to file names to get around strange behavior of // FileSystemXmlApplicationContext that converts // absolute path to relative path // Set the commons beans context as the parent of all application contexts created through // this ApplicationContextFactory AbstractApplicationContext appContext = new FileSystemXmlApplicationContext( new String[] {FILE_PREFIX + springBeansFile.getAbsolutePath()}, getCommonBeansContext()); ApplicationContextFactory.appContextMap.put(key.toLowerCase(), appContext); } catch (Exception e) { // blanket catch for all checked and unchecked exceptions LOGGER.error( "Error loading ApplicationContext. [Name][Path] : [" + key + "][" + fileName + "].Error is : " + e.getMessage(), e); this.bootstrapOutcome = BootstrapExtension.VETO_BOOTSTRAP; return; } } }
/** * Overriden superclass method. Closes the MuleContext and then invokes {@link #resetContainer()} * * @see SpringServicesContainer#destroy() */ public void destroy() throws PlatformException { try { this.muleContext.stop(); } catch (MuleException e) { LOGGER.error("Fatal error stopping Mule : " + e.getMessage(), e); throw new PlatformException("Fatal error stopping Mule : " + e.getMessage(), e); } this.muleContext.dispose(); this.muleContext = null; // now invoke superclass clean up code this.resetContainer(); }
// static initializer block for composite and table type initialization static { try { compositeType = new CompositeType( "serviceStatistics", "Service statistics", attributeNames, attributeDescriptions, attributeTypes); tableType = new TabularType( "listOfServiceStatistics", "List of Service statistics", compositeType, indexNames); } catch (Exception e) { // ideally we should never get this error as it uses statically defined data elements LOGGER.error( "Error initializing JMX types used in service statistics monitoring : " + e.getMessage(), e); } }
public Object orToMysqlType(Column column) throws Exception { if (column instanceof BitColumn) { // This is in byte order BitColumn byteColumn = (BitColumn) column; byte[] byteArray = byteColumn.getValue(); return new String(byteArray); } else if (column instanceof BlobColumn) { BlobColumn blobColumn = (BlobColumn) column; byte[] byteArray = blobColumn.getValue(); return new String(byteArray); } else if (column instanceof DateColumn) { DateColumn dateColumn = (DateColumn) column; Date date = dateColumn.getValue(); return new java.sql.Date(date.getTime()); } else if (column instanceof DatetimeColumn) { DatetimeColumn dateTimeColumn = (DatetimeColumn) column; Date date = dateTimeColumn.getValue(); /** * Bug in OR for DateTIme and Time data-types. MilliSeconds is not available for these columns * but is set with currentMillis() wrongly. */ return new java.sql.Timestamp((date.getTime() / 1000) * 1000); } else if (column instanceof DecimalColumn) { DecimalColumn decimalColumn = (DecimalColumn) column; return decimalColumn.getValue(); } else if (column instanceof DoubleColumn) { DoubleColumn doubleColumn = (DoubleColumn) column; return doubleColumn.getValue(); } else if (column instanceof EnumColumn) { EnumColumn enumColumn = (EnumColumn) column; return enumColumn.getValue(); } else if (column instanceof FloatColumn) { FloatColumn floatColumn = (FloatColumn) column; return floatColumn.getValue(); } else if (column instanceof Int24Column) { Int24Column intColumn = (Int24Column) column; return intColumn.getValue(); } else if (column instanceof LongColumn) { LongColumn longColumn = (LongColumn) column; return longColumn.getValue(); } else if (column instanceof LongLongColumn) { LongLongColumn longLongColumn = (LongLongColumn) column; return longLongColumn.getValue(); } else if (column instanceof NullColumn) { return null; } else if (column instanceof SetColumn) { SetColumn setColumn = (SetColumn) column; return setColumn.getValue(); } else if (column instanceof ShortColumn) { ShortColumn shortColumn = (ShortColumn) column; return shortColumn.getValue(); } else if (column instanceof StringColumn) { StringColumn stringColumn = (StringColumn) column; return new String(stringColumn.getValue(), Charset.defaultCharset()); } else if (column instanceof TimeColumn) { TimeColumn timeColumn = (TimeColumn) column; Time time = timeColumn.getValue(); /** * There is a bug in OR where instead of using the default year as 1970, it is using 0070. * This is a temporary measure to resolve it by working around at this layer. The value * obtained from OR is subtracted from "0070-00-01 00:00:00" */ Calendar c = Calendar.getInstance(); c.set(70, 0, 1, 0, 0, 0); /** * round off the milli-seconds as TimeColumn type has only seconds granularity but Calendar * implementation includes milli-second (System.currentTimeMillis() at the time of * instantiation) */ long rawVal = (c.getTimeInMillis() / 1000) * 1000; long val2 = (time.getTime() / 1000) * 1000; return new java.sql.Time(val2 - rawVal); } else if (column instanceof TimestampColumn) { TimestampColumn timeStampColumn = (TimestampColumn) column; return timeStampColumn.getValue(); } else if (column instanceof TinyColumn) { TinyColumn tinyColumn = (TinyColumn) column; return tinyColumn.getValue(); } else if (column instanceof YearColumn) { YearColumn yearColumn = (YearColumn) column; return yearColumn.getValue(); } else { String message = "Unknown MySQL type in the event" + column.getClass() + " Object = " + column; LOGGER.error(message); throw new RuntimeException(message); } }