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.client; 020 021import java.rmi.RemoteException; 022import java.util.ArrayList; 023import java.util.concurrent.Semaphore; 024import org.slf4j.Logger; 025import org.slf4j.LoggerFactory; 026import org.slf4j.Logger; 027import org.slf4j.LoggerFactory; 028import pt.ua.dicoogle.rGUI.interfaces.IAdmin; 029import pt.ua.dicoogle.rGUI.RFileBrowser.IRemoteFileSystem; 030import pt.ua.dicoogle.rGUI.interfaces.controllers.IAccessList; 031import pt.ua.dicoogle.rGUI.interfaces.controllers.IActiveSessions; 032import pt.ua.dicoogle.rGUI.interfaces.controllers.IDirectory; 033import pt.ua.dicoogle.rGUI.interfaces.controllers.IIndexOptions; 034import pt.ua.dicoogle.rGUI.interfaces.controllers.ILogs; 035import pt.ua.dicoogle.rGUI.interfaces.controllers.INetworkInterfaces; 036import pt.ua.dicoogle.rGUI.interfaces.controllers.IPendingMessages; 037import pt.ua.dicoogle.rGUI.interfaces.controllers.IPluginControllerAdmin; 038import pt.ua.dicoogle.rGUI.interfaces.controllers.IPluginControllerUser; 039import pt.ua.dicoogle.rGUI.interfaces.controllers.IQRServers; 040import pt.ua.dicoogle.rGUI.interfaces.controllers.IQueryRetrieve; 041import pt.ua.dicoogle.rGUI.interfaces.controllers.ISOPClass; 042import pt.ua.dicoogle.rGUI.interfaces.controllers.IServices; 043import pt.ua.dicoogle.rGUI.interfaces.controllers.IStartupServ; 044import pt.ua.dicoogle.rGUI.interfaces.controllers.ITaskList; 045import pt.ua.dicoogle.rGUI.interfaces.controllers.IUsersManager; 046 047/** 048 * Esta classe é responsável por ir buscar as referências para os objectos remotos da administração 049 * e guardar as referências para esses objectos 050 * 051 * @author Samuel Campos <samuelcampos@ua.pt> 052 */ 053@Deprecated 054public class AdminRefs { 055 056 private ILogs logs; 057 private IQRServers qrservers; 058 private IServices services; 059 private IStartupServ startupServ; 060 private IQueryRetrieve queryRetrieve; 061 private IAccessList accessList; 062 private IIndexOptions indexOptions; 063 private ISOPClass sopClass; 064 private IDirectory directorySettings; 065 private IUsersManager usersManager; 066 private IActiveSessions activeSessions; 067 private ITaskList taskList; 068 private IPendingMessages pendingMessages; 069 private IAdmin admin; 070 private INetworkInterfaces networkInterfaces; 071 private IPluginControllerAdmin pluginController; 072 073 private static AdminRefs instance; 074 private static Semaphore sem = new Semaphore(1, true); 075 076 public static synchronized AdminRefs getAdminRefs(final IAdmin admin) { 077 try { 078 sem.acquire(); 079 if (instance == null) { 080 instance = new AdminRefs(admin); 081 } 082 sem.release(); 083 } catch (InterruptedException ex) { 084 LoggerFactory.getLogger(ClientCore.class).error(ex.getMessage(), ex); 085 } 086 return instance; 087 } 088 089 public static AdminRefs getInstance() { 090 return instance; 091 } 092 093 private AdminRefs(IAdmin admin) { 094 this.admin = admin; 095 096 getRefs(); 097 } 098 099 /** 100 * This function is responsible for obtaining references to Remote administration objects 101 */ 102 private void getRefs() { 103 class GetReferences { 104 105 public void run() { 106 try { 107 //System.out.println("Starting to adquire Admin Refs"); 108 109 110 qrservers = admin.getQRServers(); 111 logs = admin.getLogs(); 112 services = admin.getServices(); 113 startupServ = admin.getStartupServ(); 114 queryRetrieve = admin.getQueryRetrive(); 115 accessList = admin.getAccessList(); 116 indexOptions = admin.getIndexOptions(); 117 sopClass = admin.getSOPClass(); 118 directorySettings = admin.getDirectorySettings(); 119 usersManager = admin.getUsersManager(); 120 activeSessions = admin.getActiveSessions(); 121 taskList = admin.getTaskList(); 122 pendingMessages = admin.getPendingMessages(); 123 networkInterfaces = admin.getNetworkInterface(); 124 pluginController = admin.getPluginController(); 125 126 //System.out.println("Admin Refs Adquired"); 127 } catch (RemoteException ex) { 128 LoggerFactory.getLogger(AdminRefs.class).error(ex.getMessage(), ex); 129 130 //TODO: se falhar, ter?? implica????es... o programa cliente deve parar 131 } 132 } 133 } 134 GetReferences getRefs = new GetReferences(); 135 136 //starts the Thread that will get the remote administrations object references 137 getRefs.run(); 138 } 139 140 /** 141 * @return the logs 142 */ 143 public ILogs getLogs() { 144 return logs; 145 } 146 147 /** 148 * @return the qrservers 149 */ 150 public IQRServers getQRservers() { 151 return qrservers; 152 } 153 154 /** 155 * @return the services 156 */ 157 public IServices getServices() { 158 return services; 159 } 160 161 /** 162 * @return the startup Services 163 */ 164 public IStartupServ getStartupServices() { 165 return startupServ; 166 } 167 168 /** 169 * @return the QueryRetrieve configuration object reference 170 */ 171 public IQueryRetrieve getQueryRetrieve() { 172 return queryRetrieve; 173 } 174 175 /** 176 * @return the Access List configuration object reference 177 */ 178 public IAccessList getAccessList() { 179 return accessList; 180 } 181 182 /** 183 * @return the IndexOptions configuration object reference 184 */ 185 public IIndexOptions getIndexOptions() { 186 return indexOptions; 187 } 188 189 /** 190 * @return the IndexOptions configuration object reference 191 */ 192 public ISOPClass getSOPClass() { 193 return sopClass; 194 } 195 196 /** 197 * @return the Directory Settings configuration object reference 198 */ 199 public IDirectory getDirectorySettings() { 200 return directorySettings; 201 } 202 203 /** 204 * 205 * @return the UsersManager object reference 206 */ 207 public IUsersManager getUsersManager(){ 208 return usersManager; 209 } 210 211 /** 212 * 213 * @return the ActiveSessions object reference 214 */ 215 public IActiveSessions getActiveSessions(){ 216 return activeSessions; 217 } 218 219 /** 220 * 221 * @return the Pending Messages object reference 222 */ 223 public IPendingMessages getPendingMessages(){ 224 return pendingMessages; 225 } 226 227 228 public INetworkInterfaces getNetworkInterfaces() 229 { 230 return networkInterfaces; 231 } 232 233 234 /** 235 * Logout Admin from serv 236 * 237 * @return true if logout succeeded 238 */ 239 public boolean logout() { 240 try { 241 admin.logout(); 242 243 return true; 244 } catch (RemoteException ex) { 245 LoggerFactory.getLogger(AdminRefs.class).error(ex.getMessage(), ex); 246 247 return false; 248 } 249 } 250 251 public boolean saveSettings(){ 252 try { 253 admin.saveSettings(); 254 255 return true; 256 } catch (RemoteException ex) { 257 LoggerFactory.getLogger(AdminRefs.class).error(ex.getMessage(), ex); 258 259 return false; 260 } 261 } 262 public boolean unsavedSettings(){ 263 try { 264 return admin.unsavedSettings(); 265 } catch (RemoteException ex) { 266 LoggerFactory.getLogger(AdminRefs.class).error(ex.getMessage(), ex); 267 } 268 return false; 269 } 270 271 public IRemoteFileSystem getRFS(){ 272 try { 273 return admin.getRFS(); 274 } catch (RemoteException ex) { 275 LoggerFactory.getLogger(AdminRefs.class).error(ex.getMessage(), ex); 276 } 277 278 return null; 279 } 280 281 public String getDefaultFilePath(){ 282 try { 283 return admin.getDefaultFilePath(); 284 } catch (RemoteException ex) { 285 LoggerFactory.getLogger(AdminRefs.class).error(ex.getMessage(), ex); 286 } 287 288 return null; 289 } 290 291 /** 292 * Index new file or folder 293 * 294 * @param Path - file or folter path 295 */ 296 public void index(String Path, boolean resume){ 297 try { 298 indexOptions.index(Path, resume); 299 } catch (RemoteException ex) { 300 LoggerFactory.getLogger(AdminRefs.class).error(ex.getMessage(), ex); 301 } 302 } 303 304 /** 305 * Re-Index one file 306 * 307 * @param Path - file or folter path 308 */ 309 public void reIndex(ArrayList<String> list){ 310 try { 311 indexOptions.reIndex(list); 312 } catch (RemoteException ex) { 313 LoggerFactory.getLogger(AdminRefs.class).error(ex.getMessage(), ex); 314 } 315 } 316 317 318 public void shutdownServer(){ 319 try { 320 admin.shutdownServer(); 321 } catch (RemoteException ex) { 322 //LoggerFactory.getLogger(AdminRefs.class).error(ex.getMessage(), ex); 323 } 324 //System.out.println("The server is Shutting Down"); 325 } 326 327 /** 328 * @return the taskList 329 */ 330 public ITaskList getTaskList() { 331 return taskList; 332 } 333 334 public IPluginControllerAdmin getPluginController() 335 { 336 return pluginController; 337 } 338 339 /* 340 * Attention, we should not pass paths directly as arguments 341 * we should instead use a datasource, since the file can be stored somewhere else 342 * or even in memory... 343 * 344 */ 345 public void cbirIndex(String path) { 346 //a list containing all indexation plugins 347 if(pluginController == null) return; 348 349 //try{ 350 //pluginController.cbirIndex(path); 351 //} 352 /* catch(RemoteException e){ 353 System.err.println("Oh dear..."); 354 System.err.println(e); 355 }*/ 356 } 357}