keycloak-service
公開メンバ関数 | 限定公開メンバ関数 | 静的限定公開変数類 | 非公開変数類 | 静的非公開変数類 | 全メンバ一覧
org.keycloak.executors.DefaultExecutorsProviderFactory クラス
org.keycloak.executors.DefaultExecutorsProviderFactory の継承関係図
Inheritance graph
org.keycloak.executors.DefaultExecutorsProviderFactory 連携図
Collaboration graph

公開メンバ関数

ExecutorsProvider create (KeycloakSession session)
 
void init (Config.Scope config)
 
void postInit (KeycloakSessionFactory factory)
 
void close ()
 
String getId ()
 

限定公開メンバ関数

ExecutorService getExecutor (String taskType, KeycloakSession session)
 
ExecutorService retrievePool (String taskType, KeycloakSession session)
 
void detectManaged ()
 
ExecutorService getPoolManaged (String taskType, KeycloakSession session)
 
ExecutorService createPoolEmbedded (String taskType, KeycloakSession session)
 
ThreadFactory createThreadFactory (String taskType, KeycloakSession session)
 

静的限定公開変数類

static final Logger logger = Logger.getLogger(DefaultExecutorsProviderFactory.class)
 

非公開変数類

Config.Scope config
 
Boolean managed = null
 
final Map< String, ExecutorService > executors = new ConcurrentHashMap<>()
 

静的非公開変数類

static final int DEFAULT_MIN_THREADS = 4
 
static final int DEFAULT_MAX_THREADS = 64
 
static final String MANAGED_EXECUTORS_SERVICE_JNDI_PREFIX = "java:jboss/ee/concurrency/executor/"
 
static final String DEFAULT_MANAGED_EXECUTORS_SERVICE_JNDI = MANAGED_EXECUTORS_SERVICE_JNDI_PREFIX + "default"
 

詳解

著者
Marek Posolda

関数詳解

◆ close()

void org.keycloak.executors.DefaultExecutorsProviderFactory.close ( )
inline
89  {
90  if (managed != null && !managed) {
91  for (Map.Entry<String, ExecutorService> executor : executors.entrySet()) {
92  logger.debugf("Shutting down executor for task '%s'", executor.getKey());
93  executor.getValue().shutdown();
94  }
95  }
96  }
final Map< String, ExecutorService > executors
Definition: DefaultExecutorsProviderFactory.java:59
static final Logger logger
Definition: DefaultExecutorsProviderFactory.java:45
Boolean managed
Definition: DefaultExecutorsProviderFactory.java:57

◆ create()

ExecutorsProvider org.keycloak.executors.DefaultExecutorsProviderFactory.create ( KeycloakSession  session)
inline
63  {
64  return new ExecutorsProvider() {
65 
66  @Override
67  public ExecutorService getExecutor(String taskType) {
68  return DefaultExecutorsProviderFactory.this.getExecutor(taskType, session);
69  }
70 
71  @Override
72  public void close() {
73 
74  }
75  };
76  }
ExecutorService getExecutor(String taskType, KeycloakSession session)
Definition: DefaultExecutorsProviderFactory.java:106
void close()
Definition: DefaultExecutorsProviderFactory.java:89

◆ createPoolEmbedded()

