Search in sources :

Example 96 with ConcurrentHashMap

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);
        }
    }
}
Also used : UnexpectedException(java.rmi.UnexpectedException) InputStream(org.omg.CORBA.portable.InputStream) OutputStream(org.omg.CORBA.portable.OutputStream) RemarshalException(org.omg.CORBA.portable.RemarshalException) ApplicationException(org.omg.CORBA.portable.ApplicationException) SystemException(org.omg.CORBA.SystemException) ServantObject(org.omg.CORBA.portable.ServantObject) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Example 97 with ConcurrentHashMap

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();
                }
            }
        }
    });
}
Also used : CustomItem(org.kde.kdeconnect.UserInterface.List.CustomItem) ConcurrentModificationException(java.util.ConcurrentModificationException) ArrayList(java.util.ArrayList) View(android.view.View) TextView(android.widget.TextView) ListView(android.widget.ListView) SmallEntryItem(org.kde.kdeconnect.UserInterface.List.SmallEntryItem) ListView(android.widget.ListView) Collection(java.util.Collection) TextView(android.widget.TextView) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) PluginItem(org.kde.kdeconnect.UserInterface.List.PluginItem) ListAdapter(org.kde.kdeconnect.UserInterface.List.ListAdapter) Plugin(org.kde.kdeconnect.Plugins.Plugin)

Example 98 with ConcurrentHashMap

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());
    }
}
Also used : DownloadFileInfo(com.okhttplib.bean.DownloadFileInfo) OkHttpClient(okhttp3.OkHttpClient) ProgressCallback(com.okhttplib.callback.ProgressCallback) Request(okhttp3.Request) ProgressResponseBody(com.okhttplib.progress.ProgressResponseBody) SocketException(java.net.SocketException) SocketTimeoutException(java.net.SocketTimeoutException) IOException(java.io.IOException) HttpInfo(com.okhttplib.HttpInfo) Response(okhttp3.Response) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Interceptor(okhttp3.Interceptor)

Example 99 with ConcurrentHashMap

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&lt;->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);
    }
}
Also used : TokenRestriction(com.iplanet.dpro.session.TokenRestriction) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) SessionID(com.iplanet.dpro.session.SessionID) JsonSetter(com.fasterxml.jackson.annotation.JsonSetter)

Example 100 with ConcurrentHashMap

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;
}
Also used : BonusObj(pcgen.core.bonus.BonusObj) HashMap(java.util.HashMap) IdentityHashMap(java.util.IdentityHashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) BonusPair(pcgen.core.bonus.BonusPair) CDOMObject(pcgen.cdom.base.CDOMObject) CDOMObject(pcgen.cdom.base.CDOMObject) MissingObject(pcgen.core.bonus.util.MissingObject) ArrayList(java.util.ArrayList) List(java.util.List) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) MissingObject(pcgen.core.bonus.util.MissingObject)

Aggregations

ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)357 Test (org.junit.Test)94 Map (java.util.Map)88 HashMap (java.util.HashMap)60 ArrayList (java.util.ArrayList)57 IOException (java.io.IOException)44 CountDownLatch (java.util.concurrent.CountDownLatch)40 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)36 List (java.util.List)27 Set (java.util.Set)26 ConcurrentMap (java.util.concurrent.ConcurrentMap)26 HashSet (java.util.HashSet)23 ExecutorService (java.util.concurrent.ExecutorService)22 Random (java.util.Random)18 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)18 AtomicLong (java.util.concurrent.atomic.AtomicLong)18 Configuration (org.apache.hadoop.conf.Configuration)16 Collection (java.util.Collection)13 Iterator (java.util.Iterator)13 Path (org.apache.hadoop.fs.Path)13