List of usage examples for org.apache.commons.configuration AbstractConfiguration EVENT_SET_PROPERTY
int EVENT_SET_PROPERTY
To view the source code for org.apache.commons.configuration AbstractConfiguration EVENT_SET_PROPERTY.
Click Source Link
From source file:com.kixeye.chassis.support.logging.LoggingConfiguration.java
@PostConstruct public void initialize() { AbstractConfiguration config = ConfigurationManager.getConfigInstance(); if (config.containsKey(LOGBACK_CONFIG_NAME)) { System.out.println("Loading logging config."); reloadLogging(config.getString(LOGBACK_CONFIG_NAME)); }/* w w w. j av a 2 s.c o m*/ config.addConfigurationListener(new ConfigurationListener() { @Override public synchronized void configurationChanged(ConfigurationEvent event) { if ((event.getType() == AbstractConfiguration.EVENT_ADD_PROPERTY || event.getType() == AbstractConfiguration.EVENT_SET_PROPERTY) && StringUtils.equalsIgnoreCase(LOGBACK_CONFIG_NAME, event.getPropertyName()) && event.getPropertyValue() != null && !event.isBeforeUpdate()) { System.out.println("Reloading logging config."); reloadLogging((String) event.getPropertyValue()); } } }); ConfigurationListener flumeConfigListener = new ConfigurationListener() { private FlumeLoggerLoader loggerLoader = null; public synchronized void configurationChanged(ConfigurationEvent event) { if (!(event.getType() == AbstractConfiguration.EVENT_SET_PROPERTY || event.getType() == AbstractConfiguration.EVENT_ADD_PROPERTY || event.getType() == AbstractConfiguration.EVENT_CLEAR_PROPERTY)) { return; } if (FlumeLoggerLoader.FLUME_LOGGER_ENABLED_PROPERTY.equals(event.getPropertyName())) { if ("true".equals(event.getPropertyValue())) { if (loggerLoader == null) { // construct the bean loggerLoader = (FlumeLoggerLoader) applicationContext .getBean(FlumeLoggerLoader.PROTOTYPE_BEAN_NAME, "chassis"); } // else we already have one so we're cool } else { if (loggerLoader != null) { // delete the bean ConfigurableBeanFactory beanFactory = (ConfigurableBeanFactory) applicationContext .getParentBeanFactory(); beanFactory.destroyBean(FlumeLoggerLoader.PROTOTYPE_BEAN_NAME, loggerLoader); loggerLoader = null; } // else we don't have any so we're cool } } else if (FlumeLoggerLoader.RELOAD_PROPERTIES.contains(event.getPropertyValue())) { // only reload if we're already running - otherwise ignore if (loggerLoader != null) { // delete the bean ConfigurableBeanFactory beanFactory = (ConfigurableBeanFactory) applicationContext .getParentBeanFactory(); beanFactory.destroyBean(FlumeLoggerLoader.PROTOTYPE_BEAN_NAME, loggerLoader); loggerLoader = null; // construct the bean loggerLoader = (FlumeLoggerLoader) applicationContext .getBean(FlumeLoggerLoader.PROTOTYPE_BEAN_NAME, "chassis"); } // else we don't have any so we're cool } } }; config.addConfigurationListener(flumeConfigListener); flumeConfigListener.configurationChanged(new ConfigurationEvent(this, AbstractConfiguration.EVENT_SET_PROPERTY, FlumeLoggerLoader.FLUME_LOGGER_ENABLED_PROPERTY, config.getProperty(FlumeLoggerLoader.FLUME_LOGGER_ENABLED_PROPERTY), false)); }
From source file:com.kixeye.chassis.support.metrics.aws.MetricsCloudWatchConfiguration.java
private void addConfigurationListener() { final MetricsCloudWatchConfiguration springConfig = this; ConfigurationManager.getConfigInstance().addConfigurationListener(new ConfigurationListener() { @Override/*from w w w .j ava2s . c om*/ public synchronized void configurationChanged(ConfigurationEvent event) { if (!(event.getType() == AbstractConfiguration.EVENT_SET_PROPERTY || event.getType() == AbstractConfiguration.EVENT_ADD_PROPERTY)) { return; } if (event.isBeforeUpdate()) { return; } String name = event.getPropertyName(); if (!(name.equals(METRICS_AWS_ENABLED) || name.equals(METRICS_AWS_FILTER) || name.equals(METRICS_AWS_PUBLISH_INTERVAL) || name.equals(METRICS_AWS_PUBLISH_INTERVAL_UNIT))) { return; } springConfig.enabled = name.equals(METRICS_AWS_ENABLED) ? Boolean.parseBoolean(event.getPropertyValue() + "") : springConfig.enabled; destroyReporter(); if (springConfig.enabled) { createReporter(); } } }); }
From source file:com.kixeye.chassis.support.metrics.codahale.MetricsGraphiteConfiguration.java
private void addConfigurationListener() { final MetricsGraphiteConfiguration springConfig = this; ConfigurationManager.getConfigInstance().addConfigurationListener(new ConfigurationListener() { @Override/*from w ww. ja v a 2 s . com*/ public synchronized void configurationChanged(ConfigurationEvent event) { if (!(event.getType() == AbstractConfiguration.EVENT_SET_PROPERTY || event.getType() == AbstractConfiguration.EVENT_ADD_PROPERTY)) { return; } if (event.isBeforeUpdate()) { return; } String name = event.getPropertyName(); if (!(name.equals(METRICS_GRAPHITE_ENABLED) || name.equals(METRICS_GRAPHITE_SERVER) || name.equals(METRICS_GRAPHITE_PORT) || name.equals(METRICS_GRAPHITE_FILTER) || name.equals(METRICS_GRAPHITE_PUBLISH_INTERVAL) || name.equals(METRICS_GRAPHITE_PUBLISH_INTERVAL_UNIT))) { return; } springConfig.enabled = name.equals(METRICS_GRAPHITE_ENABLED) ? Boolean.parseBoolean(event.getPropertyValue() + "") : springConfig.enabled; destroyReporterLoader(); if (springConfig.enabled) { createReporterLoader(); } } }); }
From source file:com.netflix.config.ExpandedConfigurationListenerAdapter.java
/** * {@inheritDoc}/* w ww . j a va 2s .com*/ * @see ConfigurationListener#configurationChanged(ConfigurationEvent) */ @SuppressWarnings("unchecked") @Override public void configurationChanged(final ConfigurationEvent event) { if (pauseListener) { return; } // Grab the event information. Some values may be null. final Object source = event.getSource(); final String name = event.getPropertyName(); final Object value = event.getPropertyValue(); final boolean beforeUpdate = event.isBeforeUpdate(); // Handle the different types. switch (event.getType()) { // Key identifies node where the Collection of nodes was added, or // null if it was at the root. case HierarchicalConfiguration.EVENT_ADD_NODES: case ConcurrentCompositeConfiguration.EVENT_CONFIGURATION_SOURCE_CHANGED: expandedListener.configSourceLoaded(source); break; // Key identifies the individual property that was added. case AbstractConfiguration.EVENT_ADD_PROPERTY: expandedListener.addProperty(source, name, value, beforeUpdate); break; // Entire configuration was cleared. case AbstractConfiguration.EVENT_CLEAR: expandedListener.clear(source, beforeUpdate); break; // Key identifies the single property that was cleared. case AbstractConfiguration.EVENT_CLEAR_PROPERTY: expandedListener.clearProperty(source, name, value, beforeUpdate); break; // Key identifies the nodes that were removed, along with all its // children. Value after update is the List of nodes that were // cleared. Before the update, the value is null. case HierarchicalConfiguration.EVENT_CLEAR_TREE: // Ignore this. We rewrote the clearTree() method below. break; // The current property set is invalid. case CombinedConfiguration.EVENT_COMBINED_INVALIDATE: //listener.configSourceLoaded(source); break; // Key identifies the property that was read. case AbstractConfiguration.EVENT_READ_PROPERTY: break; // Key identifies the property that was set. case AbstractConfiguration.EVENT_SET_PROPERTY: expandedListener.setProperty(source, name, value, beforeUpdate); break; default: break; } }
From source file:com.netflix.config.ConcurrentMapConfigurationTest.java
@Test public void testListeners() { ConcurrentMapConfiguration conf = new ConcurrentMapConfiguration(); final AtomicReference<ConfigurationEvent> eventRef = new AtomicReference<ConfigurationEvent>(); conf.addConfigurationListener(new ConfigurationListener() { @Override/*from w w w . ja v a 2s . c o m*/ public void configurationChanged(ConfigurationEvent arg0) { eventRef.set(arg0); } }); conf.addProperty("key", "1"); assertEquals(1, conf.getInt("key")); ConfigurationEvent event = eventRef.get(); assertEquals("key", event.getPropertyName()); assertEquals("1", event.getPropertyValue()); assertTrue(conf == event.getSource()); assertEquals(AbstractConfiguration.EVENT_ADD_PROPERTY, event.getType()); conf.setProperty("key", "2"); event = eventRef.get(); assertEquals("key", event.getPropertyName()); assertEquals("2", event.getPropertyValue()); assertTrue(conf == event.getSource()); assertEquals(AbstractConfiguration.EVENT_SET_PROPERTY, event.getType()); conf.clearProperty("key"); event = eventRef.get(); assertEquals("key", event.getPropertyName()); assertNull(event.getPropertyValue()); assertTrue(conf == event.getSource()); assertEquals(AbstractConfiguration.EVENT_CLEAR_PROPERTY, event.getType()); conf.clear(); assertFalse(conf.getKeys().hasNext()); event = eventRef.get(); assertTrue(conf == event.getSource()); assertEquals(AbstractConfiguration.EVENT_CLEAR, event.getType()); }
From source file:com.jkoolcloud.tnt4j.repository.FileTokenRepository.java
@Override public void configurationChanged(ConfigurationEvent event) { if (event.isBeforeUpdate()) return;// www . j av a 2 s . c o m logger.log(OpLevel.DEBUG, "configurationChanged: type={0}, {1}:{2}", event.getType(), event.getPropertyName(), event.getPropertyValue()); switch (event.getType()) { case AbstractConfiguration.EVENT_ADD_PROPERTY: repListener.repositoryChanged(new TokenRepositoryEvent(event.getSource(), TokenRepository.EVENT_ADD_KEY, event.getPropertyName(), event.getPropertyValue(), null)); break; case AbstractConfiguration.EVENT_SET_PROPERTY: repListener.repositoryChanged(new TokenRepositoryEvent(event.getSource(), TokenRepository.EVENT_SET_KEY, event.getPropertyName(), event.getPropertyValue(), null)); break; case AbstractConfiguration.EVENT_CLEAR_PROPERTY: repListener.repositoryChanged(new TokenRepositoryEvent(event.getSource(), TokenRepository.EVENT_CLEAR_KEY, event.getPropertyName(), event.getPropertyValue(), null)); break; case AbstractConfiguration.EVENT_CLEAR: repListener.repositoryChanged(new TokenRepositoryEvent(event.getSource(), TokenRepository.EVENT_CLEAR, event.getPropertyName(), event.getPropertyValue(), null)); break; case AbstractFileConfiguration.EVENT_RELOAD: repListener.repositoryChanged(new TokenRepositoryEvent(event.getSource(), TokenRepository.EVENT_RELOAD, event.getPropertyName(), event.getPropertyValue(), null)); break; } }
From source file:nz.co.senanque.madura.configuration.MaduraConfiguration.java
private void invokeListeners() { if (m_configurationListeners != null) { try {/*ww w . j a v a 2 s. c o m*/ ConfigurationEvent event = new ConfigurationEvent(this, AbstractConfiguration.EVENT_SET_PROPERTY, null, this, false); for (ConfigurationListener listener : m_configurationListeners) { listener.configurationChanged(event); } } catch (Exception e) { throw new RuntimeException(e); } } }
From source file:pl.otros.logview.gui.LogViewPanel.java
public LogViewPanel(final LogDataTableModel dataTableModel, TableColumns[] visibleColumns, final OtrosApplication otrosApplication) { super();//from www . j a va 2 s. co m this.dataTableModel = dataTableModel; this.otrosApplication = otrosApplication; this.statusObserver = otrosApplication.getStatusObserver(); configuration = otrosApplication.getConfiguration(); AllPluginables allPluginable = AllPluginables.getInstance(); markersContainer = allPluginable.getMarkersContainser(); markersContainer.addListener(new MarkersMenuReloader()); logFiltersContainer = allPluginable.getLogFiltersContainer(); messageColorizersContainer = allPluginable.getMessageColorizers(); messageFormattersContainer = allPluginable.getMessageFormatters(); selectedMessageColorizersContainer = new PluginableElementsContainer<MessageColorizer>(); selectedMessageFormattersContainer = new PluginableElementsContainer<MessageFormatter>(); for (MessageColorizer messageColorizer : messageColorizersContainer.getElements()) { selectedMessageColorizersContainer.addElement(messageColorizer); } for (MessageFormatter messageFormatter : messageFormattersContainer.getElements()) { selectedMessageFormattersContainer.addElement(messageFormatter); } messageColorizersContainer.addListener( new SynchronizePluginableContainerListener<MessageColorizer>(selectedMessageColorizersContainer)); messageFormattersContainer.addListener( new SynchronizePluginableContainerListener<MessageFormatter>(selectedMessageFormattersContainer)); menuLabelFont = new JLabel().getFont().deriveFont(Font.BOLD); filtersPanel = new JPanel(); logsTablePanel = new JPanel(); logsMarkersPanel = new JPanel(); leftPanel = new JPanel(new MigLayout()); logDetailTextArea = new JTextPane(); logDetailTextArea.setEditable(false); MouseAdapter locationInfo = new LocationClickMouseAdapter(otrosApplication, logDetailTextArea); logDetailTextArea.addMouseMotionListener(locationInfo); logDetailTextArea.addMouseListener(locationInfo); logDetailTextArea.setBorder(BorderFactory.createTitledBorder("Details")); logDetailWithRulerScrollPane = RulerBarHelper.wrapTextComponent(logDetailTextArea); table = new JTableWith2RowHighliting(dataTableModel); // Initialize default column visible before creating context menu table.setColumnControlVisible(true); final ColumnControlButton columnControlButton = new ColumnControlButton(table) { @Override public void togglePopup() { populatePopup(); super.togglePopup(); } @Override protected List<Action> getAdditionalActions() { final List<Action> additionalActions = super.getAdditionalActions(); final AbstractAction saveLayout = new AbstractAction("Save current to new column layout", Icons.DISK) { @Override public void actionPerformed(ActionEvent actionEvent) { String newLayoutName = JOptionPane.showInputDialog(table, "New Layout name"); if (newLayoutName == null) { return; } newLayoutName = newLayoutName.trim(); LOGGER.info(String.format("Saving New column layout '%s'", newLayoutName)); ArrayList<String> visibleColNames = new ArrayList<String>(); for (TableColumn tc : table.getColumns()) { Object o = tc.getIdentifier(); if (!(o instanceof TableColumns)) { LOGGER.severe("TableColumn identifier of unexpected type: " + tc.getIdentifier().getClass().getName()); LOGGER.warning("Throw up a pop-up"); return; } TableColumns tcs = (TableColumns) o; visibleColNames.add(tcs.getName()); } ColumnLayout columnLayout = new ColumnLayout(newLayoutName, visibleColNames); final List<ColumnLayout> columnLayouts = LogTableFormatConfigView .loadColumnLayouts(configuration); columnLayouts.add(columnLayout); LogTableFormatConfigView.saveColumnLayouts(columnLayouts, configuration); populatePopup(); } }; additionalActions.add(saveLayout); final List<ColumnLayout> columnLayoutNames = LogTableFormatConfigView .loadColumnLayouts(configuration); for (final ColumnLayout columnLayout : columnLayoutNames) { final String name = columnLayout.getName(); final AbstractAction applyColumnLayout = new ApplyColumnLayoutAction(name, Icons.EDIT_COLUMNS, columnLayout, table); additionalActions.add(applyColumnLayout); } return additionalActions; } }; table.setColumnControl(columnControlButton); List<TableColumn> columns = table.getColumns(true); for (int i = 0; i < columns.size(); i++) { columns.get(i).setIdentifier(TableColumns.getColumnById(i)); } for (TableColumn tableColumn : columns) { table.getColumnExt(tableColumn.getIdentifier()).setVisible(false); } for (TableColumns tableColumns : visibleColumns) { table.getColumnExt(tableColumns).setVisible(true); } table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); updateColumnsSize(); table.setAutoResizeMode(JTable.AUTO_RESIZE_SUBSEQUENT_COLUMNS); final Renderers renderers = Renderers.getInstance(otrosApplication); table.setDefaultRenderer(String.class, new TableMarkDecoratorRenderer(renderers.getStringRenderer())); table.setDefaultRenderer(Object.class, new TableMarkDecoratorRenderer(table.getDefaultRenderer(Object.class))); table.setDefaultRenderer(Integer.class, new TableMarkDecoratorRenderer(table.getDefaultRenderer(Object.class))); table.setDefaultRenderer(Level.class, new TableMarkDecoratorRenderer(renderers.getLevelRenderer())); table.setDefaultRenderer(Date.class, new TableMarkDecoratorRenderer(renderers.getDateRenderer())); final TimeDeltaRenderer timeDeltaRenderer = new TimeDeltaRenderer(); table.getSelectionModel().addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent listSelectionEvent) { final int[] selectedRows = table.getSelectedRows(); if (selectedRows.length > 0) { final int selectedRow = selectedRows[selectedRows.length - 1]; final Date selectedDate = dataTableModel.getLogData(table.convertRowIndexToModel(selectedRow)) .getDate(); timeDeltaRenderer.setSelectedTimestamp(selectedDate); table.repaint(); } } }); table.setDefaultRenderer(TimeDelta.class, new TableMarkDecoratorRenderer(timeDeltaRenderer)); ((EventSource) configuration.getConfiguration()).addConfigurationListener(new ConfigurationListener() { @Override public void configurationChanged(ConfigurationEvent ce) { if (ce.getType() == AbstractConfiguration.EVENT_SET_PROPERTY && !ce.isBeforeUpdate()) { if (ce.getPropertyName().equals(ConfKeys.LOG_TABLE_FORMAT_DATE_FORMAT)) { table.setDefaultRenderer(Date.class, new TableMarkDecoratorRenderer(new DateRenderer( configuration.getString(ConfKeys.LOG_TABLE_FORMAT_DATE_FORMAT, "HH:mm:ss.SSS")))); updateTimeColumnSize(); } else if (ce.getPropertyName().equals(ConfKeys.LOG_TABLE_FORMAT_LEVEL_RENDERER)) { table.setDefaultRenderer(Level.class, new TableMarkDecoratorRenderer(new LevelRenderer(configuration.get( LevelRenderer.Mode.class, ConfKeys.LOG_TABLE_FORMAT_LEVEL_RENDERER, LevelRenderer.Mode.IconsOnly)))); updateLevelColumnSize(); } } } }); table.setDefaultRenderer(Boolean.class, new TableMarkDecoratorRenderer(table.getDefaultRenderer(Boolean.class))); table.setDefaultRenderer(Note.class, new TableMarkDecoratorRenderer(new NoteRenderer())); table.setDefaultRenderer(MarkerColors.class, new TableMarkDecoratorRenderer(new MarkTableRenderer())); table.setDefaultEditor(Note.class, new NoteTableEditor()); table.setDefaultEditor(MarkerColors.class, new MarkTableEditor(otrosApplication)); table.setDefaultRenderer(ClassWrapper.class, new TableMarkDecoratorRenderer(renderers.getClassWrapperRenderer())); sorter = new TableRowSorter<LogDataTableModel>(dataTableModel); for (int i = 0; i < dataTableModel.getColumnCount(); i++) { sorter.setSortable(i, false); } sorter.setSortable(TableColumns.ID.getColumn(), true); sorter.setSortable(TableColumns.TIME.getColumn(), true); table.setRowSorter(sorter); messageDetailListener = new MessageDetailListener(this, dateFormat, selectedMessageFormattersContainer, selectedMessageColorizersContainer); table.getSelectionModel().addListSelectionListener(messageDetailListener); dataTableModel.addNoteObserver(messageDetailListener); table.getSelectionModel().addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { boolean hasFocus = otrosApplication.getApplicationJFrame().isFocused(); final boolean enabled = otrosApplication.getConfiguration() .getBoolean(ConfKeys.JUMP_TO_CODE_AUTO_JUMP_ENABLED, false); if (hasFocus && enabled && !e.getValueIsAdjusting()) { try { final LogData logData = dataTableModel .getLogData(table.convertRowIndexToModel(e.getFirstIndex())); LocationInfo li = new LocationInfo(logData.getClazz(), logData.getMethod(), logData.getFile(), Integer.valueOf(logData.getLine())); final JumpToCodeService jumpToCodeService = otrosApplication.getServices() .getJumpToCodeService(); final boolean ideAvailable = jumpToCodeService.isIdeAvailable(); if (ideAvailable) { LOGGER.fine("Jumping to " + li); jumpToCodeService.jump(li); } } catch (Exception e1) { LOGGER.warning("Can't perform jump to code " + e1.getMessage()); } } } }); notes = new JTextArea(); notes.setEditable(false); NoteObserver allNotesObserver = new AllNotesTextAreaObserver(notes); dataTableModel.addNoteObserver(allNotesObserver); addFiltersGUIsToPanel(filtersPanel); logsTablePanel.setLayout(new BorderLayout()); logsTablePanel.add(new JScrollPane(table)); JPanel messageDetailsPanel = new JPanel(new BorderLayout()); messageDetailToolbar = new JToolBar("MessageDetail"); messageDetailsPanel.add(messageDetailToolbar, BorderLayout.NORTH); messageDetailsPanel.add(logDetailWithRulerScrollPane); initMessageDetailsToolbar(); jTabbedPane = new JTabbedPane(); jTabbedPane.add("Message detail", messageDetailsPanel); jTabbedPane.add("All notes", new JScrollPane(notes)); leftPanel.add(filtersPanel, "wrap, growx"); leftPanel.add(new JSeparator(SwingConstants.HORIZONTAL), "wrap,growx"); leftPanel.add(logsMarkersPanel, "wrap,growx"); JSplitPane splitPaneLogsTableAndDetails = new JSplitPane(JSplitPane.VERTICAL_SPLIT, logsTablePanel, jTabbedPane); JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, new JScrollPane(leftPanel, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED), splitPaneLogsTableAndDetails); splitPane.setOneTouchExpandable(true); this.setLayout(new BorderLayout()); this.add(splitPane); splitPaneLogsTableAndDetails.setDividerLocation(0.5d); splitPaneLogsTableAndDetails.setOneTouchExpandable(true); splitPane.setDividerLocation(leftPanel.getPreferredSize().width + 10); PopupListener popupListener = new PopupListener(new Callable<JPopupMenu>() { @Override public JPopupMenu call() throws Exception { return initTableContextMenu(); } }); table.addMouseListener(popupListener); table.addKeyListener(popupListener); PopupListener popupListenerMessageDetailMenu = new PopupListener(new Callable<JPopupMenu>() { @Override public JPopupMenu call() throws Exception { return initMessageDetailPopupMenu(); } }); logDetailTextArea.addMouseListener(popupListenerMessageDetailMenu); logDetailTextArea.addKeyListener(popupListenerMessageDetailMenu); dataTableModel.notifyAllNoteObservers(new NoteEvent(EventType.CLEAR, dataTableModel, null, 0)); table.addKeyListener(new MarkRowBySpaceKeyListener(otrosApplication)); initAcceptConditions(); }