Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
package ru.atom.mm.controller;


import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import ru.atom.mm.model.Connection;
import ru.atom.mm.service.ConnectionQueue;
import ru.atom.mm.service.GameRepository;

import java.util.ArrayList;
import java.util.List;


@Controller
Expand All @@ -24,6 +29,8 @@ public class ConnectionController {
@Autowired
private ConnectionQueue connectionQueue;

private ArrayList<Connection> allConnections = new ArrayList<Connection>();

/**
* curl test
*
Expand All @@ -40,15 +47,26 @@ public void connect(@RequestParam("id") long id,

log.info("New connection id={} name={}", id, name);
connectionQueue.getQueue().offer(new Connection(id, name));
allConnections.add(new Connection(id, name));
}

/**
* curl test
*
* curl -i localhost:8080/connection/list'
*/
@RequestMapping(
path = "list",
method = RequestMethod.GET,
produces = MediaType.TEXT_PLAIN_VALUE)
@ResponseBody
public String list() {
throw new UnsupportedOperationException();
log.info("Connection Controller list requested");
if (allConnections.isEmpty()) {
return "[]";
} else {
return allConnections.toString();
}
}


Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package ru.atom.mm.service;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Repository;
import ru.atom.mm.model.GameSession;

Expand Down
1 change: 1 addition & 0 deletions lecture05/src/main/java/ru/atom/mm/service/MatchMaker.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public void run() {
candidates.add(
connectionQueue.getQueue().poll(10_000, TimeUnit.SECONDS)
);

} catch (InterruptedException e) {
log.warn("Timeout reached");
}
Expand Down
2 changes: 1 addition & 1 deletion lecture05/src/test/java/ru/atom/thread/join/BombTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
/**
* Created by sergey on 3/14/17.
*/
@Ignore

public class BombTest {
private static final Logger log = LogManager.getLogger(BombTest.class);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package ru.atom.thread.practice;

import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
Expand All @@ -8,14 +10,37 @@
*/
public class EventProcessor {
public static void produceEvents(List<EventProducer> eventProducers) {
throw new UnsupportedOperationException();//TODO eventProducers here
for (EventProducer producer : eventProducers) {
int index = producer.getClass().getName().lastIndexOf('.') + 1;
if (producer.getClass().getName().substring(index).equals("GoodEventProducer")) {
GoodEventProducer currProducer = (GoodEventProducer) producer;
currProducer.run();
} else if (producer.getClass().getName().substring(index).equals("BadEventProducer")) {
BadEventProducer currProducer = (BadEventProducer) producer;
currProducer.run();
} else {
throw new Error("AnimeError");
}
}
}

public static long countTotalNumberOfGoodEvents() {
throw new UnsupportedOperationException();//TODO
long result = 0;
for (Event event : EventQueue.getInstance()) {
if (event.getEventType() == Event.EventType.GOOD) {
result += 1;
}
}
return result;
}

public static long countTotalNumberOfBadEvents() {
throw new UnsupportedOperationException();//TODO
long result = 0;
for (Event event : EventQueue.getInstance()) {
if (event.getEventType() == Event.EventType.BAD) {
result += 1;
}
}
return result;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
* @author apomosov
* @since 15.03.17
*/
@Ignore
public class EventProcessorTest {
@Test
public void process() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package ru.atom.thread.practice;

import org.springframework.stereotype.Repository;

import javax.annotation.Resources;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;

Expand Down