|
From: <car...@us...> - 2003-03-17 03:55:20
|
Update of /cvsroot/madsserv/madsserv/src/server
In directory sc8-pr-cvs1:/tmp/cvs-serv31263
Modified Files:
DialogClient.java DialogSocket.java ServerFrame.java
ServerInit.java ThreadListenClients.java
Log Message:
amelioration de l'interface graphique et prise en compte du nouveau reencode
Index: DialogClient.java
===================================================================
RCS file: /cvsroot/madsserv/madsserv/src/server/DialogClient.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** DialogClient.java 14 Mar 2003 03:26:18 -0000 1.5
--- DialogClient.java 17 Mar 2003 03:55:17 -0000 1.6
***************
*** 47,50 ****
--- 47,64 ----
mySocket.getInetAddress().getHostAddress().toString());
}
+ else {
+ String[] warning = new String[1];
+
+ warning[0] = "Trop de clients connectés au serveur.";
+ System.out.println("Envoi du message " + warning[0]);
+ sendMessage(9, warning);
+ try {
+ Thread.sleep(1000);
+ }
+ catch (Exception e) {
+
+ }
+ this.stop();
+ }
}
***************
*** 55,59 ****
* @param _type le type du message.
* @param _message le tableau de <code>String</code> contenant les champs du
! * message reçu.
*/
--- 69,73 ----
* @param _type le type du message.
* @param _message le tableau de <code>String</code> contenant les champs du
! * message recu.
*/
***************
*** 66,69 ****
--- 80,84 ----
switch (_type) {
case 2: {
+ String[] messageToSend = new String[1];
// if (lgth < 3) raise exception;
serverInit.setMediaAddress(clientID, _message[1]);
***************
*** 74,83 ****
System.out.println("Nouveau format prefere pour le client " +
clientID + ": " + _message[2]);
! sendMessage(3, null);
serverInit.startStreaming(clientID);
break;
}
case 4: {
! serverInit.endConnexion(clientID);
break;
}
--- 89,106 ----
System.out.println("Nouveau format prefere pour le client " +
clientID + ": " + _message[2]);
! messageToSend[0] = "Connexion du client " + String.valueOf(clientID);
! sendMessage(3, messageToSend);
serverInit.startStreaming(clientID);
break;
}
case 4: {
! serverInit.endConnexionClient(clientID);
! break;
! }
! case 8: {
! double currentMediaTime;
! //clientID = Integer.parseInt(_message[0]);
! currentMediaTime = Double.parseDouble(_message[1]);
! serverInit.setCurrentMediaTime(clientID, currentMediaTime);
break;
}
Index: DialogSocket.java
===================================================================
RCS file: /cvsroot/madsserv/madsserv/src/server/DialogSocket.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** DialogSocket.java 13 Mar 2003 02:38:49 -0000 1.2
--- DialogSocket.java 17 Mar 2003 03:55:17 -0000 1.3
***************
*** 19,23 ****
public abstract class DialogSocket {
! private final int TIME_OUT = 1000;
// identite du client
--- 19,23 ----
public abstract class DialogSocket {
! // private final int TIME_OUT = 1000;
// identite du client
***************
*** 65,69 ****
* @param _type le type du message.
* @param _message le tableau de <code>String</code> contenant les champs du
! * message reçu.
*/
--- 65,69 ----
* @param _type le type du message.
* @param _message le tableau de <code>String</code> contenant les champs du
! * message reçu.
*/
***************
*** 128,132 ****
//threadInput.setEnd();
System.err.println("le thread est mort");
! Thread.sleep(1000);
//binput.close();
//System.err.println("le binput est mort");
--- 128,132 ----
//threadInput.setEnd();
System.err.println("le thread est mort");
! //Thread.sleep(1000);
//binput.close();
//System.err.println("le binput est mort");
Index: ServerFrame.java
===================================================================
RCS file: /cvsroot/madsserv/madsserv/src/server/ServerFrame.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** ServerFrame.java 14 Mar 2003 03:27:20 -0000 1.1
--- ServerFrame.java 17 Mar 2003 03:55:17 -0000 1.2
***************
*** 1,353 ****
! import javax.swing.*;
! import java.awt.*;
! import java.net.*;
! import java.awt.event.*;
! import java.awt.Component.*;
! import java.awt.TextComponent.*;
! import java.awt.Checkbox.*;
! import java.awt.CheckboxGroup.*;
! import java.util.*;
!
! public class ServerFrame
! extends JFrame {
!
! Container contentPane = null;
! ServerInit serverInit = null;
!
! BorderLayout borderLayout1 = new BorderLayout();
! GridLayout gridLayout1 = new GridLayout(4, 2, 5, 5);
! GridLayout gridLayout2 = new GridLayout(1, 1);
! GridBagLayout gridBagLayout2 = new GridBagLayout();
! GridBagConstraints c;
!
! Vector clientReports;
! JPanel jPanelTitles = new JPanel();
! JLabel jLabelID = new JLabel();
! JLabel jLabelIP = new JLabel();
! JLabel jLabelStatus = new JLabel();
! JLabel jLabelMedia = new JLabel();
! JLabel jLabelBitRate = new JLabel();
! JLabel jLabelQuality = new JLabel();
!
! JTabbedPane jTabbedPane = new JTabbedPane();
! JPanel jPanelConfig = new JPanel();
! JPanel jPanelReport = new JPanel();
! JPanel jPanelFormats = new JPanel();
! JPanel jPanelQuality = new JPanel();
!
! JPanel jPanelSouth = new JPanel();
!
! JLabel jLabelPort = new JLabel();
! JLabel jLabelPortRTP = new JLabel();
! JLabel jLabelNbMax = new JLabel();
! JLabel jLabelDebit = new JLabel();
! JTextField jTextFieldPort = new JTextField();
! JTextField jTextFieldPortRTP = new JTextField();
! JTextField jTextFieldNbMax = new JTextField();
! JTextField jTextFieldDebit = new JTextField();
!
! JButton jButtonStart = new JButton();
! JButton jButtonStop = new JButton();
! JButton jButtonQuit = new JButton();
!
! public ServerFrame( /*ServerInit _parent*/) {
! //parent = _parent;
! contentPane = getContentPane();
! contentPane.setLayout(borderLayout1);
! this.setSize(new Dimension(600, 500));
! this.setTitle("Madsserv Serveur");
!
! clientReports = new Vector();
! jPanelReport.setLayout(gridBagLayout2);
! jPanelReport.setBackground(Color.black);
! c = new GridBagConstraints();
! c.weightx = 0.0;
! jLabelID.setText("ID Client");
! jLabelID.setHorizontalAlignment(SwingConstants.CENTER);
! jPanelTitles.add(jLabelID, c);
! jLabelIP.setText("IP Client");
! jLabelIP.setHorizontalAlignment(SwingConstants.CENTER);
! jPanelTitles.add(jLabelIP, c);
! jLabelStatus.setText("Statut");
! jLabelStatus.setHorizontalAlignment(SwingConstants.CENTER);
! jPanelTitles.add(jLabelStatus, c);
! jLabelMedia.setText("Media demandé");
! jLabelMedia.setHorizontalAlignment(SwingConstants.CENTER);
! jPanelTitles.add(jLabelMedia, c);
! jLabelBitRate.setText("Débit");
! jLabelBitRate.setHorizontalAlignment(SwingConstants.CENTER);
! jPanelTitles.add(jLabelBitRate, c);
! jLabelQuality.setText("Niveau de qualité");
! jLabelQuality.setHorizontalAlignment(SwingConstants.CENTER);
! c.gridwidth = GridBagConstraints.REMAINDER;
! jPanelTitles.add(jLabelQuality, c);
! jPanelReport.add(jPanelTitles);
!
! jTabbedPane.addTab("Configuration", null, jPanelConfig,
! "Configure le serveur");
! jTabbedPane.addTab("Rapports", null, jPanelReport, "Affiche les connexions");
! jTabbedPane.addTab("Formats", null, jPanelFormats,
! "Affiche les formats supportés par le serveur");
! jTabbedPane.addTab("Qualité", null, jPanelQuality,
! "Affiche l'association format/niveau de qualité");
! contentPane.add(jTabbedPane, BorderLayout.CENTER);
!
! jLabelPort.setText("Port d'écoute :");
! jTextFieldPort.setText("5000");
! jLabelPortRTP.setText("Port de base pour RTP :");
! jTextFieldPortRTP.setText("40000");
! jLabelNbMax.setText("Nombre maximum de clients :");
! jTextFieldNbMax.setText("10");
! jLabelDebit.setText("Debit minimum en Ko/s :");
! jTextFieldDebit.setText("20");
!
! jPanelConfig.setLayout(gridLayout1);
! jPanelConfig.add(jLabelPort);
! jPanelConfig.add(jTextFieldPort);
! jPanelConfig.add(jLabelPortRTP);
! jPanelConfig.add(jTextFieldPortRTP);
! jPanelConfig.add(jLabelNbMax);
! jPanelConfig.add(jTextFieldNbMax);
! jPanelConfig.add(jLabelDebit);
! jPanelConfig.add(jTextFieldDebit);
!
! jButtonStart.setText("Démarrer");
! jButtonStart.setEnabled(true);
! jButtonStart.addActionListener(new ServerFrame_Button_Start_ActionAdapter(this));
! jPanelSouth.add(jButtonStart);
! jButtonStop.setText("Arrêter");
! jButtonStop.setEnabled(false);
! jButtonStop.addActionListener(new ServerFrame_Button_Stop_ActionAdapter(this));
! jPanelSouth.add(jButtonStop);
! jButtonQuit.setText("Quitter");
! jButtonQuit.addActionListener(new ServerFrame_Button_Quit_ActionAdapter(this));
! jPanelSouth.add(jButtonQuit);
! contentPane.add(jPanelSouth, BorderLayout.SOUTH);
! }
!
! public void Button_Start_actionPerformed(ActionEvent evt) {
! int port = 5000;
! int portBaseRTP = 40000;
! int nbClients = 10;
! int debit = 20;
! Integer integer1 = null;
! Integer integer2 = null;
! Integer integer3 = null;
! Integer integer4 = null;
!
! try {
! integer1 = Integer.valueOf(jTextFieldPort.getText());
! integer2 = Integer.valueOf(jTextFieldPortRTP.getText());
! integer3 = Integer.valueOf(jTextFieldNbMax.getText());
! integer4 = Integer.valueOf(jTextFieldDebit.getText());
! if (integer1 == null || integer2 == null || integer3 == null || integer3 == null) {
! System.err.println("il y a une erreur");
! displayError("Erreur de saisie",
! "La valeur d'un champ est incorrecte.\nVeuillez la modifier");
! }
! else {
! port = integer1.intValue();
! portBaseRTP = integer2.intValue();
! nbClients = integer3.intValue();
! debit = integer4.intValue();
! }
! }
! catch (NumberFormatException e) {
! displayError("Erreur de saisie",
! "La valeur d'un champ est incorrecte.\nVeuillez la modifier");
! }
! if (serverInit == null) {
! try {
! serverInit = new ServerInit(port, portBaseRTP, nbClients, debit, this);
! serverInit.start();
! jButtonStart.setEnabled(false);
! jButtonStop.setEnabled(true);
! }
! catch (ErrNoListen e) {
! serverInit = null;
! // lancer erreur popup
! jButtonStart.setEnabled(true);
! jButtonStop.setEnabled(false);
! }
! }
! else {
! System.err.println("ServerInit est deja cree");
! }
!
! }
!
! public void displayError(String _name, String _message) {
! JOptionPane.showMessageDialog(this, _message, _name,
! JOptionPane.WARNING_MESSAGE);
! }
!
! public void addClientReport(ClientReport _clientReport) {
! int rows, columns;
! rows = gridLayout2.getRows() + 1;
! gridLayout2.setRows(rows);
! jPanelReport.add(_clientReport.getGraphics());
! }
!
! public void Button_Stop_actionPerformed(ActionEvent evt) {
! serverInit.stop();
! }
!
! public void Button_Quit_actionPerformed(ActionEvent evt) {
! System.exit(0);
! }
!
! /**
! * processWindowEvent Methode qui permet de quitter le client quand on clique pour fermer la fenetre
! * @param e c'est l'evenement qui indique que l'on a clique sur le bouton pour fermer la fenetre
! */
! protected void processWindowEvent(WindowEvent e) {
! super.processWindowEvent(e);
! if (e.getID() == WindowEvent.WINDOW_CLOSING) {
! Button_Quit_actionPerformed(null);
! }
! }
!
! public static void main(String[] args) {
! ServerFrame serverFrame = new ServerFrame();
! serverFrame.pack();
! //Center the window
! Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
! Dimension frameSize = serverFrame.getSize();
! if (frameSize.height > screenSize.height) {
! frameSize.height = screenSize.height;
! }
! if (frameSize.width > screenSize.width) {
! frameSize.width = screenSize.width;
! }
! serverFrame.setLocation( (screenSize.width - frameSize.width) / 2,
! (screenSize.height - frameSize.height) / 2);
!
! serverFrame.show();
! }
!
! }
!
! class ServerFrame_Button_Start_ActionAdapter
! implements ActionListener {
! ServerFrame adaptee;
!
! ServerFrame_Button_Start_ActionAdapter(ServerFrame adaptee) {
! this.adaptee = adaptee;
! }
!
! public void actionPerformed(ActionEvent evt) {
! adaptee.Button_Start_actionPerformed(evt);
! }
! }
!
! class ServerFrame_Button_Stop_ActionAdapter
! implements ActionListener {
! ServerFrame adaptee;
!
! ServerFrame_Button_Stop_ActionAdapter(ServerFrame adaptee) {
! this.adaptee = adaptee;
! }
!
! public void actionPerformed(ActionEvent evt) {
! adaptee.Button_Stop_actionPerformed(evt);
! }
! }
!
! class ServerFrame_Button_Quit_ActionAdapter
! implements ActionListener {
! ServerFrame adaptee;
!
! ServerFrame_Button_Quit_ActionAdapter(ServerFrame adaptee) {
! this.adaptee = adaptee;
! }
!
! public void actionPerformed(ActionEvent evt) {
! adaptee.Button_Quit_actionPerformed(evt);
! }
! }
!
! class ClientReport {
!
! private int clientID = -1;
! private String clientIP = "";
! private String status = "";
! private String media = "";
! private float debit = 0.0f;
! private int qualityLevel = -1;
!
! private JLabel jLabelID = new JLabel();
! private JLabel jLabelIP = new JLabel();
! private JLabel jLabelStatus = new JLabel();
! private JLabel jLabelMedia = new JLabel();
! private JLabel jLabelDebit = new JLabel();
! private JLabel jLabelQuality = new JLabel();
!
! // constructeurs
! public ClientReport(int _clientID, String _IP, String _status) {
! clientID = _clientID;
! clientIP = _IP;
! status = _status;
! }
!
! public ClientReport(int _clientID, String _IP, String _status, String _media,
! int _qualityLevel) {
! clientID = _clientID;
! clientIP = _IP;
! status = _status;
! media = _media;
! qualityLevel = _qualityLevel;
! }
!
! public synchronized void setStatus(String _status) {
! status = _status;
! }
!
! public synchronized void setMedia(String _media) {
! media = _media;
! }
!
! public synchronized void setDebit(float _debit) {
! debit = _debit;
! }
!
! public synchronized void setQualityLevel(int _quality) {
! qualityLevel = _quality;
! }
!
! public JPanel getGraphics() {
! JPanel jPanelReturn = new JPanel();
! GridBagLayout gridBagLayout = new GridBagLayout();
! GridBagConstraints c = new GridBagConstraints();
! c.weightx = 1.0;
!
! jLabelID.setText(String.valueOf(clientID));
! jLabelID.setHorizontalAlignment(SwingConstants.CENTER);
! jPanelReturn.add(jLabelID, c);
! jLabelIP.setText(clientIP);
! jLabelIP.setHorizontalAlignment(SwingConstants.CENTER);
! jPanelReturn.add(jLabelIP, c);
! jLabelStatus.setText(status);
! jLabelStatus.setHorizontalAlignment(SwingConstants.CENTER);
! jPanelReturn.add(jLabelStatus, c);
! jLabelMedia.setText(media);
! jLabelMedia.setHorizontalAlignment(SwingConstants.CENTER);
! jPanelReturn.add(jLabelMedia, c);
! jLabelDebit.setText(String.valueOf(debit));
! jLabelDebit.setHorizontalAlignment(SwingConstants.CENTER);
! jPanelReturn.add(jLabelDebit, c);
! jLabelQuality.setText(String.valueOf(qualityLevel));
! jLabelQuality.setHorizontalAlignment(SwingConstants.CENTER);
! c.gridwidth = GridBagConstraints.REMAINDER;
! jPanelReturn.add(jLabelQuality);
!
! return jPanelReturn;
! }
!
! public void removeClientReport() {
!
! }
!
! public void updateClientReport() {
!
! }
! }
--- 1,456 ----
! import javax.swing.*;
! import java.awt.*;
! import java.net.*;
! import java.awt.event.*;
! import java.awt.Component.*;
! import java.awt.TextComponent.*;
! import java.awt.Checkbox.*;
! import java.awt.CheckboxGroup.*;
! import java.util.*;
! import javax.swing.table.*;
! import javax.swing.border.*;
!
! public class ServerFrame
! extends JFrame {
!
! protected ServerInit serverInit = null;
!
! // Table graphique pour l'etat des connexions
! TableClients tableClients = new TableClients();
!
! Container contentPane = null;
!
! // Declaration et instanciation des Layouts.
! BorderLayout borderLayout1 = new BorderLayout();
! // GridLayout gridLayout1 = new GridLayout(5, 2, 5, 5);
! // GridLayout gridLayout2 = new GridLayout(1, 1);
! GridBagLayout gridBagLayout1 = new GridBagLayout();
! //GridBagLayout gridBagLayout2 = new GridBagLayout();
! GridBagConstraints c = new GridBagConstraints();
!
! /*
! JPanel jPanelTitles = new JPanel();
! JLabel jLabelID = new JLabel();
! JLabel jLabelIP = new JLabel();
! JLabel jLabelStatus = new JLabel();
! JLabel jLabelMedia = new JLabel();
! JLabel jLabelBitRate = new JLabel();
! JLabel jLabelQuality = new JLabel();*/
!
! // Declaration et instanciation du JTabbedPane;
! JTabbedPane jTabbedPane = new JTabbedPane();
! JPanel jPanelConfig = new JPanel();
! JPanel jPanelReport = new JPanel();
! JPanel jPanelFormats = new JPanel();
! JPanel jPanelQuality = new JPanel();
!
! // Declaration et instanciation du JPanel destine aux boutons
! JPanel jPanelSouth = new JPanel();
!
! // Declaration et instanciation des elements graphiques de l'onglet Configuration
! JLabel jLabelPort = new JLabel();
! JLabel jLabelPortRTP = new JLabel();
! JLabel jLabelPortSim = new JLabel();
! JLabel jLabelNbMax = new JLabel();
! JLabel jLabelDebit = new JLabel();
! JTextField jTextFieldPort = new JTextField();
! JTextField jTextFieldPortSim = new JTextField();
! JTextField jTextFieldPortRTP = new JTextField();
! JTextField jTextFieldNbMax = new JTextField();
! JTextField jTextFieldDebit = new JTextField();
!
! // Declaration et instanciation des elements graphiques de jPanelSouth
! JButton jButtonStart = new JButton();
! JButton jButtonStop = new JButton();
! JButton jButtonQuit = new JButton();
!
! public ServerFrame() {
!
! contentPane = getContentPane();
! contentPane.setLayout(borderLayout1);
! this.setSize(new Dimension(750, 350));
! this.setTitle("Madsserv Serveur");
!
! // Construction des onglets
! jTabbedPane.addTab("Configuration", null, jPanelConfig,
! "Configure le serveur");
! jTabbedPane.addTab("Rapports", null, jPanelReport, "Affiche les connexions");
! jTabbedPane.addTab("Formats", null, jPanelFormats,
! "Affiche les formats supporté par le serveur");
! jTabbedPane.addTab("Qualité", null, jPanelQuality,
! "Affiche l'association format/niveau de qualité");
! contentPane.add(jTabbedPane, BorderLayout.CENTER);
!
! // Construction de l'onglet Configuration
! jLabelPort.setText("Port d'écoute clients :");
! jTextFieldPort.setText("5001");
! jTextFieldPort.setPreferredSize(new Dimension(100, 25));
! jLabelPortSim.setText("Port d'écoute simulateur :");
! jTextFieldPortSim.setText("4998");
! jTextFieldPortSim.setPreferredSize(new Dimension(100, 25));
! jLabelPortRTP.setText("Port de base pour RTP :");
! jTextFieldPortRTP.setText("40000");
! jTextFieldPortRTP.setPreferredSize(new Dimension(100, 25));
! jLabelNbMax.setText("Nombre maximum de clients :");
! jTextFieldNbMax.setText("10");
! jTextFieldNbMax.setPreferredSize(new Dimension(100, 25));
! jLabelDebit.setText("Debit minimum en Ko/s :");
! jTextFieldDebit.setText("20");
! jTextFieldDebit.setPreferredSize(new Dimension(100, 25));
!
! jPanelConfig.setLayout(gridBagLayout1);
! c.insets = new Insets(5, 5, 5, 5);
! c.fill = GridBagConstraints.NONE;
! c.gridwidth = GridBagConstraints.RELATIVE;
! c.weightx = 1.0;
! c.anchor = GridBagConstraints.EAST;
! jPanelConfig.add(jLabelPort, c);
! c.gridwidth = GridBagConstraints.REMAINDER;
! c.anchor = GridBagConstraints.WEST;
! jPanelConfig.add(jTextFieldPort, c);
! c.gridwidth = GridBagConstraints.RELATIVE;
! c.anchor = GridBagConstraints.EAST;
! jPanelConfig.add(jLabelPortSim, c);
! c.gridwidth = GridBagConstraints.REMAINDER;
! c.anchor = GridBagConstraints.WEST;
! jPanelConfig.add(jTextFieldPortSim, c);
! c.gridwidth = GridBagConstraints.RELATIVE;
! c.anchor = GridBagConstraints.EAST;
! jPanelConfig.add(jLabelPortRTP, c);
! c.gridwidth = GridBagConstraints.REMAINDER;
! c.anchor = GridBagConstraints.WEST;
! jPanelConfig.add(jTextFieldPortRTP, c);
! c.gridwidth = GridBagConstraints.RELATIVE;
! c.anchor = GridBagConstraints.EAST;
! jPanelConfig.add(jLabelNbMax, c);
! c.gridwidth = GridBagConstraints.REMAINDER;
! c.anchor = GridBagConstraints.WEST;
! jPanelConfig.add(jTextFieldNbMax, c);
! c.gridwidth = GridBagConstraints.RELATIVE;
! c.anchor = GridBagConstraints.EAST;
! jPanelConfig.add(jLabelDebit, c);
! c.gridwidth = GridBagConstraints.REMAINDER;
! c.anchor = GridBagConstraints.WEST;
! jPanelConfig.add(jTextFieldDebit, c);
!
! // Insertion de la table graphique
! tableClients.insertGraphics(jPanelReport);
!
! // Construction du panel des boutons
! jButtonStart.setText("Démarrer");
! jButtonStart.setEnabled(true);
! jButtonStart.addActionListener(new ServerFrame_Button_Start_ActionAdapter(this));
! jPanelSouth.add(jButtonStart);
! jButtonStop.setText("Arrêter");
! jButtonStop.setEnabled(false);
! jButtonStop.addActionListener(new ServerFrame_Button_Stop_ActionAdapter(this));
! jPanelSouth.add(jButtonStop);
! jButtonQuit.setText("Quitter");
! jButtonQuit.addActionListener(new ServerFrame_Button_Quit_ActionAdapter(this));
! jPanelSouth.add(jButtonQuit);
! contentPane.add(jPanelSouth, BorderLayout.SOUTH);
! }
!
! public void Button_Start_actionPerformed(ActionEvent evt) {
! int port = 5000;
! int portSim = 4998;
! int portBaseRTP = 40000;
! int nbClients = 10;
! int debit = 20;
! Integer integer1 = null;
! Integer integer2 = null;
! Integer integer3 = null;
! Integer integer4 = null;
! Integer integer5 = null;
!
! try {
! integer1 = Integer.valueOf(jTextFieldPort.getText());
! integer2 = Integer.valueOf(jTextFieldPortSim.getText());
! integer3 = Integer.valueOf(jTextFieldPortRTP.getText());
! integer4 = Integer.valueOf(jTextFieldNbMax.getText());
! integer5 = Integer.valueOf(jTextFieldDebit.getText());
! if (integer1 == null || integer2 == null || integer3 == null || integer3 == null) {
! System.err.println("il y a une erreur");
! displayError("Erreur de saisie",
! "La valeur d'un champ est incorrecte.\nVeuillez la modifier");
! }
! else {
! port = integer1.intValue();
! portSim = integer2.intValue();
! portBaseRTP = integer3.intValue();
! nbClients = integer4.intValue();
! debit = integer5.intValue();
! }
! }
! catch (NumberFormatException e) {
! displayError("Erreur de saisie",
! "La valeur d'un champ est incorrecte.\nVeuillez la modifier");
! }
! if (serverInit == null) {
! try {
! serverInit = new ServerInit(port, portSim, portBaseRTP, nbClients,
! debit, this);
! serverInit.start();
! jButtonStart.setEnabled(false);
! jButtonStop.setEnabled(true);
! }
! catch (ErrNoListen e) {
! serverInit = null;
! // lancer erreur popup
! jButtonStart.setEnabled(true);
! jButtonStop.setEnabled(false);
! }
! }
! else {
! try {
! System.err.println("ServerInit est deja cree");
! serverInit.start();
! }
! catch (ErrNoListen e) {
! serverInit = null;
! // lancer erreur popup
! jButtonStart.setEnabled(true);
! jButtonStop.setEnabled(false);
! }
! }
! }
!
! public void displayError(String _name, String _message) {
! JOptionPane.showMessageDialog(this, _message, _name,
! JOptionPane.WARNING_MESSAGE);
! }
!
! public void Button_Stop_actionPerformed(ActionEvent evt) {
! serverInit.stop();
! serverInit = null;
! System.gc();
! jButtonStart.setEnabled(true);
! jButtonStop.setEnabled(false);
! }
!
! public void Button_Quit_actionPerformed(ActionEvent evt) {
! System.exit(0);
! }
!
! /**
! * processWindowEvent Methode qui permet de quitter le client quand on clique pour fermer la fenetre
! * @param e c'est l'evenement qui indique que l'on a clique sur le bouton pour fermer la fenetre
! */
! protected void processWindowEvent(WindowEvent e) {
! super.processWindowEvent(e);
! if (e.getID() == WindowEvent.WINDOW_CLOSING) {
! Button_Quit_actionPerformed(null);
! }
! }
!
! public static void main(String[] args) {
! ServerFrame serverFrame = new ServerFrame();
! serverFrame.pack();
! //Center the window
! Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
! Dimension frameSize = serverFrame.getSize();
! if (frameSize.height > screenSize.height) {
! frameSize.height = screenSize.height;
! }
! if (frameSize.width > screenSize.width) {
! frameSize.width = screenSize.width;
! }
! serverFrame.setLocation( (screenSize.width - frameSize.width) / 2,
! (screenSize.height - frameSize.height) / 2);
!
! serverFrame.show();
! }
! }
!
! class ServerFrame_Button_Start_ActionAdapter
! implements ActionListener {
! ServerFrame adaptee;
!
! ServerFrame_Button_Start_ActionAdapter(ServerFrame adaptee) {
! this.adaptee = adaptee;
! }
!
! public void actionPerformed(ActionEvent evt) {
! adaptee.Button_Start_actionPerformed(evt);
! }
! }
!
! class ServerFrame_Button_Stop_ActionAdapter
! implements ActionListener {
! ServerFrame adaptee;
!
! ServerFrame_Button_Stop_ActionAdapter(ServerFrame adaptee) {
! this.adaptee = adaptee;
! }
!
! public void actionPerformed(ActionEvent evt) {
! adaptee.Button_Stop_actionPerformed(evt);
! }
! }
!
! class ServerFrame_Button_Quit_ActionAdapter
! implements ActionListener {
! ServerFrame adaptee;
!
! ServerFrame_Button_Quit_ActionAdapter(ServerFrame adaptee) {
! this.adaptee = adaptee;
! }
!
! public void actionPerformed(ActionEvent evt) {
! adaptee.Button_Quit_actionPerformed(evt);
! }
! }
!
! class TableClients
! extends JTable {
! private boolean DEBUG = false;
! private String[] columnNames = {
! "ID",
! "IP Client",
! "Port RTP",
! "Statut",
! "Media demande",
! "Debit",
! "Niveau de qualite"};
! private Object[][] data;
! private MyTableModel myModel = null;
!
! public TableClients() {
! super();
! myModel = new MyTableModel(data, columnNames);
! setModel(myModel);
! }
!
! public int getRowForClient(int _clientID) {
! for (int i = 0; i < myModel.getRowCount(); i++) {
! if (_clientID == ( (Integer) myModel.getValueAt(i, 0)).intValue()) {
! return i;
! }
! }
! return -1;
! }
!
! public void setValue(Object value, int row, int col) {
! myModel.setValueAt(value, row, col);
! }
!
! public void insertGraphics(JPanel jp) {
! JScrollPane sc = new JScrollPane(this);
! sc.setPreferredSize(new Dimension(750, 350));
! jp.add(sc);
! }
!
! public void newClientRecord(int _clientID, int _portRTP, String _IP,
! String _status) {
! Object[] newRow = {
! new Integer(_clientID), _IP, new Integer(_portRTP), _status, "nomedia",
! new Float(0.0), new Integer(1)};
! myModel.insertRow(0, newRow);
! }
!
! public void updateClientRecord(int _clientID, String _IP, int _portRTP,
! String _status,
! String _media, float _debit,
! int _qualityLevel) {
! int row = getRowForClient(_clientID);
!
! if (_IP != null) {
! setValue(_IP, row, 1);
! }
! if (_portRTP != 0) {
! setValue(new Integer(_portRTP), row, 2);
! }
! if (_status != null) {
! setValue(_status, row, 3);
! }
! if (_media != null) {
! setValue(_media, row, 4);
! }
! if (_debit != -1.0) {
! setValue(new Float(_debit), row, 5);
! }
! if (_qualityLevel != -1) {
! setValue(new Integer(_qualityLevel), row, 6);
! }
! }
!
!
! public void removeClientRecord(int _clientID) {
! ( (DefaultTableModel) getModel()).removeRow(getRowForClient(
! _clientID));
! }
!
! public synchronized void setIP(int _clientID, String _IP) {
!
! int row = getRowForClient(_clientID);
! setValue(_IP, row, 1);
! }
!
! public synchronized void setPortRTP(int _clientID, int _portRTP) {
!
! int row = getRowForClient(_clientID);
! setValue(new Integer(_portRTP), row, 2);
! }
!
! public synchronized void setStatus(int _clientID, String _status) {
!
! int row = getRowForClient(_clientID);
! setValue(_status, row, 3);
! }
!
! public synchronized void setMedia(int _clientID, String _media) {
! int row = getRowForClient(_clientID);
! setValue(_media, row, 4);
! }
!
! public synchronized void setDebit(int _clientID, float _debit) {
! int row = getRowForClient(_clientID);
! setValue(new Float(_debit), row, 5);
! }
!
! public synchronized void setQualityLevel(int _clientID, int _quality) {
! int row = getRowForClient(_clientID);
! setValue(new Integer(_quality), row, 6);
! }
!
! class MyTableModel
! extends DefaultTableModel {
!
! public MyTableModel() {
! super();
! }
!
! public MyTableModel(Object[][] data, Object[] columnNames) {
! super(data, columnNames);
! }
!
! /*
! * JTable uses this method to determine the default renderer/
! * editor for each cell. If we didn't implement this method,
! * then the last column would contain text ("true"/"false"),
! * rather than a check box.
! */
! public Class getColumnClass(int c) {
! return getValueAt(0, c).getClass();
! }
!
! public boolean isCellEditable(int row, int column) {
! return false;
! }
!
! private void printDebugData() {
! int numRows = getRowCount();
! int numCols = getColumnCount();
!
! for (int i = 0; i < numRows; i++) {
! System.out.print(" row " + i + ":");
! for (int j = 0; j < numCols; j++) {
! System.out.print(" " + data[i][j]);
! }
! System.out.println();
! }
! System.out.println("--------------------------");
! }
! }
!
! }
\ No newline at end of file
Index: ServerInit.java
===================================================================
RCS file: /cvsroot/madsserv/madsserv/src/server/ServerInit.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -d -r1.6 -r1.7
*** ServerInit.java 14 Mar 2003 03:26:18 -0000 1.6
--- ServerInit.java 17 Mar 2003 03:55:17 -0000 1.7
***************
*** 1,429 ****
! import java.util.*;
! import java.io.*;
! import java.net.*;
! import java.awt.*;
! import javax.media.rtp.*;
! import javax.media.*;
!
! ///////////////////////////////////////////////////////
! //
! // Server constitue la classe principale du serveur
! // Madsserv. Elle fera appel � des threads pour gerer
! // la communication par sockets avec les clients et le
! // simulateur.
! //
! //////////////////////////////////////////////////////
!
! /**
! * <code>ServerInit</code> constitue la classe de demarrage du serveur Madsserv.
! * Elle gere les connexions multiples de clients ainsi que l'instanciation des
! * modules necessaires au traitement des requetes de diffusion media.
! * @see Streaming
! * @see Reencode
! * @see Transition
! * @see GestionAdapta
! * @see DialogClient
! * @author Julien Carbonell
! */
!
! public class ServerInit {
!
! // ProcessorTest processor;
!
! // tabClients enregistre l'ensemble des clients connectes
! private ClientRecord[] tabClients;
! // tabDialog enregistre les objets de gestion des clients lances par Server a chaque nouvelle connexion
! private DialogClient[] tabDialogs;
! // tabStreaming enregistre les objets Streaming associes aux clients
! private Streaming[] tabStreaming;
! // tabReencode enregistre les objets Reencode associes aux clients
! private Reencode[] tabReencode;
! // tabTransition enregistre les objets Transition associes aux clients
! private Transition[] tabTransition;
!
! // Reference sur le gestionnnaire d'adaptabilite
! //private GestionAdapta gestionAdapta;
!
! // Reference sur le thread d'ecoute des clients
! private ThreadListenClients threadListenClients = null;
!
! // Parametres de connexion du serveur
! private int portListen;
! private int portBaseRTP;
! private int debitMin;
! private int nbMaxClients;
!
! // Socket d'ecoute clients
! private ServerSocket sockListen = null;
!
! // Interface graphique
! private ServerFrame serverFrame = null;
!
! /**
! * Constructeur de <code>ServerInit</code>.
! * @param _portListen le port d'ecoute du serveur.
! * @param _portBaseRTP le port de base a partir duquel sont deduits l'ensemble des ports necessaires a la creation des connexions RTP.
! * @param _nbMaxCliens le nombre maximum de clients acceptes par le serveur.
! * @param _debitMin le debit minimum en-dessous duquel le client est deconnecte.
! */
! public ServerInit(int _portListen, int _portBaseRTP, int _nbMaxClients,
! int _debitMin, ServerFrame _serverFrame) {
! portListen = _portListen;
! portBaseRTP = _portBaseRTP;
! nbMaxClients = _nbMaxClients;
! debitMin = _debitMin;
! serverFrame = _serverFrame;
!
! tabClients = new ClientRecord[nbMaxClients];
! tabDialogs = new DialogClient[nbMaxClients];
! tabStreaming = new Streaming[nbMaxClients];
! tabReencode = new Reencode[nbMaxClients];
! tabTransition = new Transition[nbMaxClients];
!
! //gestionAdapta = new GestionAdapta(......);
!
! //frame = new MainFrame(......);
! //frame.show();
! }
!
! /**
! * Ouvre le socket d'ecoute et demarre l'attente de connexions.
! */
! public void start() throws ErrNoListen {
!
! try {
! sockListen = new ServerSocket(portListen);
! threadListenClients = new ThreadListenClients(this, sockListen, portListen);
! threadListenClients.start();
! }
! catch (Exception e) {
! sockListen=null;
! threadListenClients = null;
! throw new ErrNoListen();
! }
! }
!
! /**
! * Arrete le serveur.
! */
! public void stop() {
! threadListenClients.close();
! }
!
! /**
! * Deconnecte un client en effaçant tous les objets relatifs au traitement de sa connexion.
! * @param _clientID l'ID du client a deconnecter.
! */
! public void endConnexion(int _clientID) {
! String[] warning = new String[1];
!
! warning[0] = "Attention je detruis la connexion du client 0";
! System.out.println("Envoi du message " + warning[0]);
! tabDialogs[_clientID].sendMessage(5, warning);
!
! tabStreaming[_clientID].stop();
! tabStreaming[_clientID] = null;
! /*tabReencode[_clientID].stop();
! tabTransition[_clientID].stop();
! tabReencode[_clientID] = null;
! tabReencode[_clientID] = null;*/
! System.out.println("Suppression du client " + _clientID);
! tabClients[_clientID] = null;
! tabDialogs[_clientID].stop();
! System.out.println("le client " + _clientID + " est mort -ref=" +
! tabClients[_clientID]);
! tabDialogs[_clientID] = null;
! System.err.println("Garbage collecting de endConnexion");
! System.gc();
! }
!
! /**
! * Renvoie l'IP d'un client.
! * @param _clientID l'ID du client.
! * @return l'adresse IP du client.
! */
! public String getIP(int _clientID) {
! return (tabClients[_clientID].getIP());
! }
!
! /**
! * Renvoie le port RTP de base affecte au client.
! * @param _clientID l'ID du client.
! * @return le port RTP de base affecte au client.
! */
! public int getPortRTP(int _clientID) {
! return (tabClients[_clientID].getPortRTP());
! }
!
! /**
! * Renvoie l'adresse du media demande par le client.
! * @param _clientID l'ID du client.
! * @return l'adresse du media demande par le client.
! */
! public String getMediaAddress(int _clientID) {
! return (tabClients[_clientID].getMediaAddress());
! }
!
! /**
! * Renvoie le format de diffusion prefere par le client.
! * @param _clientID l'ID du client.
! * @return le format de diffusion prefere par le client.
! */
! public String getPreferredFormat(int _clientID) {
! return (tabClients[_clientID].getPreferredFormat());
! }
!
! /**
! * Renvoie le niveau de qualité courant associé au client.
! * @param _clientID l'ID du client.
! * @return le niveau de qualite courant associe au client.
! */
! public int getQualityLevel(int _clientID) {
! return (tabClients[_clientID].getQualityLevel());
! }
!
! /**
! * Modifie l'IP d'un client.
! * @param _clientID l'ID du client.
! * @param _IP la nouvelle IP.
! */
! public synchronized void setIP(int _clientID, String _IP) {
! tabClients[_clientID].setIP(_IP);
! }
!
! /**
! * Modifie le port RTP de base d'un client.
! * @param _clientID l'ID du client.
! * @param _IP le nouveau port RTP de base.
! */
! public synchronized void setPortRTP(int _clientID, int _portBaseRTP) {
! tabClients[_clientID].setPortRTP(_portBaseRTP);
! }
!
! /**
! * Modifie l'adresse du media demande par le client.
! * @param _clientID l'ID du client.
! * @param _IP la nouvelle adresse du media demande par le client.
! */
! public synchronized void setMediaAddress(int _clientID, String _mediaAddress) {
! tabClients[_clientID].setMediaAddress(_mediaAddress);
! }
!
! /**
! * Modifie le format prefere d'un client.
! * @param _clientID l'ID du client.
! * @param _IP la nouvelle IP.
! */
! public synchronized void setPreferredFormat(int _clientID,
! String _preferredFormat) {
! tabClients[_clientID].setPreferredFormat(_preferredFormat);
! }
!
! /**
! * Modifie le niveau de qualite courant d'un client.
! * @param _clientID l'ID du client.
! * @param _IP la nouveau niveau de qualite.
! */
! public synchronized void setQualityLevel(int _clientID, int _qualityLevel) {
! tabClients[_clientID].setQualityLevel(_qualityLevel);
! }
!
! // cree un nouveau client dans la table et retourne le clientID affect�
! // retourne (-1) si trop de clients
!
! /**
! * Cree un nouveau client avec une ID et un numero de port RTP. La creation d'un
! * client est accompagnee par la creation des 3 modules de traitement des
! * requetes client ({@link Streaming}, {@link Reencode} et {@link Transiton}).
! * @return l'ID du client. Vaut <code>-1</code> si le nombre maximum de clients
! * est deja atteint (creation d'un nouveau client impossible).
! */
! public synchronized int createClient() {
! boolean inserted = false;
! int i = 0;
! while ( (inserted == false) && (i < nbMaxClients)) {
! if (tabClients[i] == null) {
! tabClients[i] = new ClientRecord();
! tabClients[i].setClientID(i);
! inserted = true;
! }
! i++;
! }
! if (inserted) {
! tabClients[i - 1].setPortRTP(portBaseRTP + 4 * (i - 1));
! tabStreaming[i - 1] = new Streaming(i - 1, this);
! return (i - 1);
! }
! else {
! return ( -1);
! }
! }
!
! /**
! * Cree un nouveau client a partir des arguments fournis. La creation d'un
! * client est accompagnee par la creation des 3 modules de traitement des
! * requetes client ({@link Streaming}, {@link Reencode} et {@link Transiton}).
! * @return l'ID du client. Vaut <code>-1</code> si le nombre maximum de clients
! * est deja atteint (creation d'un nouveau client impossible).
! */
! /* public synchronized int createClient(String _IP, int _portBaseRTP,
! String _mediaAddress,
! String _preferredFormat,
! int _qualityLevel) {
! boolean inserted = false;
! int i = 0;
! while ( (inserted == false) && (i < nbMaxClients)) {
! if (tabClients[i] == null) {
! tabClients[i] = new ClientRecord(i, _IP, _portBaseRTP, _mediaAddress,
! _preferredFormat, _qualityLevel);
! inserted = true;
! }
! i++;
! }
! if (inserted) {
! return (i - 1);
! }
! else {
! return ( -1);
! }
! }*/
!
! /**
! * Cree un nouveau <code>DialogClient</code> pour gerer la communication avec
! * un client.
! * @param _clientID l'ID du client.
! * @param _socketClient le {@link Socket} dedie a la communication avec le client.
! * @return le <code>DialogClient</code> cree.
! */
! public synchronized DialogClient createDialogClient(int _clientID,
! Socket _sockClient) {
! if (_clientID == -1) {
! DialogClient tempDialog = new DialogClient(_clientID, _sockClient, this);
! return tempDialog;
! }
! else {
! tabDialogs[_clientID] = new DialogClient(_clientID, _sockClient, this);
! return tabDialogs[_clientID];
! }
! }
!
! public void createReencode(int _clientID, String _URL) {
! if (tabReencode[_clientID] != null) {
! tabReencode[_clientID].stop();
! tabReencode[_clientID] = null;
! }
! tabReencode[_clientID] = new Reencode(_clientID, _URL);
! //tabReencode[_clientID].start();
! }
!
! /**
! * Demarre la diffusion du media demande pour un client donne.
! * @param _clientID l'ID du client.
! */
! public synchronized void startStreaming(int _clientID) {
! Streaming streamingTemp = tabStreaming[_clientID];
!
! streamingTemp.setClientIP(getIP(_clientID));
! streamingTemp.setClientPort(getPortRTP(_clientID));
! System.out.println("Le streaming a recu " + getIP(_clientID) + " et " +
! getPortRTP(_clientID));
! //streamingTemp.setMediaAddress(getMediaAddress(_clientID));
! if (!streamingTemp.isInitialized()) {
! streamingTemp.initialize();
! }
! System.out.println("Le streaming est initialise");
! //processor = new ProcessorTest(new MediaLocator(getMediaAddress(_clientID)),
! // streamingTemp);
! // System.out.println("Le processor est cree");
! // D�marrage du ProcessorTest
! // processor.start();
! tabReencode[_clientID].setStreamingRef(streamingTemp);
! tabReencode[_clientID].start();
! System.out.println("Le processeur a demarre");
!
! // On fournit la DataSource � diffuser
! //streamingTemp.setNewStreams(processor.getOutput());
! System.out.println("Le streaming a recu les nouveaux streams");
!
! }
!
! }
!
! class ClientRecord {
!
! private int clientID;
! private String IP;
! private int portRTP;
! private String mediaAddress;
! private String preferredFormat;
! private int qualityLevel;
!
! public ClientRecord() {
! clientID = -1;
! IP = "";
! portRTP = 40000;
! mediaAddress = "";
! preferredFormat = "";
! qualityLevel = 1;
! }
!
! public ClientRecord(int _clientID, String _IP, int _portRTP,
! String _mediaAddress, String _preferredFormat,
! int _qualityLevel) {
!
! clientID = _clientID;
! IP = _IP;
! portRTP = _portRTP;
! mediaAddress = _mediaAddress;
! preferredFormat = _preferredFormat;
! qualityLevel = _qualityLevel;
! }
!
! public int getClientID() {
! return clientID;
! }
!
! public String getIP() {
! return IP;
! }
!
! public int getPortRTP() {
! return portRTP;
! }
!
! public String getMediaAddress() {
! return mediaAddress;
! }
!
! public String getPreferredFormat() {
! return preferredFormat;
! }
!
! public int getQualityLevel() {
! return qualityLevel;
! }
!
! public void setClientID(int _clientID) {
! clientID = _clientID;
! }
!
! public void setIP(String _IP) {
! IP = _IP;
! }
!
! public void setPortRTP(int _portRTP) {
! portRTP = _portRTP;
! }
!
! public void setMediaAddress(String _mediaAddress) {
! mediaAddress = _mediaAddress;
! }
!
! public void setPreferredFormat(String _preferredFormat) {
! preferredFormat = _preferredFormat;
! }
!
! public void setQualityLevel(int _qualityLevel) {
! qualityLevel = _qualityLevel;
! }
! }
--- 1,503 ----
! import java.util.*;
! import java.io.*;
! import java.net.*;
! import java.awt.*;
! import javax.media.rtp.*;
! import javax.media.*;
!
! ///////////////////////////////////////////////////////
! //
! // Server constitue la classe principale du serveur
! // Madsserv. Elle fera appel ? des threads pour gerer
! // la communication par sockets avec les clients et le
! // simulateur.
! //
! //////////////////////////////////////////////////////
!
! /**
! * <code>ServerInit</code> constitue la classe de demarrage du serveur Madsserv.
! * Elle gere les connexions multiples de clients ainsi que l'instanciation des
! * modules necessaires au traitement des requetes de diffusion media.
! * @see Streaming
! * @see Reencode
! * @see Transition
! * @see GestionAdapta
! * @see DialogClient
! * @author Julien Carbonell
! */
!
! public class ServerInit {
!
! // ProcessorTest processor;
!
! // tabClients enregistre l'ensemble des clients connectes
! private ClientRecord[] tabClients;
! // tabDialog enregistre les objets de gestion des clients lances par Server a chaque nouvelle connexion
! private DialogClient[] tabDialogs;
! // tabStreaming enregistre les objets Streaming associes aux clients
! private Streaming[] tabStreaming;
! // tabReencode enregistre les objets Reencode associes aux clients
! private Reencode[] tabReencode;
! // tabTransition enregistre les objets Transition associes aux clients
! private Transition[] tabTransition;
!
! // Reference sur le gestionnnaire d'adaptabilite
! private GestionAdapta gestionAdapta;
!
! // Reference sur le thread d'ecoute des clients
! private ThreadListenClients threadListenClients = null;
!
! private ThreadListenSimulator threadListenSimulator = null;
! private DialogSimulator dialogSimulator = null;
!
! // Parametres de connexion du serveur
! private int portListenClients;
! private int portListenSimulator;
! private int portBaseRTP;
! private int debitMin;
! private int nbMaxClients;
!
! // indique si il y a deja un simulateur connecte
! private boolean simulatorConnected = false;
!
! // Socket d'ecoute clients
! private ServerSocket sockListenClients = null;
! private ServerSocket sockListenSimulator = null;
!
! // Interface graphique
! private ServerFrame serverFrame = null;
!
! /**
! * Constructeur de <code>ServerInit</code>.
! * @param _portListen le port d'ecoute du serveur.
! * @param _portBaseRTP le port de base a partir duquel sont deduits l'ensemble des ports necessaires a la creation des connexions RTP.
! * @param _nbMaxCliens le nombre maximum de clients acceptes par le serveur.
! * @param _debitMin le debit minimum en-dessous duquel le client est deconnecte.
! */
! public ServerInit(int _portListenClients, int _portListenSimulator,
! int _portBaseRTP, int _nbMaxClients,
! int _debitMin, ServerFrame _serverFrame) {
! portListenClients = _portListenClients;
! portListenSimulator = _portListenSimulator;
! portBaseRTP = _portBaseRTP;
! nbMaxClients = _nbMaxClients;
! debitMin = _debitMin;
! serverFrame = _serverFrame;
!
! tabClients = new ClientRecord[nbMaxClients];
! tabDialogs = new DialogClient[nbMaxClients];
! tabStreaming = new Streaming[nbMaxClients];
! tabReencode = new Reencode[nbMaxClients];
! tabTransition = new Transition[nbMaxClients];
!
! gestionAdapta = new GestionAdapta();
! }
!
! /**
! * Ouvre le socket d'ecoute et demarre l'attente de connexions.
! */
! public void start() throws ErrNoListen {
!
! try {
! sockListenClients = new ServerSocket(portListenClients);
! threadListenClients = new ThreadListenClients(this, sockListenClients,
! portListenClients);
! threadListenClients.start();
! }
! catch (Exception e) {
! sockListenClients = null;
! threadListenClients = null;
! throw new ErrNoListen();
! }
!
! try {
! sockListenSimulator = new ServerSocket(portListenSimulator);
! threadListenSimulator = new ThreadListenSimulator(this,
! sockListenSimulator, portListenSimulator);
! threadListenSimulator.start();
! }
! catch (Exception e) {
! sockListenSimulator = null;
! threadListenSimulator = null;
! throw new ErrNoListen();
! }
! }
!
! /**
! * Arrete le serveur.
! */
! public void stop() {
!
! for (int i = 0; i < nbMaxClients; i++) {
! if (tabClients[i] != null) {
! serverFrame.tableClients.removeClientRecord(i);
! endConnexionClient(i);
! }
! }
!
! threadListenSimulator.close();
! threadListenSimulator = null;
! threadListenClients.close();
! threadListenClients = null;
! System.gc();
! }
!
! /**
! * Deconnecte un client en effa�ant tous les objets relatifs au traitement de sa connexion.
! * @param _clientID l'ID du client a deconnecter.
! */
! public void endConnexionClient(int _clientID) {
! String[] warning = new String[1];
!
! if (_clientID == -1) {
! warning[0] = "Trop de clients connect?au serveur.";
! }
! else {
! warning[0] = "D?nnexion du client " + String.valueOf(_clientID);
! }
! System.out.println("Envoi du message " + warning[0]);
! tabDialogs[_clientID].sendMessage(5, warning);
!
! if (dialogSimulator != null) {
! warning[0] = String.valueOf(_clientID);
! dialogSimulator.sendMessage(3, warning);
!
! }
! try {
! Thread.sleep(500);
! }
! catch (Exception e) {
!
! }
! tabStreaming[_clientID].stop();
! tabStreaming[_clientID] = null;
! tabReencode[_clientID].stop();
! tabReencode[_clientID] = null;
! /* tabTransition[_clientID].stop();*/
! tabTransition[_clientID] = null;
! System.out.println("Suppression du client " + _clientID);
! tabClients[_clientID] = null;
! tabDialogs[_clientID].stop();
! System.out.println("le client " + _clientID + " est mort -ref=" +
! tabClients[_clientID]);
! tabDialogs[_clientID] = null;
! serverFrame.tableClients.removeClientRecord(_clientID);
! System.err.println("Garbage collecting de endConnexion");
! System.gc();
! }
!
! public void endConnexionSimulator(String _message) {
! String[] messageToSend = new String[1];
! messageToSend[0] = _message;
! if (simulatorConnected) {
! dialogSimulator.sendMessage(5, messageToSend);
! dialogSimulator.stop();
! simulatorConnected = false;
! dialogSimulator = null;
! System.gc();
! }
! else {
! System.err.println("Il n'y a pas de simulateur connecte");
! }
! }
!
! public void requestCurrentMediaTime(int _clientID) {
! tabDialogs[_clientID].sendMessage(7, null);
! }
!
! public void setCurrentMediaTime(int _clientID, double currentMediaTime) {
! tabTransition[_clientID].setCurrentMediaTime(currentMediaTime);
! }
!
! /**
! * Renvoie l'IP d'un client.
! * @param _clientID l'ID du client.
! * @return l'adresse IP du client.
! */
! public String getIP(int _clientID) {
! return (tabClients[_clientID].getIP());
! }
!
! /**
! * Renvoie le port RTP de base affecte au client.
! * @param _clientID l'ID du client.
! * @return le port RTP de base affecte au client.
! */
! public int getPortRTP(int _clientID) {
! return (tabClients[_clientID].getPortRTP());
! }
!
! /**
! * Renvoie l'adresse du media demande par le client.
! * @param _clientID l'ID du client.
! * @return l'adresse du media demande par le client.
! */
! public String getMediaAddress(int _clientID) {
! return (tabClients[_clientID].getMediaAddress());
! }
!
! /**
! * Renvoie le format de diffusion prefere par le client.
! * @param _clientID l'ID du client.
! * @return le format de diffusion prefere par le client.
! */
! public String getPreferredFormat(int _clientID) {
! return (tabClients[_clientID].getPreferredFormat());
! }
!
! /**
! * Renvoie le niveau de qualit� courant associ� au client.
! * @param _clientID l'ID du client.
! * @return le niveau de qualite courant associe au client.
! */
! public int getQualityLevel(int _clientID) {
! return (tabClients[_clientID].getQualityLevel());
! }
!
! /**
! * Modifie l'IP d'un client.
! * @param _clientID l'ID du client.
! * @param _IP la nouvelle IP.
! */
! public synchronized void setIP(int _clientID, String _IP) {
! tabClients[_clientID].setIP(_IP);
! }
!
! /**
! * Modifie le port RTP de base d'un client.
! * @param _clientID l'ID du client.
! * @param _IP le nouveau port RTP de base.
! */
! public synchronized void setPortRTP(int _clientID, int _portBaseRTP) {
! tabClients[_clientID].setPortRTP(_portBaseRTP);
! }
!
! public synchronized void setStatus(int _clientID, String _status) {
! tabClients[_clientID].setStatus(_status);
! }
!
! /**
! * Modifie l'adresse du media demande par le client.
! * @param _clientID l'ID du client.
! * @param _IP la nouvelle adresse du media demande par le client.
! */
! public synchronized void setMediaAddress(int _clientID, String _mediaAddress) {
! tabClients[_clientID].setMediaAddress(_mediaAddress);
! }
!
! /**
! * Modifie le format prefere d'un client.
! * @param _clientID l'ID du client.
! * @param _IP la nouvelle IP.
! */
! public synchronized void setPreferredFormat(int _clientID,
! String _preferredFormat) {
! tabClients[_clientID].setPreferredFormat(_preferredFormat);
! }
!
! /**
! * Modifie le niveau de qualite courant d'un client.
! * @param _clientID l'ID du client.
! * @param _IP la nouveau niveau de qualite.
! */
! public synchronized void setQualityLevel(int _clientID, int _qualityLevel) {
! tabClients[_clientID].setQualityLevel(_qualityLevel);
! tabTransition[_clientID].setQualityLevel(_qualityLevel);
!
! }
!
! // cree un nouveau client dans la table et retourne le clientID affect?
! // retourne (-1) si trop de clients
!
! /**
! * Cree un nouveau client avec une ID et un numero de port RTP. La creation d'un
! * client est accompagnee par la creation des 3 modules de traitement des
! * requetes client ({@link Streaming}, {@link Reencode} et {@link Transiton}).
! * @return l'ID du client. Vaut <code>-1</code> si le nombre maximum de clients
! * est deja atteint (creation d'un nouveau client impossible).
! */
! public synchronized int createClient() {
! boolean inserted = false;
! int i = 0;
! while (i < nbMaxClients) {
! if (tabClients[i] == null) {
! tabClients[i] = new ClientRecord(i);
! tabClients[i].setPortRTP(portBaseRTP + 4 * i);
! tabStreaming[i] = new Streaming(i, this);
! tabTransition[i] = new Transition(i, this);
! tabTransition[i].setStreaming(tabStreaming[i]);
! tabTransition[i].setGestionAdapta(gestionAdapta);
! if (dialogSimulator != null) {
! String[] messageToSend = new String[2];
! messageToSend[0] = String.valueOf(i);
! messageToSend[1] = String.valueOf(getQualityLevel(i));
! dialogSimulator.sendMessage(1, messageToSend);
! }
! return i;
! }
! i++;
! }
! return -1;
! }
!
! public void createDialogSimulator(Socket _socketSimulator) {
!
! if (simulatorConnected) {
! DialogSimulator dialogSimulatorTemp = new DialogSimulator(
! _socketSimulator, this);
! dialogSimulator.start();
! endConnexionSimulator("Un simulateur est deja connecte -> deconnexion");
! }
! else {
! dialogSimulator = new DialogSimulator(_socketSimulator, this);
! dialogSimulator.start();
! updateSimulator();
! }
! }
!
! public void updateSimulator() {
! String[] messageToSend;
! messageToSend = new String[2];
! for (int i = 0; i < nbMaxClients; i++) {
! if (tabClients[i] != null) {
! messageToSend[0] = String.valueOf(i);
! messageToSend[1] = String.valueOf(getQualityLevel(i));
! dialogSimulator.sendMessage(1, messageToSend);
! }
! }
!
! }
!
! /**
! * Cree un nouveau <code>DialogClient</code> pour gerer la communication avec
! * un client.
! * @param _clientID l'ID du client.
! * @param _socketClient le {@link Socket} dedie a la communication avec le client.
! * @return le <code>DialogClient</code> cree.
! */
! public synchronized DialogClient createDialogClient(int _clientID,
! Socket _sockClient) {
! if (_clientID == -1) {
! DialogClient tempDialog = new DialogClient(_clientID, _sockClient, this);
! return tempDialog;
! }
! else {
! tabDialogs[_clientID] = new DialogClient(_clientID, _sockClient, this);
! return tabDialogs[_clientID];
! }
! }
!
! public void createReencode(int _clientID, String _URL) {
! if (tabReencode[_clientID] != null) {
! tabReencode[_clientID].stop();
! tabReencode[_clientID] = null;
! System.gc();
! }
! tabReencode[_clientID] = new Reencode(_clientID, _URL);
! tabTransition[_clientID].setReencode(tabReencode[_clientID]);
! //tabReencode[_clientID].start();
!
! }
!
! /**
! * Demarre la diffusion du media demande pour un client donne.
! * @param _clientID l'ID du client.
! */
! public synchronized void startStreaming(int _clientID) {
! Streaming streamingTemp = tabStreaming[_clientID];
!
! streamingTemp.setClientIP(getIP(_clientID));
! streamingTemp.setClientPort(getPortRTP(_clientID));
! System.out.println("Le streaming a recu " + getIP(_clientID) + " et " +
! getPortRTP(_clientID));
! if (!streamingTemp.isInitialized()) {
! streamingTemp.initialize();
! }
! System.out.println("Le streaming est initialise");
! tabReencode[_clientID].setStreamingRef(streamingTemp);
! tabTransition[_clientID].setQualityLevel(getQualityLevel(_clientID));
! }
!
! class ClientRecord {
!
! private int clientID;
! private String IP;
! private int portRTP;
! private String status;
! private String mediaAddress;
! private String preferredFormat;
! private int qualityLevel;
!
! publi...
[truncated message content] |