resolvendo conflitos
This commit is contained in:
commit
543073e84e
|
|
@ -0,0 +1,7 @@
|
|||
/pitiupi/build/
|
||||
/pitiupi/dist/
|
||||
/pitiupi.chat/build/
|
||||
/pitiupi.chat/dist/
|
||||
/pitiupi.chat/nbproject/private/
|
||||
/pitiupi.screenCast/build/
|
||||
/pitiupi.screenCast/dist/
|
||||
|
|
@ -94,7 +94,7 @@ public class ChatWindow extends javax.swing.JDialog {
|
|||
if (jTextArea1.getText().trim().length() == 0) {
|
||||
return;
|
||||
}
|
||||
ChatMessage message = new ChatMessage(mainWindow.getName(), jTextArea1.getText());
|
||||
ChatMessage message = new ChatMessage(mainWindow.getUserName(), jTextArea1.getText());
|
||||
this.sendChatMessage(message);
|
||||
jTextArea1.setText("");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,61 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="AutoImportSettings">
|
||||
<option name="autoReloadType" value="SELECTIVE" />
|
||||
</component>
|
||||
<component name="ChangeListManager">
|
||||
<list default="true" id="083e72ce-fa9b-4ddf-a0ef-24105aa3eabb" name="Changes" comment="">
|
||||
<change afterPath="$PROJECT_DIR$/../pitiupi.quiz/src/META-INF/services/pitiupi.plugin.Plugin" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/../pitiupi.quiz/src/pitiupi/GUI/QuizWindow.java" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/../pitiupi.quiz/src/pitiupi/control/Pergunta.java" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/../pitiupi.quiz/src/pitiupi/control/Quiz.java" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/../pitiupi.quiz/src/pitiupi/net/QuizMessage.java" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/../pitiupi.quiz/src/pitiupi/plugin/Quiz.java" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/../.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/../.idea/workspace.xml" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/pitiupi/screenCast/net/ScreenCastMessage.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/pitiupi/screenCast/net/ScreenCastMessage.java" afterDir="false" />
|
||||
</list>
|
||||
<option name="SHOW_DIALOG" value="false" />
|
||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
|
||||
<option name="LAST_RESOLUTION" value="IGNORE" />
|
||||
</component>
|
||||
<component name="Git.Settings">
|
||||
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$/.." />
|
||||
</component>
|
||||
<component name="ProjectColorInfo"><![CDATA[{
|
||||
"associatedIndex": 7
|
||||
}]]></component>
|
||||
<component name="ProjectId" id="3Gs0wFaRD4HyhP9VXLUWBeq0qTL" />
|
||||
<component name="ProjectViewState">
|
||||
<option name="hideEmptyMiddlePackages" value="true" />
|
||||
<option name="showLibraryContents" value="true" />
|
||||
</component>
|
||||
<component name="PropertiesComponent"><![CDATA[{
|
||||
"keyToString": {
|
||||
"ModuleVcsDetector.initialDetectionPerformed": "true",
|
||||
"RunOnceActivity.ShowReadmeOnStart": "true",
|
||||
"RunOnceActivity.git.unshallow": "true",
|
||||
"git-widget-placeholder": "QuizPlugin",
|
||||
"kotlin-language-version-configured": "true",
|
||||
"last_opened_file_path": "C:/Users/extre/OneDrive/Documentos/Faculdade/2026_02/Monitoria/Pitiupi/pitiupi.screenCast",
|
||||
"settings.editor.selected.configurable": "preferences.keymap"
|
||||
}
|
||||
}]]></component>
|
||||
<component name="SharedIndexes">
|
||||
<attachedChunks>
|
||||
<set>
|
||||
<option value="bundled-jdk-9823dce3aa75-bf35d07a577b-intellij.indexing.shared.core-IU-252.28539.54" />
|
||||
</set>
|
||||
</attachedChunks>
|
||||
</component>
|
||||
<component name="TaskManager">
|
||||
<task active="true" id="Default" summary="Default task">
|
||||
<changelist id="083e72ce-fa9b-4ddf-a0ef-24105aa3eabb" name="Changes" comment="" />
|
||||
<created>1784745206049</created>
|
||||
<option name="number" value="Default" />
|
||||
<option name="presentableId" value="Default" />
|
||||
<updated>1784745206049</updated>
|
||||
</task>
|
||||
<servers />
|
||||
</component>
|
||||
</project>
|
||||
|
|
@ -1,8 +1,3 @@
|
|||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package pitiupi.GUI;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
|
|
@ -11,6 +6,7 @@ import java.awt.GridBagConstraints;
|
|||
import java.awt.GridBagLayout;
|
||||
import java.awt.Insets;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.util.prefs.Preferences;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JDialog;
|
||||
|
|
@ -26,9 +22,14 @@ import javax.swing.JTextField;
|
|||
* multicast que será utilizada pela comunicação.</p>
|
||||
*
|
||||
* @author flavio
|
||||
* @author tony
|
||||
*/
|
||||
public final class Login extends JDialog {
|
||||
|
||||
private static final Preferences prefs = Preferences.userNodeForPackage(Login.class);
|
||||
private static final String PREF_NOME = "lastUserName";
|
||||
private static final String PREF_PORTA = "lastPort";
|
||||
|
||||
JLabel nameLabel = new JLabel("Name: ");
|
||||
JLabel portLabel = new JLabel("Port: ");
|
||||
|
||||
|
|
@ -47,8 +48,12 @@ public final class Login extends JDialog {
|
|||
public void initComponents() {
|
||||
this.setTitle("Login");
|
||||
|
||||
portField.setModel(new javax.swing.SpinnerNumberModel(8000, 8000, 9000, 1));
|
||||
nameField.setText(System.getProperty("user.name"));
|
||||
|
||||
String nomeSalvo = prefs.get(PREF_NOME, System.getProperty("user.name"));
|
||||
int portaSalva = prefs.getInt(PREF_PORTA, 8000);
|
||||
|
||||
portField.setModel(new javax.swing.SpinnerNumberModel(portaSalva, 8000, 9000, 1));
|
||||
nameField.setText(nomeSalvo);
|
||||
|
||||
JPanel topPanel = new JPanel(new GridBagLayout());
|
||||
JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
|
||||
|
|
@ -87,6 +92,15 @@ public final class Login extends JDialog {
|
|||
this.add(buttonPanel, BorderLayout.SOUTH);
|
||||
|
||||
okButton.addActionListener((ActionEvent e) -> {
|
||||
try {
|
||||
portField.commitEdit();
|
||||
} catch (java.text.ParseException ex) {
|
||||
return;
|
||||
}
|
||||
|
||||
prefs.put(PREF_NOME, nameField.getText());
|
||||
prefs.putInt(PREF_PORTA, (Integer) portField.getValue());
|
||||
|
||||
Login.this.setVisible(false);
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -41,8 +41,8 @@ public class MainWindow extends javax.swing.JFrame {
|
|||
|
||||
private Socket socket;
|
||||
|
||||
private final String userName;
|
||||
private final int port;
|
||||
private String userName;
|
||||
private int port;
|
||||
|
||||
private PluginLoader pluginManager;
|
||||
private final List<Plugin> plugins;
|
||||
|
|
@ -137,4 +137,28 @@ public class MainWindow extends javax.swing.JFrame {
|
|||
public List<Plugin> getPlugins() {
|
||||
return plugins;
|
||||
}
|
||||
|
||||
public void setUserName(String userName) {
|
||||
this.userName = userName;
|
||||
updateStatus();
|
||||
}
|
||||
|
||||
public void setPort(int port) {
|
||||
this.port = port;
|
||||
reconnect();
|
||||
updateStatus();
|
||||
}
|
||||
|
||||
private void updateStatus() {
|
||||
this.status.setText("Connected on port " + this.port + " name " + this.userName);
|
||||
}
|
||||
|
||||
private void reconnect() {
|
||||
if (this.socket != null) {
|
||||
this.socket.close();
|
||||
}
|
||||
this.socket = new Socket(this);
|
||||
this.socket.start();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,6 +16,8 @@ import javax.swing.JMenuBar;
|
|||
*
|
||||
* @author flavio
|
||||
* @author Gustavo
|
||||
* @author tony
|
||||
*
|
||||
*/
|
||||
public class MenuBar extends JMenuBar {
|
||||
|
||||
|
|
@ -67,9 +69,14 @@ public class MenuBar extends JMenuBar {
|
|||
mainWindow.exit();
|
||||
}
|
||||
|
||||
private void setupMenuActionPerformed(java.awt.event.ActionEvent evt) {
|
||||
|
||||
private void setupMenuActionPerformed(java.awt.event.ActionEvent evt) {
|
||||
Login login = new Login();
|
||||
login.setVisible(true);
|
||||
|
||||
mainWindow.setUserName(login.getName());
|
||||
mainWindow.setPort(login.getPort());
|
||||
|
||||
login.dispose();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ import java.util.logging.Logger;
|
|||
/**
|
||||
*
|
||||
* @author flavio
|
||||
* @author tony
|
||||
*/
|
||||
public class Main {
|
||||
/**
|
||||
|
|
@ -39,14 +40,15 @@ public class Main {
|
|||
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
|
||||
java.util.logging.Logger.getLogger(pitiupi.GUI.MainWindow.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
|
||||
}
|
||||
//</editor-fold>
|
||||
|
||||
/* Create and display the form */
|
||||
java.awt.EventQueue.invokeLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
pitiupi.GUI.Login login = new pitiupi.GUI.Login();
|
||||
login.setVisible(true);
|
||||
|
||||
pitiupi.GUI.MainWindow main;
|
||||
main = new pitiupi.GUI.MainWindow(System.getProperty("user.name"), 8000);
|
||||
main = new pitiupi.GUI.MainWindow(login.getName(), login.getPort());
|
||||
main.setVisible(true);
|
||||
}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ import java.util.logging.Level;
|
|||
import java.util.logging.Logger;
|
||||
import pitiupi.GUI.MainWindow;
|
||||
import pitiupi.net.HeartbeatMessage;
|
||||
import java.util.UUID;
|
||||
/**
|
||||
* Gerencia o mecanismo de heartbeat da aplicação.
|
||||
*
|
||||
|
|
@ -32,6 +33,7 @@ public class HeartbeatManager {
|
|||
private final Map<String, PeerInfo> peers = new ConcurrentHashMap<>();
|
||||
private final List<PeerListener> listeners = new CopyOnWriteArrayList<>();
|
||||
private ScheduledExecutorService scheduler;
|
||||
private final String instanceId = UUID.randomUUID().toString();
|
||||
|
||||
public HeartbeatManager(MainWindow mainWindow) {
|
||||
this.mainWindow = mainWindow;
|
||||
|
|
@ -51,7 +53,7 @@ public class HeartbeatManager {
|
|||
|
||||
private void announce() {
|
||||
try {
|
||||
HeartbeatMessage msg = new HeartbeatMessage(mainWindow.getUserName());
|
||||
HeartbeatMessage msg = new HeartbeatMessage(mainWindow.getUserName(), instanceId);
|
||||
mainWindow.getSocket().send(msg.toByteArray());
|
||||
} catch (IOException ex) {
|
||||
Logger.getLogger(HeartbeatManager.class.getName()).log(Level.WARNING, "Falha ao enviar heartbeat", ex);
|
||||
|
|
@ -70,13 +72,14 @@ public class HeartbeatManager {
|
|||
* @param msg mensagem de heartbeat recebida.
|
||||
* @param from endereço de rede do usuário que enviou a mensagem.
|
||||
*/
|
||||
|
||||
public void receiveHeartbeat(HeartbeatMessage msg, InetAddress from) {
|
||||
// ignora o próprio heartbeat
|
||||
if (msg.getUserName().equals(mainWindow.getUserName())) {
|
||||
if (msg.getInstanceId().equals(instanceId) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
String key = from.getHostAddress() + "#" + msg.getUserName();
|
||||
String key = msg.getInstanceId();
|
||||
boolean isNew = !peers.containsKey(key);
|
||||
|
||||
PeerInfo peer = peers.computeIfAbsent(key, k -> new PeerInfo(msg.getUserName(), from, msg.getTimestamp()));
|
||||
|
|
|
|||
|
|
@ -11,9 +11,11 @@ public class HeartbeatMessage extends Message {
|
|||
|
||||
private final String userName;
|
||||
private final long timestamp;
|
||||
private final String instanceId;
|
||||
|
||||
public HeartbeatMessage(String userName) {
|
||||
public HeartbeatMessage(String userName, String instanceId) {
|
||||
this.userName = userName;
|
||||
this.instanceId = instanceId;
|
||||
this.timestamp = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
|
|
@ -24,4 +26,8 @@ public class HeartbeatMessage extends Message {
|
|||
public long getTimestamp() {
|
||||
return timestamp;
|
||||
}
|
||||
|
||||
public String getInstanceId() {
|
||||
return instanceId;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,6 +33,7 @@ public class Socket extends Thread {
|
|||
private MulticastSocket multicastSocket;
|
||||
private InetAddress address;
|
||||
private MainWindow main;
|
||||
private volatile boolean running = true;
|
||||
public final static String INET_ADDR = "224.0.0.3";
|
||||
|
||||
/**
|
||||
|
|
@ -71,6 +72,19 @@ public class Socket extends Thread {
|
|||
multicastSocket.send(msgPacket);
|
||||
}
|
||||
|
||||
public void close() {
|
||||
running = false;
|
||||
if (multicastSocket != null) {
|
||||
try {
|
||||
multicastSocket.leaveGroup(address);
|
||||
} catch (IOException ex) {
|
||||
|
||||
}
|
||||
multicastSocket.close();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Inicia o loop de recepção de mensagens da aplicação.
|
||||
*
|
||||
|
|
@ -84,16 +98,21 @@ public class Socket extends Thread {
|
|||
*/
|
||||
public void receive() throws UnknownHostException, IOException, ClassNotFoundException {
|
||||
byte[] buf = new byte[256000];
|
||||
while (true) {
|
||||
while (running) {
|
||||
DatagramPacket msgPacket = new DatagramPacket(buf, buf.length);
|
||||
multicastSocket.receive(msgPacket);
|
||||
|
||||
try {
|
||||
multicastSocket.receive(msgPacket);
|
||||
} catch (IOException ex) {
|
||||
if (!running) {
|
||||
break;
|
||||
}
|
||||
throw ex;
|
||||
}
|
||||
HeartbeatMessage heartbeat = tryParseHeartbeat(msgPacket.getData());
|
||||
if (heartbeat != null) {
|
||||
main.getHeartbeatManager().receiveHeartbeat(heartbeat, msgPacket.getAddress());
|
||||
continue;
|
||||
}
|
||||
|
||||
for (Plugin plugin : main.getPlugins()) {
|
||||
System.out.println(msgPacket.getAddress().toString());
|
||||
plugin.receiveMessage(msgPacket.getData());
|
||||
|
|
|
|||
Loading…
Reference in New Issue