Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
518fe10
task 1 done
simiyutin Mar 4, 2017
14c5beb
more comments
simiyutin Mar 6, 2017
436381a
Create README.md
simiyutin Mar 6, 2017
12f41aa
Update README.md
simiyutin Mar 7, 2017
ac8f8cb
exceptions
simiyutin Mar 7, 2017
e0006bf
Merge branch 'dev' of github.com:simiyutin/au_software_design into dev
simiyutin Mar 7, 2017
bae7b44
Update README.md
simiyutin Mar 7, 2017
cf1f13b
Update README.md
simiyutin Mar 7, 2017
87259a6
grep command added
simiyutin Mar 8, 2017
209ea7f
tests
simiyutin Mar 11, 2017
57caaa3
comments
simiyutin Mar 11, 2017
2dcc535
Update README.md
simiyutin Mar 11, 2017
26a5078
fixes
simiyutin Mar 11, 2017
1879ced
reversed domain name packages
simiyutin Mar 11, 2017
9541039
.gradle folder removed
simiyutin Mar 11, 2017
db4f811
Merge branch 'dev' of github.com:simiyutin/au_software_design into dev
simiyutin Mar 11, 2017
d895b9a
Merge branch 'dev' into grep
simiyutin Mar 11, 2017
1d8d00a
post merge fix
simiyutin Mar 11, 2017
5f68b21
Merge branch 'grep' of github.com:simiyutin/au_software_design into grep
simiyutin Mar 11, 2017
dc44b31
book store class diagram
simiyutin Mar 29, 2017
b21a634
minor updatee
simiyutin Mar 31, 2017
eb01c65
gitignore modification
simiyutin Apr 12, 2017
26cb7ed
roguelike arch
simiyutin Apr 12, 2017
e4cdc9e
first stubs
simiyutin May 8, 2017
898333d
first world
simiyutin May 8, 2017
20848c6
randomized world
simiyutin May 8, 2017
69094ae
display player
simiyutin May 8, 2017
35c329a
beings and player
simiyutin May 9, 2017
963710c
mushrooms
simiyutin May 9, 2017
368b3b9
dead screen & health display
simiyutin May 9, 2017
1c0ab95
ai
simiyutin May 10, 2017
a0e49a7
ghosts can feel player
simiyutin May 10, 2017
800423c
ghost actions
simiyutin May 10, 2017
d3715ad
ghost effect
simiyutin May 11, 2017
1a36c59
messages
simiyutin May 11, 2017
bcd7fbf
dummy Weapons
simiyutin May 11, 2017
b5efefb
todo ++
simiyutin May 11, 2017
caa8823
++ todo
simiyutin May 11, 2017
64611a6
dragon dummy
simiyutin May 11, 2017
b3f80e2
pick weapons
simiyutin May 11, 2017
74d19b8
battle
simiyutin May 11, 2017
c8258cf
amend
simiyutin May 11, 2017
0fe3905
med aids
simiyutin May 11, 2017
573040b
slightly tuned
simiyutin May 11, 2017
73e396f
updated todo list
simiyutin May 11, 2017
04e7e22
artefacts fix
simiyutin May 13, 2017
77c016f
minor updates
simiyutin May 13, 2017
104018d
amend
simiyutin May 13, 2017
0b90e56
Z level
simiyutin May 13, 2017
3edc211
level
simiyutin May 13, 2017
f02c56b
random colors on new level
simiyutin May 13, 2017
217eebe
refactor
simiyutin May 13, 2017
329c0a2
reverse domain name
simiyutin May 13, 2017
1bcf168
refactor
simiyutin May 13, 2017
27f9307
tests
simiyutin May 13, 2017
a30e763
logging
simiyutin May 13, 2017
7c2383e
fix
simiyutin May 13, 2017
c8d3450
building fix
simiyutin May 13, 2017
5bb68c9
more logging + refactor
simiyutin May 13, 2017
2a82807
++
simiyutin May 14, 2017
715b1c2
task done
simiyutin May 24, 2017
40ca752
build & run scripts
simiyutin May 24, 2017
5602c95
readme
simiyutin May 24, 2017
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
/**/.idea/
/**/build
/**/*.vpp.*
/**/*.iml
/**/*.class
/**/target/
44 changes: 44 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# au_software_design

