001/* 002 * Copyright 2016 Anyware Services 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.ametys.core.util; 017 018import java.util.Collection; 019import java.util.HashSet; 020import java.util.Set; 021 022import org.apache.avalon.framework.activity.Disposable; 023import org.apache.avalon.framework.activity.Initializable; 024import org.apache.avalon.framework.component.Component; 025import org.apache.commons.collections.CollectionUtils; 026 027/** 028 * Component that centralizes and provides the system status 029 */ 030public class SystemStatus implements Component, Initializable, Disposable 031{ 032 /** The Avalon Role */ 033 public static final String ROLE = SystemStatus.class.getName(); 034 035 private Set<String> _systemStatus; 036 037 @Override 038 public void initialize() throws Exception 039 { 040 if (_systemStatus == null) 041 { 042 _systemStatus = new HashSet<>(); 043 } 044 } 045 046 @Override 047 public void dispose() 048 { 049 _systemStatus = null; 050 } 051 052 /** 053 * Returns the system status 054 * @return The collection of system status 055 */ 056 public Collection<String> getStatus() 057 { 058 return CollectionUtils.unmodifiableCollection(_systemStatus); 059 } 060 061 /** 062 * Add a system status 063 * @param status The system status to add 064 * @return <tt>true</tt> if the system status did not already contain the specified status 065 */ 066 public boolean addStatus(String status) 067 { 068 return _systemStatus.add(status); 069 } 070 071 /** 072 * Add a system status 073 * @param status The system status to remove 074 * @return <tt>true</tt> if the system status contained the specified element 075 */ 076 public boolean removeStatus(String status) 077 { 078 return _systemStatus.remove(status); 079 } 080}