|
|
@ -4,17 +4,22 @@ import java.io.BufferedReader; |
|
|
|
import java.io.DataOutputStream; |
|
|
|
import java.io.IOException; |
|
|
|
import java.io.InputStreamReader; |
|
|
|
|
|
|
|
import java.net.ServerSocket; |
|
|
|
import java.net.Socket; |
|
|
|
|
|
|
|
import java.text.DateFormat; |
|
|
|
import java.text.SimpleDateFormat; |
|
|
|
import java.util.Date; |
|
|
|
import redis.clients.jedis.Jedis; |
|
|
|
|
|
|
|
import com.amazonaws.services.s3.AmazonS3; |
|
|
|
import com.amazonaws.services.s3.AmazonS3ClientBuilder; |
|
|
|
|
|
|
|
class TCPTimeCounterServer { |
|
|
|
public static void main(String args[]) throws Exception { |
|
|
|
int tcpPort = 36038; |
|
|
|
String redisClusterURL = "vertsys-ec1-0001-002.71rxr9.0001.euc1.cache.amazonaws.com"; |
|
|
|
String bucketName = "vertsys-counter"; |
|
|
|
//String redisClusterURL = "vertsys-ec1-0001-002.71rxr9.0001.euc1.cache.amazonaws.com"; |
|
|
|
DateFormat df = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss"); |
|
|
|
|
|
|
|
// Socket erzeugen |
|
|
@ -35,19 +40,33 @@ class TCPTimeCounterServer { |
|
|
|
long number = new Long(new String(inFromClient.readLine())); |
|
|
|
|
|
|
|
// Verbindung zum Redis Cluster (Amazon ElastiCache) |
|
|
|
Jedis jedis = new Jedis(redisClusterURL, 6379); |
|
|
|
System.out.println("Connected to redis server"); |
|
|
|
//JedisPool pool = new JedisPool(new JedisPoolConfig(), redisClusterURL); |
|
|
|
//Jedis jedis = pool.getResource(); |
|
|
|
//jedis.connect(); |
|
|
|
//JedisCluster jedisCluster = new JedisCluster(new HostAndPort(redisClusterURL, 6379)); |
|
|
|
//System.out.println("Connected to redis server"); |
|
|
|
// check whether server is running or not |
|
|
|
//System.out.println("redis server is running: " + jedis.ping()); |
|
|
|
//System.out.println("redis server cluster info: " + jedis.clusterInfo()); |
|
|
|
// Variable für Zählerstand des Servers, dieser Zähler wird durch Anfragen der |
|
|
|
// Clients erhöht |
|
|
|
jedis.incrBy("vertsys-counter", number); |
|
|
|
long counter = new Long(jedis.get("vertsys-counter")); |
|
|
|
jedis.close(); |
|
|
|
//jedisCluster.incrBy("vertsys-counter", number); |
|
|
|
//long counter = new Long(jedisCluster.get("vertsys-counter")); |
|
|
|
//jedisCluster.close(); |
|
|
|
//System.out.println("TTL:" + jedisCluster.ttl("vertsys-counter")); |
|
|
|
//System.out.println("Anfrage von Client " + connectionSocket.getInetAddress() + ":" + connectionSocket.getPort() + " Zahl: " + number + " Zählerstand: " + counter); |
|
|
|
|
|
|
|
//Verbindung zu S3 |
|
|
|
AmazonS3 s3Client = AmazonS3ClientBuilder.defaultClient(); |
|
|
|
String region = s3Client.getRegionName(); |
|
|
|
if (!s3Client.doesObjectExist("vertsys-counter", region)) |
|
|
|
{ |
|
|
|
s3Client.putObject(bucketName, region, new Long(0).toString()); |
|
|
|
} |
|
|
|
long counter = new Long(s3Client.getObjectAsString(bucketName, region)); |
|
|
|
counter = counter + number; |
|
|
|
s3Client.putObject(bucketName, region, new Long(counter).toString()); |
|
|
|
|
|
|
|
System.out.println("TTL:" + jedis.ttl("vertsys-counter")); |
|
|
|
System.out.println("Anfrage von Client " + connectionSocket.getInetAddress() + ":" + connectionSocket.getPort() + " Zahl: " + number + " Zählerstand: " + counter); |
|
|
|
|
|
|
|
// Try/Catch hinzugefügt, nachdem bei Einsatz Amazon AWS (Healthcheck des ELB) clientSentence null war |
|
|
|
try { |
|
|
|