use of java.util.concurrent.ConcurrentHashMap in project jdk8u_jdk by JetBrains.
the class _HelloInterface_Stub method sayHelloWithHashMap.
public String sayHelloWithHashMap(ConcurrentHashMap arg0) throws java.rmi.RemoteException {
if (!Util.isLocal(this)) {
try {
org.omg.CORBA_2_3.portable.InputStream in = null;
try {
org.omg.CORBA_2_3.portable.OutputStream out = (org.omg.CORBA_2_3.portable.OutputStream) _request("sayHelloWithHashMap", true);
out.write_value(arg0, ConcurrentHashMap.class);
in = (org.omg.CORBA_2_3.portable.InputStream) _invoke(out);
return (String) in.read_value(String.class);
} catch (ApplicationException ex) {
in = (org.omg.CORBA_2_3.portable.InputStream) ex.getInputStream();
String $_id = in.read_string();
throw new UnexpectedException($_id);
} catch (RemarshalException ex) {
return sayHelloWithHashMap(arg0);
} finally {
_releaseReply(in);
}
} catch (SystemException ex) {
throw Util.mapSystemException(ex);
}
} else {
ServantObject so = _servant_preinvoke("sayHelloWithHashMap", HelloInterface.class);
if (so == null) {
return sayHelloWithHashMap(arg0);
}
try {
ConcurrentHashMap arg0Copy = (ConcurrentHashMap) Util.copyObject(arg0, _orb());
return ((HelloInterface) so.servant).sayHelloWithHashMap(arg0Copy);
} catch (Throwable ex) {
Throwable exCopy = (Throwable) Util.copyObject(ex, _orb());
throw Util.wrapException(exCopy);
} finally {
_servant_postinvoke(so);
}
}
}
use of java.util.concurrent.ConcurrentHashMap in project kdeconnect-android by KDE.
the class DeviceFragment method refreshUI.
void refreshUI() {
if (device == null || rootView == null) {
return;
}
//Once in-app, there is no point in keep displaying the notification if any
device.hidePairingNotification();
mActivity.runOnUiThread(new Runnable() {
@Override
public void run() {
if (device.isPairRequestedByPeer()) {
((TextView) rootView.findViewById(R.id.pair_message)).setText(R.string.pair_requested);
rootView.findViewById(R.id.pair_progress).setVisibility(View.GONE);
rootView.findViewById(R.id.pair_button).setVisibility(View.GONE);
rootView.findViewById(R.id.pair_request).setVisibility(View.VISIBLE);
} else {
boolean paired = device.isPaired();
boolean reachable = device.isReachable();
boolean onData = NetworkHelper.isOnMobileNetwork(getContext());
rootView.findViewById(R.id.pairing_buttons).setVisibility(paired ? View.GONE : View.VISIBLE);
rootView.findViewById(R.id.not_reachable_message).setVisibility((paired && !reachable && !onData) ? View.VISIBLE : View.GONE);
rootView.findViewById(R.id.on_data_message).setVisibility((paired && !reachable && onData) ? View.VISIBLE : View.GONE);
try {
ArrayList<ListAdapter.Item> items = new ArrayList<>();
//Plugins button list
final Collection<Plugin> plugins = device.getLoadedPlugins().values();
for (final Plugin p : plugins) {
if (!p.hasMainActivity())
continue;
if (p.displayInContextMenu())
continue;
items.add(new PluginItem(p, new View.OnClickListener() {
@Override
public void onClick(View v) {
p.startMainActivity(mActivity);
}
}));
}
//Failed plugins List
final ConcurrentHashMap<String, Plugin> failed = device.getFailedPlugins();
if (!failed.isEmpty()) {
if (errorHeader == null) {
errorHeader = new TextView(mActivity);
errorHeader.setPadding(0, ((int) (28 * getResources().getDisplayMetrics().density)), 0, ((int) (8 * getResources().getDisplayMetrics().density)));
errorHeader.setOnClickListener(null);
errorHeader.setOnLongClickListener(null);
errorHeader.setText(getResources().getString(R.string.plugins_failed_to_load));
}
items.add(new CustomItem(errorHeader));
for (Map.Entry<String, Plugin> entry : failed.entrySet()) {
String pluginKey = entry.getKey();
final Plugin plugin = entry.getValue();
if (plugin == null) {
items.add(new SmallEntryItem(pluginKey));
} else {
items.add(new SmallEntryItem(plugin.getDisplayName(), new View.OnClickListener() {
@Override
public void onClick(View v) {
plugin.getErrorDialog(mActivity).show();
}
}));
}
}
}
//Plugins without permissions List
final ConcurrentHashMap<String, Plugin> permissionsNeeded = device.getPluginsWithoutPermissions();
if (!permissionsNeeded.isEmpty()) {
if (noPermissionsHeader == null) {
noPermissionsHeader = new TextView(mActivity);
noPermissionsHeader.setPadding(0, ((int) (28 * getResources().getDisplayMetrics().density)), 0, ((int) (8 * getResources().getDisplayMetrics().density)));
noPermissionsHeader.setOnClickListener(null);
noPermissionsHeader.setOnLongClickListener(null);
noPermissionsHeader.setText(getResources().getString(R.string.plugins_need_permission));
}
items.add(new CustomItem(noPermissionsHeader));
for (Map.Entry<String, Plugin> entry : permissionsNeeded.entrySet()) {
String pluginKey = entry.getKey();
final Plugin plugin = entry.getValue();
if (plugin == null) {
items.add(new SmallEntryItem(pluginKey));
} else {
items.add(new SmallEntryItem(plugin.getDisplayName(), new View.OnClickListener() {
@Override
public void onClick(View v) {
plugin.getPermissionExplanationDialog(mActivity).show();
}
}));
}
}
}
ListView buttonsList = (ListView) rootView.findViewById(R.id.buttons_list);
ListAdapter adapter = new ListAdapter(mActivity, items);
buttonsList.setAdapter(adapter);
mActivity.invalidateOptionsMenu();
} catch (IllegalStateException e) {
e.printStackTrace();
//Ignore: The activity was closed while we were trying to update it
} catch (ConcurrentModificationException e) {
Log.e("DeviceActivity", "ConcurrentModificationException");
//Try again
this.run();
}
}
}
});
}
use of java.util.concurrent.ConcurrentHashMap in project OkHttp3 by MrZhousf.
the class DownUpLoadHelper method downloadFile.
/**
* 文件下载
*/
void downloadFile(final OkHttpHelper helper) {
try {
final HttpInfo info = httpInfo;
final DownloadFileInfo fileInfo = helper.getDownloadFileInfo();
String url = fileInfo.getUrl();
if (TextUtils.isEmpty(url)) {
showLog("下载文件失败:文件下载地址不能为空!");
return;
}
info.setUrl(url);
ProgressCallback progressCallback = fileInfo.getProgressCallback();
//获取文件断点
long completedSize = fetchCompletedSize(fileInfo);
fileInfo.setCompletedSize(completedSize);
//添加下载任务
if (null == downloadTaskMap)
downloadTaskMap = new ConcurrentHashMap<>();
if (downloadTaskMap.containsKey(fileInfo.getSaveFileNameEncrypt())) {
showLog(fileInfo.getSaveFileName() + " 已在下载任务中");
return;
}
downloadTaskMap.put(fileInfo.getSaveFileNameEncrypt(), fileInfo.getSaveFileNameEncrypt());
Interceptor interceptor = new Interceptor() {
@Override
public Response intercept(Chain chain) throws IOException {
Response originalResponse = chain.proceed(chain.request());
return originalResponse.newBuilder().body(new ProgressResponseBody(originalResponse.body(), fileInfo, timeStamp, requestTag)).build();
}
};
//采用新的OkHttpClient处理多线程干扰回调进度问题
OkHttpClient httpClient = helper.getClientBuilder().addInterceptor(interceptor).build();
Request.Builder requestBuilder = new Request.Builder();
requestBuilder.url(url).header("RANGE", "bytes=" + completedSize + "-");
helper.getHttpHelper().addHeadsToRequest(info, requestBuilder);
Request request = requestBuilder.build();
helper.setRequest(request);
helper.setHttpClient(httpClient);
helper.getHttpHelper().responseCallback(helper.doRequestSync(), progressCallback, OkMainHandler.RESPONSE_DOWNLOAD_CALLBACK, requestTag);
//删除下载任务
if (null != downloadTaskMap) {
downloadTaskMap.remove(fileInfo.getSaveFileNameEncrypt());
}
} catch (Exception e) {
showLog("下载文件失败:" + e.getMessage());
}
}
use of java.util.concurrent.ConcurrentHashMap in project OpenAM by OpenRock.
the class InternalSession method setRestrictedTokensBySid.
/**
* This setter method is used by the JSON serialization mechanism and should not be used for other purposes.
*
* @param restrictedTokensBySid The deserialized map of sid<->restricted tokens that should be stored in a
* ConcurrentHashMap.
*/
@JsonSetter
private void setRestrictedTokensBySid(ConcurrentMap<SessionID, TokenRestriction> restrictedTokensBySid) {
for (Map.Entry<SessionID, TokenRestriction> entry : restrictedTokensBySid.entrySet()) {
SessionID sid = entry.getKey();
TokenRestriction restriction = entry.getValue();
this.restrictedTokensBySid.put(sid, restriction);
this.restrictedTokensByRestriction.put(restriction, sid);
}
}
use of java.util.concurrent.ConcurrentHashMap in project pcgen by PCGen.
the class BonusManager method getPartialStatBonusFor.
public int getPartialStatBonusFor(PCStat stat, boolean useTemp, boolean useEquip) {
String statAbbr = stat.getKeyName();
final String prefix = "STAT." + statAbbr;
Map<String, String> bonusMap = new HashMap<>();
Map<String, String> nonStackMap = new ConcurrentHashMap<>();
Map<String, String> stackMap = new ConcurrentHashMap<>();
for (BonusObj bonus : getActiveBonusList()) {
if (pc.isApplied(bonus) && bonus.getBonusName().equals("STAT")) {
boolean found = false;
Object co = getSourceObject(bonus);
for (Object element : bonus.getBonusInfoList()) {
if (element instanceof PCStat && element.equals(stat)) {
found = true;
break;
}
// parisng.
if (element instanceof MissingObject) {
String name = ((MissingObject) element).getObjectName();
if (("%LIST".equals(name) || "LIST".equals(name)) && co instanceof CDOMObject) {
CDOMObject creator = (CDOMObject) co;
for (String assoc : pc.getConsolidatedAssociationList(creator)) {
//TODO Case sensitivity?
if (assoc.contains(statAbbr)) {
found = true;
break;
}
}
}
}
}
if (!found) {
continue;
}
// The bonus has been applied to the target stat
// Should it be included?
boolean addIt = false;
if (co instanceof Equipment || co instanceof EquipmentModifier) {
addIt = useEquip;
} else if (co instanceof Ability) {
List<String> types = ((Ability) co).getTypes();
if (types.contains("Equipment")) {
addIt = useEquip;
} else {
addIt = true;
}
} else if (tempBonusBySource.containsKey(bonus)) {
addIt = useTemp;
} else {
addIt = true;
}
if (addIt) {
// bonuses with the stacking rules applied.
for (BonusPair bp : getStringListFromBonus(bonus)) {
if (bp.fullyQualifiedBonusType.startsWith(prefix)) {
setActiveBonusStack(bp.resolve(pc).doubleValue(), bp.fullyQualifiedBonusType, nonStackMap, stackMap);
totalBonusesForType(nonStackMap, stackMap, bp.fullyQualifiedBonusType, bonusMap);
}
}
}
}
}
// Sum the included bonuses to the stat to get our result.
int total = 0;
for (String bKey : bonusMap.keySet()) {
total += Float.parseFloat(bonusMap.get(bKey));
}
return total;
}
Aggregations