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"?>
|
||||
<project version="4">
|
||||
<component name="EntryPointsManager">
|
||||
<writeAnnotations>
|
||||
<writeAnnotation name="org.springframework.beans.factory.annotation.Autowired" />
|
||||
</writeAnnotations>
|
||||
</component>
|
||||
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
||||
<component name="MavenProjectsManager">
|
||||
<option name="originalFiles">
|
||||
|
7
pom.xml
7
pom.xml
@ -41,6 +41,13 @@
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-context</artifactId>
|
||||
<version>6.1.3</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
</dependencies>
|
||||
<build>
|
||||
<plugins>
|
||||
|
@ -1,25 +1,31 @@
|
||||
package org.example;
|
||||
|
||||
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.JedisPooled;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
@Component
|
||||
public class LoadGameTask implements Runnable
|
||||
{
|
||||
@Autowired
|
||||
private RedisServiceImpl redisService;
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
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++)
|
||||
{
|
||||
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)
|
||||
{
|
||||
@ -31,8 +37,6 @@ public class LoadGameTask implements Runnable
|
||||
jedis.set(String.valueOf(i), json.toString());
|
||||
System.out.println("Current id = " + i);
|
||||
System.out.println(json.toPrettyString());
|
||||
|
||||
System.out.println("jedis value for " + i + "\n" + jedis.get(String.valueOf(i)));
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
@ -2,6 +2,7 @@ package org.example;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.springframework.stereotype.Service;
|
||||
import redis.clients.jedis.DefaultJedisClientConfig;
|
||||
|
||||
import javax.net.ssl.KeyManagerFactory;
|
||||
@ -18,12 +19,12 @@ import java.nio.file.Paths;
|
||||
import java.security.GeneralSecurityException;
|
||||
import java.security.KeyStore;
|
||||
|
||||
//TODO: Add bean annotation
|
||||
@Service
|
||||
public class RedisServiceImpl
|
||||
{
|
||||
//TODO: remove deprecated URL constructor
|
||||
//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;
|
||||
|
||||
@ -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
|
||||
String keystorePath = new File("src/main/resources/redis-keystore.p12").getAbsolutePath();
|
||||
|
@ -1,17 +1,25 @@
|
||||
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.Executors;
|
||||
|
||||
@Configuration
|
||||
@ComponentScan
|
||||
public class SteamPriceParser
|
||||
{
|
||||
public static void main(String[] args)
|
||||
{
|
||||
try (ExecutorService executorService = Executors.newFixedThreadPool(50))
|
||||
{
|
||||
executorService.submit(new LoadGameTask());
|
||||
}
|
||||
}
|
||||
AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext(SteamPriceParser.class);
|
||||
|
||||
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