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.HashMap;
023import java.util.Map;
024import java.util.concurrent.Semaphore;
025import org.slf4j.Logger;
026import org.slf4j.LoggerFactory;
027import org.slf4j.Logger;
028import org.slf4j.LoggerFactory;
029import pt.ua.dicoogle.core.ServerSettings;
030import pt.ua.dicoogle.rGUI.interfaces.controllers.IQueryRetrieve;
031
032/**
033 * Controller of Query/Retrieve Settings
034 *
035 * @author Samuel Campos <samuelcampos@ua.pt>
036 */
037@Deprecated
038public class QueryRetrieve implements IQueryRetrieve {
039    private ServerSettings settings;
040
041    private int MaxClientAssoc;
042    private int MaxPDULengthReceive;
043    private int MaxPDULengthSend;
044    private int IdleTimeout;
045    private int AcceptTimeout;
046    private int RspDelay;
047    private int ConnectionTimeout;
048
049
050    private static Semaphore sem = new Semaphore(1, true);
051    private static QueryRetrieve instance = null;
052
053    public static synchronized QueryRetrieve getInstance()
054    {
055        try {
056            sem.acquire();
057            if (instance == null) {
058                instance = new QueryRetrieve();
059            }
060            sem.release();
061        } catch (InterruptedException ex) {
062            LoggerFactory.getLogger(QRServers.class).error(ex.getMessage(), ex);
063        }
064        return instance;
065    }
066
067    private QueryRetrieve(){
068        settings = ServerSettings.getInstance();
069
070        loadSettings();
071    }
072
073    public void loadSettings(){
074        MaxClientAssoc = settings.getMaxClientAssoc();
075        MaxPDULengthReceive = settings.getMaxPDULengthReceive();
076        MaxPDULengthSend = settings.getMaxPDULenghtSend();
077        IdleTimeout = settings.getIdleTimeout();
078        AcceptTimeout = settings.getAcceptTimeout();
079        RspDelay = settings.getRspDelay();
080        ConnectionTimeout = settings.getConnectionTimeout();
081    }
082
083    /**
084     * Save the Settings related to QueryRetrieve to ServerSettings
085     *
086     * dont print XML
087     */
088    public void saveSettings(){
089        settings.setMaxClientAssoc(MaxClientAssoc);
090        settings.setMaxPDULengthReceive(MaxPDULengthReceive);
091        settings.setMaxPDULengthSend(MaxPDULengthSend);
092        settings.setIdleTimeout(IdleTimeout);
093        settings.setAcceptTimeout(AcceptTimeout);
094        settings.setRspDelay(RspDelay);
095        settings.setConnectionTimeout(ConnectionTimeout);
096    }
097
098    /**
099     *
100     * @return  true - if there are unsaved settings ( != ServerSettings)
101     *          false - not
102     */
103    public boolean unsavedSettings(){
104        if(MaxClientAssoc != settings.getMaxClientAssoc() || MaxPDULengthReceive != settings.getMaxPDULengthReceive()
105                || MaxPDULengthSend != settings.getMaxPDULenghtSend() || IdleTimeout != settings.getIdleTimeout()
106                || AcceptTimeout != settings.getAcceptTimeout() || RspDelay != settings.getRspDelay()
107                || ConnectionTimeout != settings.getConnectionTimeout())
108            return true;
109
110        return false;
111    }
112
113    @Override
114    public int getMaxClientAssoc() throws RemoteException {
115        return MaxClientAssoc;
116    }
117    @Override
118    public void setMaxClientAssoc(int value) throws RemoteException {
119        MaxClientAssoc = value;
120    }
121
122    @Override
123    public int getMaxPDULengthReceive() throws RemoteException {
124        return MaxPDULengthReceive;
125    }
126    @Override
127    public void setMaxPDULengthReceive(int value) throws RemoteException {
128        MaxPDULengthReceive = value;
129    }
130
131    @Override
132    public int getMaxPDULengthSend() throws RemoteException {
133        return MaxPDULengthSend;
134    }
135    @Override
136    public void setMaxPDULengthSend(int value) throws RemoteException {
137        MaxPDULengthSend = value;
138    }
139
140    @Override
141    public int getQRIdleTimeout() throws RemoteException {
142        return IdleTimeout;
143    }
144    @Override
145    public void setQRIdleTimeout(int value) throws RemoteException {
146        IdleTimeout = value;
147    }
148
149    @Override
150    public int getQRAcceptTimeout() throws RemoteException {
151        return AcceptTimeout;
152    }
153    @Override
154    public void setQRAcceptTimeout(int value) throws RemoteException {
155        AcceptTimeout = value;
156    }
157
158    @Override
159    public int getQRRspDelay() throws RemoteException {
160        return RspDelay;
161    }
162    @Override
163    public void setQRRspDelay(int value) throws RemoteException {
164        RspDelay = value;
165    }
166
167    @Override
168    public int getQRConnectionTimeout() throws RemoteException {
169        return ConnectionTimeout;
170    }
171    @Override
172    public void setQRConnectionTimeout(int value) throws RemoteException {
173        ConnectionTimeout = value;
174    }
175
176    @Override
177    public HashMap<String, String> getFindModalities() throws RemoteException {
178        Map<String, String> map = settings.getModalityFind();
179        
180        return new HashMap<String, String>(map);
181    }
182
183}