Compare commits

..

No commits in common. "81c37225fac91d24e8651da729d0282cc09af6a2" and "cf43f6279395d0041a46798cfe7ccabde3915c37" have entirely different histories.

12 changed files with 67 additions and 224 deletions

7
.gitignore vendored
View File

@ -1,7 +0,0 @@
/pitiupi/build/
/pitiupi/dist/
/pitiupi.chat/build/
/pitiupi.chat/dist/
/pitiupi.chat/nbproject/private/
/pitiupi.screenCast/build/
/pitiupi.screenCast/dist/

View File

@ -4,7 +4,29 @@
<option name="autoReloadType" value="SELECTIVE" />
</component>
<component name="ChangeListManager">
<list default="true" id="62118a1b-608f-4144-b29c-cf46419ca676" name="Changes" comment="" />
<list default="true" id="62118a1b-608f-4144-b29c-cf46419ca676" name="Changes" comment="">
<change afterPath="$PROJECT_DIR$/pitiupi/Documentation.md" afterDir="false" />
<change afterPath="$PROJECT_DIR$/pitiupi/PluginTutorial.md" afterDir="false" />
<change beforePath="$PROJECT_DIR$/pitiupi.chat/build/built-jar.properties" beforeDir="false" afterPath="$PROJECT_DIR$/pitiupi.chat/build/built-jar.properties" afterDir="false" />
<change beforePath="$PROJECT_DIR$/pitiupi.chat/dist/pitiupi.chat.jar" beforeDir="false" afterPath="$PROJECT_DIR$/pitiupi.chat/dist/pitiupi.chat.jar" afterDir="false" />
<change beforePath="$PROJECT_DIR$/pitiupi.screenCast/build/built-jar.properties" beforeDir="false" afterPath="$PROJECT_DIR$/pitiupi.screenCast/build/built-jar.properties" afterDir="false" />
<change beforePath="$PROJECT_DIR$/pitiupi.screenCast/dist/pitiupi.screenCast.jar" beforeDir="false" afterPath="$PROJECT_DIR$/pitiupi.screenCast/dist/pitiupi.screenCast.jar" afterDir="false" />
<change beforePath="$PROJECT_DIR$/pitiupi/build/classes/.netbeans_automatic_build" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/pitiupi/build/classes/.netbeans_update_resources" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/pitiupi/build/classes/pitiupi/GUI/Login.class" beforeDir="false" afterPath="$PROJECT_DIR$/pitiupi/build/classes/pitiupi/GUI/Login.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/pitiupi/build/classes/pitiupi/GUI/MainWindow.class" beforeDir="false" afterPath="$PROJECT_DIR$/pitiupi/build/classes/pitiupi/GUI/MainWindow.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/pitiupi/build/classes/pitiupi/GUI/MenuBar.class" beforeDir="false" afterPath="$PROJECT_DIR$/pitiupi/build/classes/pitiupi/GUI/MenuBar.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/pitiupi/build/classes/pitiupi/Main$1.class" beforeDir="false" afterPath="$PROJECT_DIR$/pitiupi/build/classes/pitiupi/Main$1.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/pitiupi/build/classes/pitiupi/Main.class" beforeDir="false" afterPath="$PROJECT_DIR$/pitiupi/build/classes/pitiupi/Main.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/pitiupi/build/classes/pitiupi/control/PluginLoader.class" beforeDir="false" afterPath="$PROJECT_DIR$/pitiupi/build/classes/pitiupi/control/PluginLoader.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/pitiupi/build/classes/pitiupi/net/Socket.class" beforeDir="false" afterPath="$PROJECT_DIR$/pitiupi/build/classes/pitiupi/net/Socket.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/pitiupi/build/classes/pitiupi/plugin/Plugin.class" beforeDir="false" afterPath="$PROJECT_DIR$/pitiupi/build/classes/pitiupi/plugin/Plugin.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/pitiupi/dist/README.TXT" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/pitiupi/dist/pitiupi.jar" beforeDir="false" afterPath="$PROJECT_DIR$/pitiupi/dist/pitiupi.jar" afterDir="false" />
<change beforePath="$PROJECT_DIR$/pitiupi/plugins/pitiupi.chat.jar" beforeDir="false" afterPath="$PROJECT_DIR$/pitiupi/plugins/pitiupi.chat.jar" afterDir="false" />
<change beforePath="$PROJECT_DIR$/pitiupi/plugins/pitiupi.screenCast.jar" beforeDir="false" afterPath="$PROJECT_DIR$/pitiupi/plugins/pitiupi.screenCast.jar" afterDir="false" />
<change beforePath="$PROJECT_DIR$/pitiupi/src/pitiupi/GUI/MenuBar.java" beforeDir="false" afterPath="$PROJECT_DIR$/pitiupi/src/pitiupi/GUI/MenuBar.java" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
@ -21,20 +43,20 @@
<option name="hideEmptyMiddlePackages" value="true" />
<option name="showLibraryContents" value="true" />
</component>
<component name="PropertiesComponent">{
&quot;keyToString&quot;: {
&quot;Application.Main.executor&quot;: &quot;Run&quot;,
&quot;ModuleVcsDetector.initialDetectionPerformed&quot;: &quot;true&quot;,
&quot;RunOnceActivity.ShowReadmeOnStart&quot;: &quot;true&quot;,
&quot;RunOnceActivity.TerminalTabsStorage.copyFrom.TerminalArrangementManager.252&quot;: &quot;true&quot;,
&quot;RunOnceActivity.git.unshallow&quot;: &quot;true&quot;,
&quot;git-widget-placeholder&quot;: &quot;feature/help-and-documentation&quot;,
&quot;ignore.virus.scanning.warn.message&quot;: &quot;true&quot;,
&quot;kotlin-language-version-configured&quot;: &quot;true&quot;,
&quot;last_opened_file_path&quot;: &quot;C:/Users/extre/OneDrive/Documentos/Faculdade/2026_02/Monitoria/Pitiupi&quot;,
&quot;settings.editor.selected.configurable&quot;: &quot;preferences.keymap&quot;
<component name="PropertiesComponent"><![CDATA[{
"keyToString": {
"Application.Main.executor": "Run",
"ModuleVcsDetector.initialDetectionPerformed": "true",
"RunOnceActivity.ShowReadmeOnStart": "true",
"RunOnceActivity.TerminalTabsStorage.copyFrom.TerminalArrangementManager.252": "true",
"RunOnceActivity.git.unshallow": "true",
"git-widget-placeholder": "feature/help-and-documentation",
"ignore.virus.scanning.warn.message": "true",
"kotlin-language-version-configured": "true",
"last_opened_file_path": "C:/Users/extre/OneDrive/Documentos/Faculdade/2026_02/Monitoria/Pitiupi",
"settings.editor.selected.configurable": "preferences.keymap"
}
}</component>
}]]></component>
<component name="RecentsManager">
<key name="CopyFile.RECENT_KEYS">
<recent name="C:\Users\extre\OneDrive\Documentos\Faculdade\2026_02\Monitoria\Pitiupi\pitiupi\plugins" />

View File

@ -94,7 +94,7 @@ public class ChatWindow extends javax.swing.JDialog {
if (jTextArea1.getText().trim().length() == 0) {
return;
}
ChatMessage message = new ChatMessage(mainWindow.getUserName(), jTextArea1.getText());
ChatMessage message = new ChatMessage(mainWindow.getName(), jTextArea1.getText());
this.sendChatMessage(message);
jTextArea1.setText("");
}

View File

@ -1,61 +0,0 @@
<?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>

View File

@ -60,7 +60,7 @@ O método `send()` recebe uma mensagem já serializada em bytes e cria um
De forma geral, o socket atua apenas como mecanismo de transporte das mensagens.
A única exceção é o tratamento de HeartbeatMessage, utilizado pela infraestrutura
da aplicação para manter a lista de peers ativos.
da aplicação para manter a lista de usuários ativos.
#### Recepção de mensagens
@ -98,15 +98,9 @@ comportamentos necessários para cada funcionalidade.
O mecanismo de heartbeat é utilizado para identificar quais usuários estão
ativos na rede.
A aplicação envia periodicamente uma `HeartbeatMessage` contendo
informações do usuário, um identificador único da instância da aplicação
e um timestamp. Quando outra instância recebe essa mensagem, o `HeartbeatManager`
registra ou atualiza o peer correspondente, utilizando o identificador
da instância para diferenciá-lo das demais.
Um peer é considerado inativo quando permanece mais de 15 segundos
sem receber um novo heartbeat. O `HeartbeatManager` então remove o peer
da lista e notifica os listeners sobre a alteração.
A aplicação envia periodicamente uma `HeartbeatMessage` contendo informações
do usuário e um timestamp. Quando outra instância recebe essa mensagem, o
`HeartbeatManager` atualiza o registro do usuário correspondente.
O fluxo de heartbeat é independente das mensagens dos plugins:
@ -115,7 +109,7 @@ O fluxo de heartbeat é independente das mensagens dos plugins:
3. O `Socket` transmite a mensagem pela rede multicast.
4. O `Socket` identifica mensagens de heartbeat recebidas e encaminha ao
`HeartbeatManager`.
5. O `HeartbeatManager` atualiza a lista de peers ativos e notifica os
5. O `HeartbeatManager` atualiza a lista de usuários ativos e notifica os
listeners.
## Sistema de plugins

View File

@ -1,3 +1,8 @@
/*
* 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;
@ -6,7 +11,6 @@ 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;
@ -22,14 +26,9 @@ 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: ");
@ -48,12 +47,8 @@ public final class Login extends JDialog {
public void initComponents() {
this.setTitle("Login");
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);
portField.setModel(new javax.swing.SpinnerNumberModel(8000, 8000, 9000, 1));
nameField.setText(System.getProperty("user.name"));
JPanel topPanel = new JPanel(new GridBagLayout());
JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
@ -92,15 +87,6 @@ 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);
});

View File

@ -41,8 +41,8 @@ public class MainWindow extends javax.swing.JFrame {
private Socket socket;
private String userName;
private int port;
private final String userName;
private final int port;
private PluginLoader pluginManager;
private final List<Plugin> plugins;
@ -137,28 +137,4 @@ 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();
}
}

View File

@ -16,8 +16,6 @@ import javax.swing.JMenuBar;
*
* @author flavio
* @author Gustavo
* @author tony
*
*/
public class MenuBar extends JMenuBar {
@ -29,11 +27,6 @@ public class MenuBar extends JMenuBar {
private javax.swing.JMenuItem exitMenu;
private final MainWindow mainWindow;
/**
* Cria a barra de menus principal da aplicação.
*
* @param mainWindow mainWindow janela principal da aplicação utilizada para executar
*/
public MenuBar(MainWindow mainWindow) {
this.mainWindow = mainWindow;
this.initComponents();
@ -74,14 +67,9 @@ 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();
}

View File

@ -12,7 +12,6 @@ import java.util.logging.Logger;
/**
*
* @author flavio
* @author tony
*/
public class Main {
/**
@ -40,15 +39,14 @@ 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(login.getName(), login.getPort());
main = new pitiupi.GUI.MainWindow(System.getProperty("user.name"), 8000);
main.setVisible(true);
}
});

View File

@ -14,7 +14,6 @@ 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.
*
@ -33,30 +32,17 @@ 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();
/**
* Cria um gerenciador de heartbeat associado à janela principal da aplicação.
*
* @param mainWindow janela principal utilizada para obter o nome do usuário
* e o socket de comunicação.
*/
public HeartbeatManager(MainWindow mainWindow) {
this.mainWindow = mainWindow;
}
/**
* Inicia o mecanismo de heartbeat.
*/
public void start() {
scheduler = Executors.newScheduledThreadPool(1);
scheduler.scheduleAtFixedRate(this::announce, 0, HEARTBEAT_INTERVAL_MS, TimeUnit.MILLISECONDS);
scheduler.scheduleAtFixedRate(this::checkTimeouts, HEARTBEAT_INTERVAL_MS, HEARTBEAT_INTERVAL_MS, TimeUnit.MILLISECONDS);
}
/**
* Para o mecanismo de heartbeat e encerra as tarefas agendadas.
*/
public void stop() {
if (scheduler != null) {
scheduler.shutdownNow();
@ -65,7 +51,7 @@ public class HeartbeatManager {
private void announce() {
try {
HeartbeatMessage msg = new HeartbeatMessage(mainWindow.getUserName(), instanceId);
HeartbeatMessage msg = new HeartbeatMessage(mainWindow.getUserName());
mainWindow.getSocket().send(msg.toByteArray());
} catch (IOException ex) {
Logger.getLogger(HeartbeatManager.class.getName()).log(Level.WARNING, "Falha ao enviar heartbeat", ex);
@ -76,22 +62,21 @@ public class HeartbeatManager {
/**
* Processa uma mensagem de heartbeat recebida de outro usuário.
*
* <p>Atualiza o momento da última atividade do peer correspondente e notifica os listeners
* caso outra instância da aplicação seja identificada.</p>
* <p>Atualiza a informação do peer correspondente e notifica os listeners
* caso um novo usuário seja identificado.</p>
*
* <p>Mensagens de heartbeat enviadas pela própria aplicação são ignoradas.</p>
*
* @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.getInstanceId().equals(instanceId) ) {
if (msg.getUserName().equals(mainWindow.getUserName())) {
return;
}
String key = msg.getInstanceId();
String key = from.getHostAddress() + "#" + msg.getUserName();
boolean isNew = !peers.containsKey(key);
PeerInfo peer = peers.computeIfAbsent(key, k -> new PeerInfo(msg.getUserName(), from, msg.getTimestamp()));
@ -130,20 +115,10 @@ public class HeartbeatManager {
l.onPeersChanged(new ArrayList<>(peers.values()));
}
/**
* Remove um listener previamente registrado.
*
* @param l listener que deixará de receber atualizações.
*/
public void removePeerListener(PeerListener l) {
listeners.remove(l);
}
/**
* Retorna uma cópia da lista atual de peers conhecidos.
*
* @return lista contendo os peers atualmente conhecidos.
*/
public List<PeerInfo> getPeers() {
return new ArrayList<>(peers.values());
}

View File

@ -11,11 +11,9 @@ public class HeartbeatMessage extends Message {
private final String userName;
private final long timestamp;
private final String instanceId;
public HeartbeatMessage(String userName, String instanceId) {
public HeartbeatMessage(String userName) {
this.userName = userName;
this.instanceId = instanceId;
this.timestamp = System.currentTimeMillis();
}
@ -26,8 +24,4 @@ public class HeartbeatMessage extends Message {
public long getTimestamp() {
return timestamp;
}
public String getInstanceId() {
return instanceId;
}
}

View File

@ -20,7 +20,7 @@ import pitiupi.plugin.Plugin;
import pitiupi.net.HeartbeatMessage;
/**
* "Responsável pela comunicação multicast da aplicação e pelo encaminhamento de mensagens aos plugins."
* Responsável pela comunicação multicast entre a aplicação e os plugins.
*
* <p>Esta classe gerencia o envio e o recebimento de mensagens, além de
* manter a conexão com o grupo multicast utilizado pela aplicação.</p>
@ -33,7 +33,6 @@ 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";
/**
@ -72,22 +71,6 @@ public class Socket extends Thread {
multicastSocket.send(msgPacket);
}
/**
* Encerra a comunicação multicast e interrompe a recepção de mensagens.
*/
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.
*
@ -101,21 +84,16 @@ public class Socket extends Thread {
*/
public void receive() throws UnknownHostException, IOException, ClassNotFoundException {
byte[] buf = new byte[256000];
while (running) {
while (true) {
DatagramPacket msgPacket = new DatagramPacket(buf, buf.length);
try {
multicastSocket.receive(msgPacket);
} catch (IOException ex) {
if (!running) {
break;
}
throw ex;
}
multicastSocket.receive(msgPacket);
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());