ExecutorService org.keycloak.executors.DefaultExecutorsProviderFactory.createPoolEmbedded ( String  taskType,
KeycloakSession  session 
)
inlineprotected
172  {
173  Config.Scope currentScope = config.scope(taskType);
174  int min = DEFAULT_MIN_THREADS;
175  int max = DEFAULT_MAX_THREADS;
176 
177  if (currentScope != null) {
178  min = currentScope.getInt("min", DEFAULT_MIN_THREADS);
179  max = currentScope.getInt("max", DEFAULT_MAX_THREADS);
180  }
181 
182  logger.debugf("Creating pool for task '%s': min=%d, max=%d", taskType, min, max);
183 
184  ThreadFactory threadFactory = createThreadFactory(taskType, session);
185 
186  if (min == max) {
187  return Executors.newFixedThreadPool(min, threadFactory);
188  } else {
189  // Same like Executors.newCachedThreadPool. Besides that "min" and "max" are configurable
190  return new ThreadPoolExecutor(min, max,
191  60L, TimeUnit.SECONDS,
192  new SynchronousQueue<Runnable>(),
193  threadFactory);
194  }
195  }
Config.Scope config
Definition: DefaultExecutorsProviderFactory.java:55
static final int DEFAULT_MAX_THREADS
Definition: DefaultExecutorsProviderFactory.java:48
static final int DEFAULT_MIN_THREADS
Definition: DefaultExecutorsProviderFactory.java:47
ThreadFactory createThreadFactory(String taskType, KeycloakSession session)
Definition: DefaultExecutorsProviderFactory.java:198
static final Logger logger
Definition: DefaultExecutorsProviderFactory.java:45

◆ createThreadFactory()

ThreadFactory org.keycloak.executors.DefaultExecutorsProviderFactory.createThreadFactory ( String  taskType,
KeycloakSession  session 
)
inlineprotected
198  {
199  return new ThreadFactory() {
200 
201  private AtomicInteger i = new AtomicInteger(0);
202  private int group = new Random().nextInt(2048);
203 
204  @Override
205  public Thread newThread(Runnable r) {
206  int threadNumber = i.getAndIncrement();
207  String threadName = "kc-" + taskType + "-" + group + "-" + threadNumber;
208 
209  if (logger.isTraceEnabled()) {
210  logger.tracef("Creating thread: %s", threadName);
211  }
212 
213  return new Thread(r, threadName);
214  }
215 
216  };
217  }
static final Logger logger
Definition: DefaultExecutorsProviderFactory.java:45

◆ detectManaged()

void org.keycloak.executors.DefaultExecutorsProviderFactory.detectManaged ( )
inlineprotected
136  {
137  String jndiName = MANAGED_EXECUTORS_SERVICE_JNDI_PREFIX + "default";
138  try {
139  new InitialContext().lookup(jndiName);
140  logger.debugf("We are in managed environment. Executor '%s' was available.", jndiName);
141  managed = true;
142  } catch (NamingException nnfe) {
143  logger.debugf("We are not in managed environment. Executor '%s' was not available.", jndiName);
144  managed = false;
145  }
146  }
static final Logger logger
Definition: DefaultExecutorsProviderFactory.java:45
Boolean managed
Definition: DefaultExecutorsProviderFactory.java:57
static final String MANAGED_EXECUTORS_SERVICE_JNDI_PREFIX
Definition: DefaultExecutorsProviderFactory.java:50

◆ getExecutor()

ExecutorService org.keycloak.executors.DefaultExecutorsProviderFactory.getExecutor ( String  taskType,
KeycloakSession  session 
)
inlineprotected
106  {
107  ExecutorService existing = executors.get(taskType);
108 
109  if (existing == null) {
110  synchronized (this) {
111  if (!executors.containsKey(taskType)) {
112  ExecutorService executor = retrievePool(taskType, session);
113  executors.put(taskType, executor);
114  }
115 
116  existing = executors.get(taskType);
117  }
118  }
119 
120  return existing;
121  }
ExecutorService retrievePool(String taskType, KeycloakSession session)
Definition: DefaultExecutorsProviderFactory.java:124
final Map< String, ExecutorService > executors
Definition: DefaultExecutorsProviderFactory.java:59

◆ getId()

String org.keycloak.executors.DefaultExecutorsProviderFactory.getId ( )
inline
99  {
100  return "default";
101  }

◆ getPoolManaged()

