gluu
静的公開メンバ関数 | 静的非公開メンバ関数 | 静的非公開変数類 | 全メンバ一覧
org.xdi.oxauth.dev.CacheGrantManual クラス
org.xdi.oxauth.dev.CacheGrantManual 連携図
Collaboration graph

静的公開メンバ関数

static void main (String[] args) throws IOException
 
static ThreadFactory daemonThreadFactory ()
 

静的非公開メンバ関数

static MemcachedClient createClients () throws IOException
 
static int random ()
 
static void sleep (int seconds)
 
static SessionId testState ()
 
static Client testClient ()
 
static User testUser ()
 
static CacheGrant testGrant ()
 

静的非公開変数類

static final int CLIENT_COUNT = 10
 
static final Random RANDOM = new Random()
 

詳解

著者
yuriyz
バージョン
August 9, 2017

関数詳解

◆ createClients()

static MemcachedClient org.xdi.oxauth.dev.CacheGrantManual.createClients ( ) throws IOException
inlinestaticprivate
41  {
42  return new MemcachedClient(new DefaultConnectionFactory(100, 32768),
43  Lists.newArrayList(new InetSocketAddress("localhost", 11211)));
44  }

◆ daemonThreadFactory()

static ThreadFactory org.xdi.oxauth.dev.CacheGrantManual.daemonThreadFactory ( )
inlinestatic
122  {
123  return new ThreadFactory() {
124  public Thread newThread(Runnable p_r) {
125  Thread thread = new Thread(p_r);
126  thread.setDaemon(true);
127  return thread;
128  }
129  };
130  }

◆ main()

static void org.xdi.oxauth.dev.CacheGrantManual.main ( String []  args) throws IOException
inlinestatic
52  {
53  final MemcachedClient client = createClients();
54  final ExecutorService executorService = Executors.newFixedThreadPool(1000, daemonThreadFactory());
55 
56  int count = 10000;
57  final long start = System.currentTimeMillis();
58 
59  for (int i = 0; i < count; i++) {
60  final int key = i;
61  executorService.execute(new Runnable() {
62  @Override
63  public void run() {
64  // MemcachedClient client = clients.get(random);
65 
66  Object toPut = testGrant();
67  // Object toPut = UUID.randomUUID().toString();
68 
69  OperationFuture<Boolean> set = null;
70  for (int j = 0; j < 3; j++) {
71  set = client.set(Integer.toString(key), 60, toPut);
72  }
73 
74  OperationStatus status = set.getStatus(); // block
75 
76  System.out.println(
77  " key: " + key + ", time: " + (new Date().getTime() - start) + "ms, set: " + status);
78 
79  executorService.execute(new Runnable() {
80  @Override
81  public void run() {
82 
83  int random = random();
84  if (random % 3 == 0) {
85  try {
86  Thread.sleep(10000);
87  } catch (InterruptedException e) {
88  e.printStackTrace();
89  }
90  }
91 
92  Object get = client.get(Integer.toString(key));
93  System.out.println("GET key: " + key + " result: " + get);
94  }
95  });
96  }
97  });
98  }
99 
100  sleep(40);
101  // System.out.println(client.get("myKey"));
102  //
103  // client.set("myKey", 30, testState());
104  //
105  // sleep(12);
106  // System.out.println(client.get("myKey"));
107  //
108  // sleep(12);
109  // System.out.println(client.get("myKey"));
110  client.shutdown();
111 
112  }
static MemcachedClient createClients()
Definition: CacheGrantManual.java:41
static CacheGrant testGrant()
Definition: CacheGrantManual.java:156
static int random()
Definition: CacheGrantManual.java:46
static ThreadFactory daemonThreadFactory()
Definition: CacheGrantManual.java:122
static void sleep(int seconds)
Definition: CacheGrantManual.java:114

◆ random()

static int org.xdi.oxauth.dev.CacheGrantManual.random ( )
inlinestaticprivate
46  {
47  int min = 0;
48  int max = CLIENT_COUNT;
49  return RANDOM.nextInt(max - min + 1) + min;
50  }
static final int CLIENT_COUNT
Definition: CacheGrantManual.java:38
static final Random RANDOM
Definition: CacheGrantManual.java:39

◆ sleep()

static void org.xdi.oxauth.dev.CacheGrantManual.sleep ( int  seconds)
inlinestaticprivate
114  {
115  try {
116  Thread.sleep(seconds * 1000);
117  } catch (InterruptedException e) {
118  throw new RuntimeException(e);
119  }
120  }

◆ testClient()

static Client org.xdi.oxauth.dev.CacheGrantManual.testClient ( )
inlinestaticprivate
144  {
145  Client client = new Client();
146  client.setClientId(UUID.randomUUID().toString());
147  return client;
148  }

◆ testGrant()

static CacheGrant org.xdi.oxauth.dev.CacheGrantManual.testGrant ( )
inlinestaticprivate
156  {
157  CacheGrant grant = new CacheGrant();
158  grant.setAcrValues("basic");
159  grant.setAuthenticationTime(new Date());
160  grant.setAuthorizationCodeString(UUID.randomUUID().toString());
161  grant.setClient(testClient());
162  grant.setGrantId(UUID.randomUUID().toString());
163  grant.setNonce(UUID.randomUUID().toString());
164  grant.setScopes(Sets.newHashSet("openid"));
165  grant.setUser(testUser());
166  return grant;
167  }
static User testUser()
Definition: CacheGrantManual.java:150
static Client testClient()
Definition: CacheGrantManual.java:144

◆ testState()

static SessionId org.xdi.oxauth.dev.CacheGrantManual.testState ( )
inlinestaticprivate
132  {
133  HashMap<String, String> map = new HashMap<String, String>();
134  map.put("mapKey", "mapValue");
135 
136  SessionId state = new SessionId();
137  state.setUserDn("userDn");
138  state.setId(UUID.randomUUID().toString());
139  state.setLastUsedAt(new Date());
140  state.setSessionAttributes(map);
141  return state;
142  }

◆ testUser()

static User org.xdi.oxauth.dev.CacheGrantManual.testUser ( )
inlinestaticprivate
150  {
151  User user = new User();
152  user.setUserId(UUID.randomUUID().toString());
153  return user;
154  }

メンバ詳解

◆ CLIENT_COUNT

final int org.xdi.oxauth.dev.CacheGrantManual.CLIENT_COUNT = 10
staticprivate

◆ RANDOM

final Random org.xdi.oxauth.dev.CacheGrantManual.RANDOM = new Random()
staticprivate

このクラス詳解は次のファイルから抽出されました: