Merge branch 'dev' into maximilien

# Conflicts:
#	.idea/.gitignore
#	.idea/misc.xml
This commit is contained in:
Maximilien LEDOUX 2022-02-20 11:29:41 +01:00
commit 09b90e6067
11 changed files with 339 additions and 14 deletions

4
.idea/.gitignore vendored
View File

@ -1,8 +1,8 @@
# Default ignored files
/shelf/
/workspace.xml
# Editor-based HTTP Client requests
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml
# Editor-based HTTP Client requests
/httpRequests/

7
.idea/discord.xml Normal file
View File

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="DiscordProjectSettings">
<option name="show" value="PROJECT_FILES" />
<option name="description" value="" />
</component>
</project>

View File

@ -0,0 +1,6 @@
<component name="InspectionProjectProfileManager">
<profile version="1.0">
<option name="myName" value="Project Default" />
<inspection_tool class="InfiniteLoopStatement" enabled="false" level="WARNING" enabled_by_default="false" />
</profile>
</component>

View File

@ -0,0 +1,65 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="libraries-with-intellij-classes">
<option name="intellijApiContainingLibraries">
<list>
<LibraryCoordinatesState>
<option name="artifactId" value="ideaIU" />
<option name="groupId" value="com.jetbrains.intellij.idea" />
</LibraryCoordinatesState>
<LibraryCoordinatesState>
<option name="artifactId" value="ideaIU" />
<option name="groupId" value="com.jetbrains" />
</LibraryCoordinatesState>
<LibraryCoordinatesState>
<option name="artifactId" value="ideaIC" />
<option name="groupId" value="com.jetbrains.intellij.idea" />
</LibraryCoordinatesState>
<LibraryCoordinatesState>
<option name="artifactId" value="ideaIC" />
<option name="groupId" value="com.jetbrains" />
</LibraryCoordinatesState>
<LibraryCoordinatesState>
<option name="artifactId" value="pycharmPY" />
<option name="groupId" value="com.jetbrains.intellij.pycharm" />
</LibraryCoordinatesState>
<LibraryCoordinatesState>
<option name="artifactId" value="pycharmPY" />
<option name="groupId" value="com.jetbrains" />
</LibraryCoordinatesState>
<LibraryCoordinatesState>
<option name="artifactId" value="pycharmPC" />
<option name="groupId" value="com.jetbrains.intellij.pycharm" />
</LibraryCoordinatesState>
<LibraryCoordinatesState>
<option name="artifactId" value="pycharmPC" />
<option name="groupId" value="com.jetbrains" />
</LibraryCoordinatesState>
<LibraryCoordinatesState>
<option name="artifactId" value="clion" />
<option name="groupId" value="com.jetbrains.intellij.clion" />
</LibraryCoordinatesState>
<LibraryCoordinatesState>
<option name="artifactId" value="clion" />
<option name="groupId" value="com.jetbrains" />
</LibraryCoordinatesState>
<LibraryCoordinatesState>
<option name="artifactId" value="riderRD" />
<option name="groupId" value="com.jetbrains.intellij.rider" />
</LibraryCoordinatesState>
<LibraryCoordinatesState>
<option name="artifactId" value="riderRD" />
<option name="groupId" value="com.jetbrains" />
</LibraryCoordinatesState>
<LibraryCoordinatesState>
<option name="artifactId" value="goland" />
<option name="groupId" value="com.jetbrains.intellij.goland" />
</LibraryCoordinatesState>
<LibraryCoordinatesState>
<option name="artifactId" value="goland" />
<option name="groupId" value="com.jetbrains" />
</LibraryCoordinatesState>
</list>
</option>
</component>
</project>

View File

@ -4,7 +4,5 @@
<component name="FrameworkDetectionExcludesConfiguration">
<file type="web" url="file://$PROJECT_DIR$" />
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_11" default="true" project-jdk-name="11" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_11" project-jdk-name="11" project-jdk-type="JavaSDK" />
</project>

View File