ExecutorService org.keycloak.executors.DefaultExecutorsProviderFactory.getPoolManaged ( String  taskType,
KeycloakSession  session 
)
inlineprotected
149  {
150  try {
151  InitialContext ctx = new InitialContext();
152 
153  // First check if specific pool for the task
154  String jndiName = MANAGED_EXECUTORS_SERVICE_JNDI_PREFIX + taskType;
155  try {
156  ExecutorService executor = (ExecutorService) ctx.lookup(jndiName);
157  logger.debugf("Found executor for '%s' under JNDI name '%s'", taskType, jndiName);
158  return executor;
159  } catch (NameNotFoundException nnfe) {
160  logger.debugf("Not found executor for '%s' under specific JNDI name '%s'. Fallback to the default pool", taskType, jndiName);
161 
162  ExecutorService executor = (ExecutorService) ctx.lookup(DEFAULT_MANAGED_EXECUTORS_SERVICE_JNDI);
163  logger.debugf("Found default executor for '%s' of JNDI name '%s'", taskType, DEFAULT_MANAGED_EXECUTORS_SERVICE_JNDI);
164  return executor;
165  }
166  } catch (NamingException ne) {
167  throw new IllegalStateException(ne);
168  }
169  }
static final Logger logger
Definition: DefaultExecutorsProviderFactory.java:45
static final String DEFAULT_MANAGED_EXECUTORS_SERVICE_JNDI
Definition: DefaultExecutorsProviderFactory.java:53
static final String MANAGED_EXECUTORS_SERVICE_JNDI_PREFIX
Definition: DefaultExecutorsProviderFactory.java:50

◆ init()

void org.keycloak.executors.DefaultExecutorsProviderFactory.init ( Config.Scope  config)
inline
79  {
80  this.config = config;
81  }
Config.Scope config
Definition: DefaultExecutorsProviderFactory.java:55

◆ postInit()

void org.keycloak.executors.DefaultExecutorsProviderFactory.postInit ( KeycloakSessionFactory  factory)
inline
84  {
85 
86  }

◆ retrievePool()

ExecutorService org.keycloak.executors.DefaultExecutorsProviderFactory.retrievePool ( String  taskType,
KeycloakSession  session 
)
inlineprotected
124  {
125  if (managed == null) {
126  detectManaged();
127  }
128 
129  if (managed) {
130  return getPoolManaged(taskType, session);
131  } else {
132  return createPoolEmbedded(taskType, session);
133  }
134  }
ExecutorService createPoolEmbedded(String taskType, KeycloakSession session)
Definition: DefaultExecutorsProviderFactory.java:172
Boolean managed
Definition: DefaultExecutorsProviderFactory.java:57
ExecutorService getPoolManaged(String taskType, KeycloakSession session)
Definition: DefaultExecutorsProviderFactory.java:149
void detectManaged()
Definition: DefaultExecutorsProviderFactory.java:136

メンバ詳解

◆ config

Config.Scope org.keycloak.executors.DefaultExecutorsProviderFactory.config
private

◆ DEFAULT_MANAGED_EXECUTORS_SERVICE_JNDI

final String org.keycloak.executors.DefaultExecutorsProviderFactory.DEFAULT_MANAGED_EXECUTORS_SERVICE_JNDI = MANAGED_EXECUTORS_SERVICE_JNDI_PREFIX + "default"
staticprivate

◆ DEFAULT_MAX_THREADS

final int org.keycloak.executors.DefaultExecutorsProviderFactory.DEFAULT_MAX_THREADS = 64
staticprivate

◆ DEFAULT_MIN_THREADS

final int org.keycloak.executors.DefaultExecutorsProviderFactory.DEFAULT_MIN_THREADS = 4
staticprivate

◆ executors

final Map<String, ExecutorService> org.keycloak.executors.DefaultExecutorsProviderFactory.executors = new ConcurrentHashMap<>()
private

◆ logger

final Logger org.keycloak.executors.DefaultExecutorsProviderFactory.logger = Logger.getLogger(DefaultExecutorsProviderFactory.class)
staticprotected

◆ managed

Boolean org.keycloak.executors.DefaultExecutorsProviderFactory.managed = null
private

◆ MANAGED_EXECUTORS_SERVICE_JNDI_PREFIX

final String org.keycloak.executors.DefaultExecutorsProviderFactory.MANAGED_EXECUTORS_SERVICE_JNDI_PREFIX = "java:jboss/ee/concurrency/executor/"
staticprivate

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