Added spring bean annotation and processing
This commit is contained in:
5
.idea/misc.xml
generated
5
.idea/misc.xml
generated
@ -1,5 +1,10 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project version="4">
|
<project version="4">
|
||||||
|
<component name="EntryPointsManager">
|
||||||
|
<writeAnnotations>
|
||||||
|
<writeAnnotation name="org.springframework.beans.factory.annotation.Autowired" />
|
||||||
|
</writeAnnotations>
|
||||||
|
</component>
|
||||||
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
||||||
<component name="MavenProjectsManager">
|
<component name="MavenProjectsManager">
|
||||||
<option name="originalFiles">
|
<option name="originalFiles">
|
||||||
|
7
pom.xml
7
pom.xml
@ -41,6 +41,13 @@
|
|||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework</groupId>
|
||||||
|
<artifactId>spring-context</artifactId>
|
||||||
|
<version>6.1.3</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
<build>
|
<build>
|
||||||
<plugins>
|
<plugins>
|
||||||
|
@ -1,25 +1,31 @@
|
|||||||
package org.example;
|
package org.example;
|
||||||
|
|
||||||
import com.fasterxml.jackson.databind.JsonNode;
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
import redis.clients.jedis.HostAndPort;
|
import redis.clients.jedis.HostAndPort;
|
||||||
import redis.clients.jedis.JedisPooled;
|
import redis.clients.jedis.JedisPooled;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
|
@Component
|
||||||
public class LoadGameTask implements Runnable
|
public class LoadGameTask implements Runnable
|
||||||
{
|
{
|
||||||
|
@Autowired
|
||||||
|
private RedisServiceImpl redisService;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run()
|
public void run()
|
||||||
{
|
{
|
||||||
JsonNode json;
|
JsonNode json;
|
||||||
|
|
||||||
try (JedisPooled jedis = new JedisPooled(new HostAndPort(SteamConstants.REDIS_HOST, 6380), RedisServiceImpl.prepareRedisConfig()))
|
try (JedisPooled jedis = new JedisPooled(new HostAndPort(SteamConstants.REDIS_HOST, 6380), redisService.prepareRedisConfig()))
|
||||||
{
|
{
|
||||||
for (int i = 0; i < 150000; i++)
|
for (int i = 0; i < 150000; i++)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
json = RedisServiceImpl.loadGameJson(String.format(SteamConstants.GAME_DETAILS_API_TEMPLATE, i, "KZ"));
|
json = redisService.loadGameJson(String.format(SteamConstants.GAME_DETAILS_API_TEMPLATE, i, "KZ"));
|
||||||
}
|
}
|
||||||
catch (IOException e)
|
catch (IOException e)
|
||||||
{
|
{
|
||||||
@ -31,8 +37,6 @@ public class LoadGameTask implements Runnable
|
|||||||
jedis.set(String.valueOf(i), json.toString());
|
jedis.set(String.valueOf(i), json.toString());
|
||||||
System.out.println("Current id = " + i);
|
System.out.println("Current id = " + i);
|
||||||
System.out.println(json.toPrettyString());
|
System.out.println(json.toPrettyString());
|
||||||
|
|
||||||
System.out.println("jedis value for " + i + "\n" + jedis.get(String.valueOf(i)));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
|
@ -2,6 +2,7 @@ package org.example;
|
|||||||
|
|
||||||
import com.fasterxml.jackson.databind.JsonNode;
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
import redis.clients.jedis.DefaultJedisClientConfig;
|
import redis.clients.jedis.DefaultJedisClientConfig;
|
||||||
|
|
||||||
import javax.net.ssl.KeyManagerFactory;
|
import javax.net.ssl.KeyManagerFactory;
|
||||||
@ -18,12 +19,12 @@ import java.nio.file.Paths;
|
|||||||
import java.security.GeneralSecurityException;
|
import java.security.GeneralSecurityException;
|
||||||
import java.security.KeyStore;
|
import java.security.KeyStore;
|
||||||
|
|
||||||
//TODO: Add bean annotation
|
@Service
|
||||||
public class RedisServiceImpl
|
public class RedisServiceImpl
|
||||||
{
|
{
|
||||||
//TODO: remove deprecated URL constructor
|
//TODO: remove deprecated URL constructor
|
||||||
//TODO: replace mapper towards concrete class model GameInfoResponse
|
//TODO: replace mapper towards concrete class model GameInfoResponse
|
||||||
public static JsonNode loadGameJson(String url) throws IOException
|
public JsonNode loadGameJson(String url) throws IOException
|
||||||
{
|
{
|
||||||
InputStream inputStream;
|
InputStream inputStream;
|
||||||
|
|
||||||
@ -45,7 +46,7 @@ public class RedisServiceImpl
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static DefaultJedisClientConfig prepareRedisConfig() throws GeneralSecurityException, IOException
|
public DefaultJedisClientConfig prepareRedisConfig() throws GeneralSecurityException, IOException
|
||||||
{
|
{
|
||||||
//Hack for building absolute path for user certificate
|
//Hack for building absolute path for user certificate
|
||||||
String keystorePath = new File("src/main/resources/redis-keystore.p12").getAbsolutePath();
|
String keystorePath = new File("src/main/resources/redis-keystore.p12").getAbsolutePath();
|
||||||
|
@ -1,17 +1,25 @@
|
|||||||
package org.example;
|
package org.example;
|
||||||
|
|
||||||
|
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||||
|
import org.springframework.context.annotation.ComponentScan;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
@ComponentScan
|
||||||
public class SteamPriceParser
|
public class SteamPriceParser
|
||||||
{
|
{
|
||||||
public static void main(String[] args)
|
public static void main(String[] args)
|
||||||
{
|
{
|
||||||
try (ExecutorService executorService = Executors.newFixedThreadPool(50))
|
AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext(SteamPriceParser.class);
|
||||||
{
|
|
||||||
executorService.submit(new LoadGameTask());
|
ExecutorService executorService = Executors.newFixedThreadPool(50);
|
||||||
}
|
|
||||||
|
// Hack for adding runnable to spring watching list
|
||||||
|
LoadGameTask task = applicationContext.getBean(LoadGameTask.class);
|
||||||
|
executorService.submit(task);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user