@ -3,12 +3,30 @@
*/
package lightcontainer;
import lightcontainer.domains.StoreMulticastRunnable;
import lightcontainer.protocol.Protocol;
import java.util.HashMap;
import java.util.Map;
public class App {
public String getGreeting() {
return "Hello World!";
public static void main(String[] args) {
System.out.println("Hello World !");
int port = 42500;
String ip = "226.0.0.1";
StoreMulticastRunnable multicast = new StoreMulticastRunnable(ip, port);
(new Thread(multicast)).start();
// Sleep
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
e.printStackTrace();
}
public static void main(String[] args) {
System.out.println(new App().getGreeting());
// Close
multicast.stop();
}
}

View File

@ -0,0 +1,5 @@
package lightcontainer.domains;
public class FileFrontEnd {
}

View File

@ -0,0 +1,70 @@
package lightcontainer.domains;
import java.net.DatagramPacket;
import java.net.InetAddress;
import java.net.MulticastSocket;
/**
* StoreMulticastRunnable
*
* Class listening to the announcement of new StoreBackEnd.
* Allowing it to be used as a storage unit.
*
* @version 1.0
* @since 1.0
*
* @see Runnable
* @author Jérémi NIHART <j.nihart@student.helmo.be>
*/
public class StoreMulticastRunnable implements Runnable {
// Variable
private final String multicast_address;
private final int multicast_port;
private final byte[] buffer = new byte[256];
private MulticastSocket listener;
// Constructor
public StoreMulticastRunnable(String multicast_address, int multicast_port) {
this.multicast_address = multicast_address;
this.multicast_port = multicast_port;
}
/**
* Start Multicast listening on indicated port and IP group.
*
* @since 1.0
*
* @see MulticastSocket#receive(DatagramPacket)
* @see DatagramPacket
*/
@Override
public void run() {
try {
// Create a new listening socket
this.listener = new MulticastSocket(this.multicast_port);
// Create an identifier for the multicast group on the specified ip
InetAddress listener_group = InetAddress.getByName(this.multicast_address);
// Creation of a packet for the information received
DatagramPacket packet = new DatagramPacket(buffer, buffer.length);
// Add the listener to the multicast group
listener.joinGroup(listener_group);
while(true) {
listener.receive(packet);
String data = new String(packet.getData(), 0, packet.getLength());
System.out.println(data); // TODO ajouter un controller et lui signaler qu'il y a un nouveau StoreBackEnd
}
} catch (Exception ignore) { }
}
/**
* Closes the MulticastSocket connection and aborts the listening and infinite listening loop.
*
* @since 1.0
*
* @see StoreMulticastRunnable#run()
*/
public void stop() {
this.listener.close();
}
}

View File

@ -0,0 +1,31 @@
package lightcontainer.protocol;
public class HelloRule extends Protocol {
// Variables
// Constructor
protected HelloRule() {
super("HELLO", "HELLO "); // TODO : add the regex here (sbe_hello = "HELLO bl domain bl port line")
}
/**
* Execute the rule on a command.
*
* This function allows you to check a command and process those groups (parameters)
* use the utility functions of {@link Protocol} to facilitate processing, see @see.
*
* @param cmd Command on which to execute the rule.
* @see Protocol#execute(String)
* @see #matcherCheck(String)
* @see #matcherGetGroups()
* @since 1.0
*/
@Override
public void execute(String cmd) {
if (matcherCheck(cmd)) {
System.out.println("Good rule ;-) !");
} else {
System.out.println("OUPPS unknown rule !");
}
}
}

View File

@ -0,0 +1,125 @@
package lightcontainer.protocol;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* Protocol
*
* Class allowing to define new rules for the LightContainer protocol,
* also provides utility functions to work with regexes and the command to compare.
*
* @version 1.0
* @since 1.0
*
* @see Pattern
* @author Jérémi NIHART <j.nihart@student.helmo.be>
*/
public abstract class Protocol {
// Variables
private final String rule;
private final Pattern rulePattern;
private List<String> groups;
/**
* Protocol constructor
* @param rule Command (e.g: LOGIN).
* @param regex Regex to compile and use for this command (e.g: LOGIN ([A-Z0-9a-z]{1,20})).
* Do not forget to define the groups in the regex.
*/
protected Protocol(String rule, String regex) {
this.rule = rule;
this.rulePattern = Pattern.compile(regex);
}
/**
* Retrieve, the name of the Rule.
*
* @return Name of this rule.
*
* @since 1.0
*/
public String getRule() {
return this.rule;
}
/**
* Check if a command matches the rule with the rule matcher.
*
* @return True : if the command match with the rule.
* False though.
* @param cmd Command to verify with the rule matcher.
*
* @since 1.0
*/
protected boolean matcherCheck(String cmd) {
Matcher ruleMatcher = this.rulePattern.matcher(cmd);
if (ruleMatcher.matches()) {
this.groups = new ArrayList<>();
for (int i=1; i <= ruleMatcher.groupCount(); i++) this.groups.add(ruleMatcher.group(i));
return true;
}
return false;
}
/**
* Get a list of all the groups extracted from the previously matched command with {@link #matcherCheck(String)}.
*
* <b>Requires to have run {@link #matcherCheck(String)}</b>
*
* @return String list containing all the groups extrapolated from the command.
*
* @since 1.0
*
* @see Protocol#matcherCheck(String)
*/
protected List<String> matcherGetGroups() {
return this.groups;
}
/**
* Execute the rule on a command.
*
* This function allows you to check a command and process those groups (parameters)
* use the utility functions of {@link Protocol} to facilitate processing, see @see.
*
* @param cmd Command on which to execute the rule.
*
* @since 1.0
*
* @see Protocol#execute(String)
* @see #matcherCheck(String)
* @see #matcherGetGroups()
*/
public abstract void execute(String cmd);
/**
* Retrieve, the hashcode of the rule.
*
* @return Rule hashcode.
*
* @since 1.0
*/
@Override
public int hashCode() {
return rule.hashCode() % 8;
}
/**
* Compare the equality of two rules.
*
* @return True : if the rules are equals
* False if not.
*
* @since 1.0
*/
@Override
public boolean equals(final Object obj) {
if (this == obj) return true;
if (!(obj instanceof Protocol)) return false;
final Protocol other = (Protocol) obj;
return hashCode() == other.hashCode();
}
}

View File

@ -7,8 +7,8 @@ import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
class AppTest {
@Test void appHasAGreeting() {
App classUnderTest = new App();
assertNotNull(classUnderTest.getGreeting(), "app should have a greeting");
}
// @Test void appHasAGreeting() {
// App classUnderTest = new App();
// assertNotNull(classUnderTest.getGreeting(), "app should have a greeting");
// }
}