##1. Shell

###Command line utility similar to Unix shell.

####Supported features:

* echo command
* cat command
* wc command
* exit command
* pwd command
* environment variables
* unknown commands are passed to system shell as separate process through Java.Process library.

####Class diagram:
![shell class diagram](https://www.gliffy.com/go/share/image/smx5dub0j39jxied850w.png?utm_medium=live-embed&utm_source=custom)

####Data flow:
* Main: run Shell object.
* Shell: Read line from System.in.

* Preprocessor: Substitute environment variables in input string. E. g. "Hello, $name" -> "Hello, Alex"
* Tokeniser: Split string into a list of tokens: words and operators.
* Parser: Parse list of tokens as sequence of commands divided by pipes.
* Command Executor: Perform chained computation passing output of one comand as input to the next one.
* Pass result to System.in and loop again.


##2. Grep
###Command similar to UNIX grep utility.

####Supports:
* Reading from standard input or from file.
* Parameters:
* -i: case insensivity.
* -w: whole words search.
* -A %number%: Number of lines to add to output after each matched line.

####Implementation:
* For regular expressions java.util.regex package is used.

* For parsing command line arguments Apache Commons CLI library was chosen, because it is pretty easy to use and fits our requirements very well. Other libraries like JCommander and args4j were considered as an option, but were rejected as a little overkill at this point. If number of arguments will grow seriously, it may be reasonable to switch to one of these libraries, because of usage of annotations for introducing parameters.
Binary file added book_store/book_store_class_diagram.vpp
Binary file not shown.
1 change: 1 addition & 0 deletions grpcchat/README.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Имя пользователя можно передать первым входным параметром скриптам runServer и runClient
3 changes: 3 additions & 0 deletions grpcchat/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#! /bin/bash

mvn clean compile assembly:single
95 changes: 95 additions & 0 deletions grpcchat/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.simiyutin</groupId>
<artifactId>grpc-chat</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.apache.maven.reporting</groupId>
<artifactId>maven-reporting-impl</artifactId>
<version>2.0.5</version>
</dependency>
<dependency>
<groupId>io.grpc</groupId>
<artifactId>grpc-netty</artifactId>
<version>1.3.0</version>
</dependency>
<dependency>
<groupId>io.grpc</groupId>
<artifactId>grpc-protobuf</artifactId>
<version>1.3.0</version>
</dependency>
<dependency>
<groupId>io.grpc</groupId>
<artifactId>grpc-stub</artifactId>
<version>1.3.0</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.8.1</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.8.1</version>
</dependency>
</dependencies>

<build>
<extensions>
<extension>
<groupId>kr.motd.maven</groupId>
<artifactId>os-maven-plugin</artifactId>
<version>1.4.1.Final</version>
</extension>
</extensions>
<plugins>
<plugin>
<groupId>org.xolstice.maven.plugins</groupId>
<artifactId>protobuf-maven-plugin</artifactId>
<version>0.5.0</version>
<configuration>
<protocArtifact>com.google.protobuf:protoc:3.2.0:exe:${os.detected.classifier}</protocArtifact>
<pluginId>grpc-java</pluginId>
<pluginArtifact>io.grpc:protoc-gen-grpc-java:1.3.0:exe:${os.detected.classifier}</pluginArtifact>
</configuration>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>compile-custom</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>com.simiyutin.grpcchat.Chat</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</build>


</project>
8 changes: 8 additions & 0 deletions grpcchat/runClient.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#! /bin/bash

if [ -n "$1" ]
then
java -jar ./target/*-jar-with-dependencies.jar localhost 50051 "$1"
else
java -jar ./target/*-jar-with-dependencies.jar localhost 50051 Client
fi
8 changes: 8 additions & 0 deletions grpcchat/runServer.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#! /bin/bash

if [ -n "$1" ]
then
java -jar ./target/*-jar-with-dependencies.jar "$1"
else
java -jar ./target/*-jar-with-dependencies.jar Server
fi
125 changes: 125 additions & 0 deletions grpcchat/src/main/java/com/simiyutin/grpcchat/Chat.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
package com.simiyutin.grpcchat;

import io.grpc.ManagedChannel;
import io.grpc.ManagedChannelBuilder;
import io.grpc.Server;
import io.grpc.ServerBuilder;
import io.grpc.stub.StreamObserver;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Scanner;


public class Chat extends ChatGrpc.ChatImplBase {

private static final Logger LOGGER = LogManager.getLogger(Chat.class);

private static StreamObserver<ChatOuterClass.Message> handleToClient;
private StreamObserver<ChatOuterClass.Message> handleToServer;

private String userName;

private static void initClient(final Chat chat, String[] args) {
chat.userName = args[2];

String host = args[0];
String port = args[1];
ManagedChannelBuilder builder = ManagedChannelBuilder.forAddress(host, Integer.parseInt(port)).usePlaintext(true);
ManagedChannel channel = builder.build();
ChatGrpc.ChatStub stub = ChatGrpc.newStub(channel);

chat.handleToServer = stub.routeChat(new StreamObserver<ChatOuterClass.Message>() {
public void onNext(ChatOuterClass.Message message) {
chat.printMsg(message);
}

public void onError(Throwable throwable) {
LOGGER.error("server error:", throwable);
}

public void onCompleted() {}
});
}

private static void initServer(final Chat chat, String[] args) {
chat.userName = args[0];
Server server = ServerBuilder.forPort(50051).addService(new Chat()).build();

try {
server.start();
} catch (IOException e) {
LOGGER.error("server error:", e);
}
}


public static void main(String[] args) {
final Chat chat = new Chat();

if (args.length == 3) {

initClient(chat, args);

} else if (args.length == 1) {

initServer(chat, args);

} else {

System.out.println("input parameters: [host, port, user name] or [user name]");
return;
}

Scanner scanner = new Scanner(System.in);

while (true) {
String message = scanner.nextLine();
chat.sendMessage(message);
}
}

private void sendMessage(String message) {
ChatOuterClass.Message msg = ChatOuterClass.Message
.newBuilder()
.setFrom(userName)
.setText(message)
.setTime(new SimpleDateFormat("h:mm a").format(new Date()))
.build();

if (handleToClient != null) {

handleToClient.onNext(msg);

} else if (handleToServer != null) {

handleToServer.onNext(msg);
}
}

private void printMsg(ChatOuterClass.Message msg) {
System.out.format("[%s], %s: %s\n", msg.getTime(), msg.getFrom(), msg.getText());
}

@Override
public StreamObserver<ChatOuterClass.Message> routeChat(final StreamObserver<ChatOuterClass.Message> responseObserver) {
handleToClient = responseObserver;

return new StreamObserver<ChatOuterClass.Message>() {
public void onNext(ChatOuterClass.Message message) {
printMsg(message);
}

public void onError(Throwable throwable) {
LOGGER.error("client error:", throwable);
}

public void onCompleted() {
responseObserver.onCompleted();
}
};
}
}
14 changes: 14 additions & 0 deletions grpcchat/src/main/proto/chat.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
syntax = "proto3";
option java_package = "com.simiyutin.grpcchat";

service Chat {
rpc RouteChat(stream Message) returns(stream Message) {}


}

message Message {
string text = 1;
string from = 2;
string time = 3;
}
13 changes: 13 additions & 0 deletions grpcchat/src/main/resources/log4j2.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="ERROR">
<Appenders>
<File name="File" fileName="src/main/resources/main.log">
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
</File>
</Appenders>
<Loggers>
<Root level="all">
<AppenderRef ref="File" level="all"/>
</Root>
</Loggers>
</Configuration>
Loading