From a818b826744f62636caef8c8ee7037b36529b411 Mon Sep 17 00:00:00 2001 From: Kanken6174 Date: Wed, 25 Jan 2023 13:41:45 +0100 Subject: [PATCH] init commit --- .idea/.gitignore | 3 ++ .idea/misc.xml | 6 ++++ .idea/modules.xml | 8 +++++ TP2.iml | 11 +++++++ out/production/TP2/Main.class | Bin 0 -> 516 bytes src/Main.java | 5 +++ src/sweet/Boulangerie.java | 36 +++++++++++++++++++++ src/sweet/Client.java | 18 +++++++++++ src/sweet/Gateau.java | 18 +++++++++++ src/sweet/Patisserie.java | 15 +++++++++ src/sweet/Patissier.java | 19 ++++++++++++ src/world/threadWeaver.java | 57 ++++++++++++++++++++++++++++++++++ 12 files changed, 196 insertions(+) create mode 100644 .idea/.gitignore create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 TP2.iml create mode 100644 out/production/TP2/Main.class create mode 100644 src/Main.java create mode 100644 src/sweet/Boulangerie.java create mode 100644 src/sweet/Client.java create mode 100644 src/sweet/Gateau.java create mode 100644 src/sweet/Patisserie.java create mode 100644 src/sweet/Patissier.java create mode 100644 src/world/threadWeaver.java diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..a346fd7 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..8fa7630 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/TP2.iml b/TP2.iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/TP2.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/out/production/TP2/Main.class b/out/production/TP2/Main.class new file mode 100644 index 0000000000000000000000000000000000000000..9a93b5fe0abcb3074eba8a3fe3f89263700d847d GIT binary patch literal 516 zcmZvZ%TB^T6o&tSLTRmnAb3}B1upE;1%{1@aZxV`1{badnBb6UYlhau$I^u+E_?tV z%6O)js0owInVkQe|C`(A*ZT*69u8dOkhfuZD4@ttnes>OD;`b!tKn3P5{BZ5jAYVd z$hSKK2PHT*Tn|g|{FL9{cA0wq@QTP!)^&H4Boj=DsJA!T8&#S zDp<8q^-#kaLv4YJ!G16d6%n>Q=Vk{asEj7v&cH^4!Mfm*I;_)pEEvjxjKpOc4u!tq zLq$q8h(}xvxRxgW5v}B2&ghDPF?Y!wW{^hvZqYte=Xyf@wFPAcw;!i^B+jJS&N0Lz za~-r$r$;s;2WFm`;yPtMt&G;f;Tza sweets = new ArrayList<>(); + + /** + * + */ + public synchronized void depose(Patisserie p) { + this.notify(); + sweets.add(p); + } + + /** + * + */ + public synchronized Patisserie achete() { + while(sweets.size() == 0) { + try {this.wait();} catch (InterruptedException ignored) {}} + Patisserie pat = sweets.get(0); + sweets.remove(pat); + return pat; + } + + /** + * + */ + public void getStock() { + // TODO implement here + } + +} \ No newline at end of file diff --git a/src/sweet/Client.java b/src/sweet/Client.java new file mode 100644 index 0000000..5f0dc21 --- /dev/null +++ b/src/sweet/Client.java @@ -0,0 +1,18 @@ +package sweet; +import java.util.*; +/** + * + */ +public class Client implements Runnable { + + /** + * Default constructor + */ + public Client() { + } + + @Override + public void run() { + + } +} \ No newline at end of file diff --git a/src/sweet/Gateau.java b/src/sweet/Gateau.java new file mode 100644 index 0000000..0b6e045 --- /dev/null +++ b/src/sweet/Gateau.java @@ -0,0 +1,18 @@ +package sweet; + +import sweet.Patisserie; + +import java.util.*; + +/** + * + */ +public class Gateau extends Patisserie { + + /** + * Default constructor + */ + public Gateau() { + } + +} \ No newline at end of file diff --git a/src/sweet/Patisserie.java b/src/sweet/Patisserie.java new file mode 100644 index 0000000..693bcc0 --- /dev/null +++ b/src/sweet/Patisserie.java @@ -0,0 +1,15 @@ +package sweet; +import java.util.*; + +/** + * + */ +public class Patisserie { + + /** + * Default constructor + */ + public Patisserie() { + } + +} \ No newline at end of file diff --git a/src/sweet/Patissier.java b/src/sweet/Patissier.java new file mode 100644 index 0000000..4fdab00 --- /dev/null +++ b/src/sweet/Patissier.java @@ -0,0 +1,19 @@ +package sweet; +import java.util.*; + +/** + * + */ +public class Patissier implements Runnable { + + /** + * Default constructor + */ + public Patissier() { + } + + @Override + public void run() { + + } +} \ No newline at end of file diff --git a/src/world/threadWeaver.java b/src/world/threadWeaver.java new file mode 100644 index 0000000..df60c6b --- /dev/null +++ b/src/world/threadWeaver.java @@ -0,0 +1,57 @@ +package world; + +import java.lang.reflect.Array; +import java.util.ArrayList; +import java.util.List; + +public class threadWeaver { + private final List runners = new ArrayList(); + private final List managed = new ArrayList(); + public void addRunners(Runnable... runners){ + + } + + public void weave(){ + for(Runnable r: runners){ + managed.add(new Thread(r)); + } + } + + public void run(){ + for(Thread t : managed){ + t.start(); + } + } + + public void recover(){ + for(Thread t : managed){ + try { + t.wait(); + }catch(InterruptedException ie){ + System.out.println(ie.getMessage()); + } + } + termina(); + } + + public void recover(Long timeout){ + for(Thread t : managed){ + try { + t.wait(timeout); + }catch(InterruptedException ie){ + System.out.println(ie.getMessage()); + } + managed.remove(t); + } + termina(); + } + + public void termina(){ + for(Thread t : managed){ + System.out.println("Thread "+t.getName()+" has not stopped being cleaned up"); + t.interrupt(); + } + managed.clear(); + runners.clear(); + } +}