001/** 002 * Copyright (C) 2014 Universidade de Aveiro, DETI/IEETA, Bioinformatics Group - http://bioinformatics.ua.pt/ 003 * 004 * This file is part of Dicoogle/dicoogle. 005 * 006 * Dicoogle/dicoogle is free software: you can redistribute it and/or modify 007 * it under the terms of the GNU General Public License as published by 008 * the Free Software Foundation, either version 3 of the License, or 009 * (at your option) any later version. 010 * 011 * Dicoogle/dicoogle is distributed in the hope that it will be useful, 012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 014 * GNU General Public License for more details. 015 * 016 * You should have received a copy of the GNU General Public License 017 * along with Dicoogle. If not, see <http://www.gnu.org/licenses/>. 018 */ 019package pt.ua.dicoogle.rGUI.server.controllers; 020 021import java.rmi.RemoteException; 022import java.util.concurrent.Semaphore; 023import org.slf4j.Logger; 024import org.slf4j.LoggerFactory; 025import org.slf4j.Logger; 026import org.slf4j.LoggerFactory; 027import pt.ua.dicoogle.core.ServerSettings; 028import pt.ua.dicoogle.rGUI.interfaces.controllers.IStartupServ; 029 030/** 031 * Controller of Startup Services Settings 032 * 033 * @author Samuel Campos <samuelcampos@ua.pt> 034 */ 035@Deprecated 036public class StartupServices implements IStartupServ { 037 038 private static Semaphore sem = new Semaphore(1, true); 039 private static StartupServices instance = null; 040 041 private ServerSettings settings; 042 043 private boolean p2p; 044 private boolean storage; 045 private boolean qr; 046 private boolean web; 047 private boolean webservices; 048 private int storagePort; 049 private int webPort; 050 private int webservicesPort; 051 private int QRPort; 052 private int remoteGUIPort; 053 private String remoteGUIExtIP; 054 055 public static synchronized StartupServices getInstance() { 056 try { 057 sem.acquire(); 058 if (instance == null) { 059 instance = new StartupServices(); 060 } 061 sem.release(); 062 } catch (InterruptedException ex) { 063 LoggerFactory.getLogger(StartupServices.class).error(ex.getMessage(), ex); 064 } 065 066 return instance; 067 } 068 069 private StartupServices() { 070 settings = ServerSettings.getInstance(); 071 072 loadSettings(); 073 } 074 075 /** 076 * Load Settings from ServerSettings 077 */ 078 public void loadSettings() { 079 // p2p = settings.isP2P(); 080 storage = settings.isStorage(); 081 qr = settings.isQueryRetrive(); 082 web = settings.getWeb().isWebServer(); 083 webservices = settings.getWeb().isWebServices(); 084 085 storagePort = settings.getStoragePort(); 086 webPort = settings.getWeb().getServerPort(); 087 webservicesPort = settings.getWeb().getServicePort(); 088 QRPort = settings.getWlsPort(); 089 090 remoteGUIPort = settings.getRemoteGUIPort(); 091 remoteGUIExtIP = settings.getRGUIExternalIP(); 092 } 093 094 /** 095 * Save the settings related to Startup Services 096 * 097 * not write the settings in XML 098 */ 099 public void saveSettings() { 100 // settings.setP2P(p2p); 101 settings.setStorage(storage); 102 settings.setQueryRetrive(qr); 103 settings.getWeb().setWebServer(web); 104 settings.getWeb().setWebServices(webservices); 105 106 settings.setStoragePort(storagePort); 107 settings.getWeb().setServerPort(webPort); 108 settings.getWeb().setServicePort(webservicesPort); 109 settings.setWlsPort(QRPort); 110 settings.setRemoteGUIPort(remoteGUIPort); 111 settings.setRGUIExternalIP(remoteGUIExtIP); 112 } 113 114 /** 115 * 116 * @return true - if there are unsaved settings ( != ServerSettings) 117 * false - not 118 */ 119 public boolean unsavedSettings() { 120 if (/*p2p != settings.isP2P() ||*/ storage != settings.isStorage() 121 || qr != settings.isQueryRetrive() || web != settings.getWeb().isWebServer() 122 || webservices != settings.getWeb().isWebServices() || storagePort != settings.getStoragePort() 123 || webPort != settings.getWeb().getServerPort() || webservicesPort != settings.getWeb().getServicePort() 124 || remoteGUIPort != settings.getRemoteGUIPort() || QRPort != settings.getWlsPort() 125 || (remoteGUIExtIP != null && !remoteGUIExtIP.equals(settings.getRGUIExternalIP()))) { 126 return true; 127 } 128 129 return false; 130 } 131 132 @Override 133 public void setP2P(boolean value) throws RemoteException { 134 p2p = value; 135 } 136 137 @Override 138 public boolean getP2P() throws RemoteException { 139 return p2p; 140 } 141 142 @Override 143 public void setDICOMStorage(boolean value) throws RemoteException { 144 storage = value; 145 } 146 147 @Override 148 public boolean getDICOMStorage() throws RemoteException { 149 return storage; 150 } 151 152 @Override 153 public void setDICOMStoragePort(int value) throws RemoteException { 154 storagePort = value; 155 } 156 157 @Override 158 public int getDICOMStoragePort() throws RemoteException { 159 return storagePort; 160 } 161 162 @Override 163 public void setDICOMQR(boolean value) throws RemoteException { 164 qr = value; 165 } 166 167 @Override 168 public boolean getDICOMQR() throws RemoteException { 169 return qr; 170 } 171 172 @Override 173 public void setWebServer(boolean value) throws RemoteException { 174 web = value; 175 } 176 177 @Override 178 public boolean getWebServer() throws RemoteException { 179 return web; 180 } 181 182 @Override 183 public void setWebServerPort(int value) throws RemoteException { 184 webPort = value; 185 } 186 187 @Override 188 public int getWebServerPort() throws RemoteException { 189 return webPort; 190 } 191 192 @Override 193 public void setWebServices(boolean value) throws RemoteException { 194 webservices = value; 195 } 196 197 @Override 198 public boolean getWebServices() throws RemoteException { 199 return webservices; 200 } 201 202 @Override 203 public void setWebServicesPort(int value) throws RemoteException { 204 webservicesPort = value; 205 } 206 207 @Override 208 public int getWebServicesPort() throws RemoteException { 209 return webservicesPort; 210 } 211 212 @Override 213 public void setRemoteGUIPort(int value) throws RemoteException { 214 remoteGUIPort = value; 215 } 216 217 @Override 218 public int getRemoteGUIPort() throws RemoteException { 219 return remoteGUIPort; 220 } 221 222 @Override 223 public void setDICOMQRPort(int value) throws RemoteException { 224 QRPort = value; 225 } 226 227 @Override 228 public int getDICOMQRPort() throws RemoteException { 229 return QRPort; 230 } 231 232 @Override 233 public void setRemoteGUIExtIP(String IP) throws RemoteException { 234 remoteGUIExtIP = IP; 235 } 236 237 @Override 238 public String getRemoteGUIExtIP() throws RemoteException { 239 return remoteGUIExtIP; 240 } 241}