Skip to content

Commit

Permalink
logging and instructions
Browse files Browse the repository at this point in the history
  • Loading branch information
simbo1905 committed Dec 27, 2024
1 parent 623b2be commit c674618
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 4 deletions.
68 changes: 68 additions & 0 deletions Stack.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# Stack Example Local

You must be running Java 23 or higher. Build the code with:

```bash
pushd trex2-lib
mvn -DNO_LOGGING=true clean test
popd
```

Run jshell with:

```bash
jshell --enable-preview --class-path ./trex-locks/target/classes:./trex-locks/target/test-classes:./trex2-lib/target/classes:./trex2-lib/target/test-classes
```

To exist press Ctrl+d

Inside jshell import the coee then set the logging to what you would like to see and create a two node cluster:

```
jshell> import com.github.trex_paxos.*
jshell> StackClusterImpl.setLogLevel(java.util.logging.Level.WARNING)
jshell> var stack = new StackClusterImpl()
```

You may need to hit enter to see the command prompt come back.

Now you can do push strings, peek and pop and get back a Response. Define some methods to print the result:

```
void push(String x){
stack.push(x);
}
void peek(){
System.out.println(stack.peek().value().get());
}
void pop(){
System.out.println(stack.pop().value().get());
}
```

With that you can:

```
jshell> push("hello")
jshell> push("world")
jshell> peek();
world
jshell> peek();
world
jshell> pop()
world
jshell> pop()
hello
jshell> pop()
Dec 27, 2024 3:28:17 PM com.github.trex_paxos.StackClusterImpl lambda$new$4
WARNING: Attempted operation on empty stack
Stack is empty
```
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.github.trex_paxos;

import com.github.trex_paxos.StackService.Push;
import com.github.trex_paxos.msg.*;
import java.io.*;
import java.util.*;
Expand All @@ -12,11 +11,11 @@

public class StackClusterImpl implements StackService {
private static final Logger LOGGER = Logger.getLogger(StackClusterImpl.class.getName());
static {
public static void setLogLevel(Level level) {
Logger root = Logger.getLogger("");
root.setLevel(Level.FINEST);
root.setLevel(level);
ConsoleHandler handler = new ConsoleHandler();
handler.setLevel(Level.FINEST);
handler.setLevel(level);
root.addHandler(handler);
}

Expand Down

0 comments on commit c674618

Please sign in to comment.