Skip to content

Commit

Permalink
Refactor PrivilegeBuilder (apache#9756)
Browse files Browse the repository at this point in the history
* Refactor PrivilegeBuilder

* Refactor PrivilegeMerger

* Refactor PrivilegeBuilder
  • Loading branch information
terrymanu authored Mar 21, 2021
1 parent 581419b commit 1dcb372
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public final class PrivilegeBuilder {

private static final int CPU_CORES = Runtime.getRuntime().availableProcessors();

private static final int FUTURE_GET_TIME_OUT_SECOND = 5;
private static final long FUTURE_GET_TIME_OUT_MILLISECONDS = 5000L;

/**
* Build privileges.
Expand Down Expand Up @@ -102,7 +102,7 @@ private static Collection<ShardingSpherePrivilege> load(final Collection<DataSou
}
futures.forEach(each -> {
try {
each.get(FUTURE_GET_TIME_OUT_SECOND, TimeUnit.SECONDS).ifPresent(result::add);
each.get(FUTURE_GET_TIME_OUT_MILLISECONDS, TimeUnit.MILLISECONDS).ifPresent(result::add);
} catch (final InterruptedException | ExecutionException | TimeoutException ex) {
throw new IllegalStateException(String.format("Error while loading privilege with %s", each), ex);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;

/**
* Privilege merger.
Expand All @@ -36,18 +37,18 @@
public final class PrivilegeMerger {

/**
* Merge.
* Merge privilege.
*
* @param authentication authentication
* @param schemaName schema name
* @param rules ShardingSphere rules
* @return privileges
*/
public static Map<ShardingSphereUser, ShardingSpherePrivilege> merge(final Map<ShardingSphereUser, Collection<ShardingSpherePrivilege>> authentication,
final String schemaName, final Collection<ShardingSphereRule> rules) {
Map<ShardingSphereUser, ShardingSpherePrivilege> result = new HashMap<>();
for (ShardingSphereUser each : authentication.keySet()) {
result.put(each, merge(each, authentication.get(each)));
final String schemaName, final Collection<ShardingSphereRule> rules) {
Map<ShardingSphereUser, ShardingSpherePrivilege> result = new HashMap<>(authentication.size(), 1);
for (Entry<ShardingSphereUser, Collection<ShardingSpherePrivilege>> entry : authentication.entrySet()) {
result.put(entry.getKey(), merge(entry.getKey(), entry.getValue()));
}
return result;
}
Expand Down

0 comments on commit 1dcb372

Please sign in to comment.