Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
###
# #%L
# Bitrepository Alarm Service
# BitRepository Alarm Service
# %%
# Copyright (C) 2010 - 2013 The State and University Library, The Royal Library and The State Archives, Denmark
# %%
Expand Down
2 changes: 1 addition & 1 deletion bitrepository-alarm-service/src/main/assembly/assembly.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<!--
#%L
Bitrepository Reference Pillar
BitRepository Reference Pillar

$Id$
$HeadURL$
Expand Down
Original file line number Diff line number Diff line change
@@ -1,45 +1,47 @@
/*
* #%L
* bitrepository-access-client
*
*
* $Id$
* $HeadURL$
* %%
* Copyright (C) 2010 - 2011 The State and University Library, The Royal Library and The State Archives, Denmark
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 2.1 of the
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 2.1 of the
* License, or (at your option) any later version.
*
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Lesser Public License for more details.
*
* You should have received a copy of the GNU General Lesser Public
*
* You should have received a copy of the GNU General Lesser Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-2.1.html>.
* #L%
*/
package org.bitrepository.alarm;

/**
* Exception for the alarm module. Is thrown whenever a alarm cannot be handled.
* Exception for the alarm module. Is thrown whenever an alarm cannot be handled.
*/
@SuppressWarnings("serial")
public class AlarmException extends RuntimeException {
/**
* Constructor for this exception with both text message and a cause.
*
* @param message The message for the exception.
* @param cause The cause in the form of another Throwable which has triggered this exception.
* @param cause The cause in the form of another Throwable which has triggered this exception.
*/
public AlarmException(String message, Throwable cause) {
super(message, cause);
}

/**
* Constructor for this exception based on a text message.
*
* @param message The message for the exception.
*/
public AlarmException(String message) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,54 +8,55 @@
* Copyright (C) 2010 - 2011 The State and University Library, The Royal Library and The State Archives, Denmark
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 2.1 of the
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 2.1 of the
* License, or (at your option) any later version.
*
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Lesser Public License for more details.
*
* You should have received a copy of the GNU General Lesser Public
*
* You should have received a copy of the GNU General Lesser Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-2.1.html>.
* #L%
*/
package org.bitrepository.alarm;

import java.util.Collection;
import java.util.Date;

import org.bitrepository.alarm.handling.AlarmHandler;
import org.bitrepository.bitrepositoryelements.Alarm;
import org.bitrepository.bitrepositoryelements.AlarmCode;
import org.bitrepository.service.LifeCycledService;

import java.util.Collection;
import java.util.Date;

/**
* The interface for an alarm service
*/
public interface AlarmService extends LifeCycledService {
/**
* Adds a handler for a specific queue.
*
* Adds a handler for a specific queue.
*
* @param handler The handler for the Alarm messages.
*/
void addHandler(AlarmHandler handler);

/**
* Extracts the alarms based on the given optional restictions.
* @param componentID [OPTIONAL] The id of the component.
* @param alarmCode [OPTIONAL] The alarm code.
* @param minDate [OPTIONAL] The earliest date for the alarms.
* @param maxDate [OPTIONAL] The latest date for the alarms.
* @param fileID [OPTIONAL] The id of the file, which the alarms are connected.
* Extracts the alarms based on the given optional restrictions.
*
* @param componentID [OPTIONAL] The id of the component.
* @param alarmCode [OPTIONAL] The alarm code.
* @param minDate [OPTIONAL] The earliest date for the alarms.
* @param maxDate [OPTIONAL] The latest date for the alarms.
* @param fileID [OPTIONAL] The id of the file, which the alarms are connected.
* @param collectionID [OPTIONAL] the collectionID, for which alarms are from
* @param maxResults [OPTIONAL] The maximum number of alarms to retrieve from the store.
* @param ascending Whether the alarms should be delivered ascending.
* @param maxResults [OPTIONAL] The maximum number of alarms to retrieve from the store.
* @param ascending Whether the alarms should be delivered ascending.
* @return The requested collection of alarms from the store.
*/
Collection<Alarm> extractAlarms(String componentID, AlarmCode alarmCode, Date minDate, Date maxDate,
String fileID, String collectionID, Integer maxResults, boolean ascending);
Collection<Alarm> extractAlarms(String componentID, AlarmCode alarmCode, Date minDate, Date maxDate,
String fileID, String collectionID, Integer maxResults, boolean ascending);

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,22 @@
* Copyright (C) 2010 - 2011 The State and University Library, The Royal Library and The State Archives, Denmark
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 2.1 of the
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 2.1 of the
* License, or (at your option) any later version.
*
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Lesser Public License for more details.
*
* You should have received a copy of the GNU General Lesser Public
*
* You should have received a copy of the GNU General Lesser Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-2.1.html>.
* #L%
*/
package org.bitrepository.alarm;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.nio.file.Paths;
import java.util.Properties;

import org.bitrepository.alarm.handling.handlers.AlarmStorer;
import org.bitrepository.alarm.store.AlarmDAOFactory;
import org.bitrepository.alarm.store.AlarmStore;
Expand All @@ -47,76 +38,99 @@
import org.bitrepository.service.contributor.SimpleContributorMediator;
import org.bitrepository.settings.referencesettings.ServiceType;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.nio.file.Paths;
import java.util.Properties;

/**
* Class for launching an alarm service.
*/
public class AlarmServiceFactory {
/** The alarm service.
* @see #getAlarmService().*/
/**
* The alarm service.
*
* @see #getAlarmService().
*/
private static AlarmService alarmService;
/** The path to the directory containing the configuration files.*/
/**
* The path to the directory containing the configuration files.
*/
private static String configurationDir;
/** The path to the private key file.*/
/**
* The path to the private key file.
*/
private static String privateKeyFile;

/** The properties file holding implementation specifics for the alarm service. */
private static final String CONFIGFILE = "alarmservice.properties";
/** Property key to tell where to locate the path and filename to the private key file. */

/**
* The properties file holding implementation specifics for the alarm service.
*/
private static final String CONFIG_FILE = "alarmservice.properties";
/**
* Property key to tell where to locate the path and filename to the private key file.
*/
private static final String PRIVATE_KEY_FILE = "org.bitrepository.alarm-service.privateKeyFile";

/**
* Private constructor as the class is meant to be used in a static way.
*/
private AlarmServiceFactory() { }
private AlarmServiceFactory() {}

/**
* Initialize the factory with configuration.
* Initialize the factory with configuration.
*
* @param confDir String containing the path to the AlarmService's configuration directory
*/
public static synchronized void init(String confDir) {
configurationDir = confDir;
}

/**
* Factory method to retrieve AlarmService
* Factory method to retrieve AlarmService
*
* @return The AlarmService.
*/
public static synchronized AlarmService getAlarmService() {
if(alarmService == null) {
if (alarmService == null) {
SecurityManager securityManager;
ServiceSettingsProvider settingsLoader =
new ServiceSettingsProvider(new XMLFileSettingsLoader(configurationDir), ServiceType.ALARM_SERVICE);

Settings settings = settingsLoader.getSettings();
try {
loadProperties();
securityManager = SecurityManagerUtil.getSecurityManager(settings, Paths.get(privateKeyFile),
settings.getReferenceSettings().getAlarmServiceSettings().getID());
MessageBus messageBus = ProtocolComponentFactory.getInstance().getMessageBus(settings,
securityManager = SecurityManagerUtil.getSecurityManager(settings, Paths.get(privateKeyFile),
settings.getReferenceSettings().getAlarmServiceSettings().getID());
MessageBus messageBus = ProtocolComponentFactory.getInstance().getMessageBus(settings,
securityManager);
ContributorMediator contributorMediator = new SimpleContributorMediator(messageBus, settings, null, null);
AlarmDAOFactory alarmDAOFactory = new AlarmDAOFactory();
AlarmStore store = alarmDAOFactory.getAlarmServiceDAOInstance(
settings.getReferenceSettings().getAlarmServiceSettings().getAlarmServiceDatabase());
alarmService = new BasicAlarmService(messageBus, settings, store, contributorMediator);

// Add the default handler for putting the alarms into the database.
alarmService.addHandler(new AlarmStorer(store));
} catch (IOException e) {
throw new RuntimeException(e);
}
}

return alarmService;
}

/**
* Loads the properties.
* Loads the properties from the properties file found at {@link #CONFIG_FILE}.
*
* @throws IOException If any input/output issues occurs.
*/
private static void loadProperties() throws IOException {
Properties properties = new Properties();
File propertiesFile = new File(configurationDir, CONFIGFILE);
File propertiesFile = new File(configurationDir, CONFIG_FILE);
try (BufferedReader propertiesReader = new BufferedReader(
new InputStreamReader(new FileInputStream(propertiesFile), StandardCharsets.UTF_8))) {
properties.load(propertiesReader);
Expand Down
Loading