当前位置: 首页>>代码示例>>Java>>正文


Java AtomicReference.get方法代码示例

本文整理汇总了Java中java.util.concurrent.atomic.AtomicReference.get方法的典型用法代码示例。如果您正苦于以下问题:Java AtomicReference.get方法的具体用法?Java AtomicReference.get怎么用?Java AtomicReference.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.util.concurrent.atomic.AtomicReference的用法示例。


在下文中一共展示了AtomicReference.get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: supports

import java.util.concurrent.atomic.AtomicReference; //导入方法依赖的package包/类
@Override
protected boolean supports(Class<?> clazz) {
    JavaType javaType = getJavaType(clazz);
    AtomicReference<Throwable> causeRef = new AtomicReference<Throwable>();
    if (this.objectMapper.canDeserialize(javaType, causeRef)) {
        return true;
    }
    Throwable cause = causeRef.get();
    if (cause != null) {
        String msg = "Failed to evaluate deserialization for type " + javaType;
        if (logger.isDebugEnabled()) {
            logger.warn(msg, cause);
        }
        else {
            logger.warn(msg + ": " + cause);
        }
    }
    return false;
}
 
开发者ID:devefx,项目名称:validator-web,代码行数:20,代码来源:AbstractJackson2HttpMessageReader.java

示例2: compute

import java.util.concurrent.atomic.AtomicReference; //导入方法依赖的package包/类
public final void compute() {
	final Fun<Entry<K, V>, ? extends U> searchFunction;
	final AtomicReference<U> result;
	if ((searchFunction = this.searchFunction) != null && (result = this.result) != null) {
		for (int i = baseIndex, f, h; batch > 0 && (h = ((f = baseLimit) + i) >>> 1) > i;) {
			if (result.get() != null)
				return;
			addToPendingCount(1);
			new SearchEntriesTask<K, V, U>(this, batch >>>= 1, baseLimit = h, f, tab, searchFunction, result)
					.fork();
		}
		while (result.get() == null) {
			U u;
			Node<K, V> p;
			if ((p = advance()) == null) {
				propagateCompletion();
				break;
			}
			if ((u = searchFunction.apply(p)) != null) {
				if (result.compareAndSet(null, u))
					quietlyCompleteRoot();
				return;
			}
		}
	}
}
 
开发者ID:zhangjunfang,项目名称:util,代码行数:27,代码来源:ConcurrentHashMapV8.java

示例3: showMessageDialog

import java.util.concurrent.atomic.AtomicReference; //导入方法依赖的package包/类
private void showMessageDialog() {

        Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        AtomicReference<Point2D> ref = new AtomicReference<>();
        execute(ptr -> {
            ref.set(nativeGetIconLocation(ptr));
        });
        Point2D iconLoc = ref.get();
        if (iconLoc == null) {
            return;
        }

        int dialogY = (int)iconLoc.getY();
        int dialogX = (int)iconLoc.getX();
        if (dialogX + messageDialog.getWidth() > screenSize.width) {
            dialogX = screenSize.width - messageDialog.getWidth();
        }

        messageDialog.setLocation(dialogX, dialogY);
        messageDialog.setVisible(true);
    }
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:22,代码来源:CTrayIcon.java

示例4: getResource

import java.util.concurrent.atomic.AtomicReference; //导入方法依赖的package包/类
private <T extends IResource> T getResource(String name, Class<T> resourceClass) {
	final File fileCandidate = getFullPath().append(name).toFile();
	final AtomicReference<T> actualRef = new AtomicReference<>();
	if (fileCandidate.exists()) {
		acceptUnsafe(resource -> {
			if (resource instanceof IExternalResource && resourceClass.isAssignableFrom(resource.getClass())) {
				if (fileCandidate.equals(((IExternalResource) resource).getExternalResource())) {
					actualRef.set(resourceClass.cast(resource));
					return false;
				}
			}
			return true;
		});
	}

	return actualRef.get(); // TODO return with missing instance?
}
 
开发者ID:eclipse,项目名称:n4js,代码行数:18,代码来源:ExternalProject.java

示例5: bufferLimitTest

import java.util.concurrent.atomic.AtomicReference; //导入方法依赖的package包/类
private static void bufferLimitTest(HeapBufferedAsyncResponseConsumer consumer, int bufferLimit) throws Exception {
    ProtocolVersion protocolVersion = new ProtocolVersion("HTTP", 1, 1);
    StatusLine statusLine = new BasicStatusLine(protocolVersion, 200, "OK");
    consumer.onResponseReceived(new BasicHttpResponse(statusLine));

    final AtomicReference<Long> contentLength = new AtomicReference<>();
    HttpEntity entity = new StringEntity("", ContentType.APPLICATION_JSON) {
        @Override
        public long getContentLength() {
            return contentLength.get();
        }
    };
    contentLength.set(randomLong(bufferLimit));
    consumer.onEntityEnclosed(entity, ContentType.APPLICATION_JSON);

    contentLength.set(randomLongBetween(bufferLimit + 1, MAX_TEST_BUFFER_SIZE));
    try {
        consumer.onEntityEnclosed(entity, ContentType.APPLICATION_JSON);
    } catch(ContentTooLongException e) {
        assertEquals("entity content is too long [" + entity.getContentLength() +
                "] for the configured buffer limit [" + bufferLimit + "]", e.getMessage());
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:24,代码来源:HeapBufferedAsyncResponseConsumerTests.java

示例6: buildComparatorChain

import java.util.concurrent.atomic.AtomicReference; //导入方法依赖的package包/类
public static <T> Comparator<T> buildComparatorChain(Collection<RestSortDirective> sortDirectives, Class<T> rootClass) {
  AtomicReference<Comparator<T>> comparatorChainRef = new AtomicReference<>();

  if (sortDirectives != null && sortDirectives.size() > 0) {

    sortDirectives.forEach(sortDirective -> {
      Comparator<T> comparator = XmlElementPathBeanComparator.forSortDirective(sortDirective, rootClass);

      if (comparatorChainRef.get() == null) {
        comparatorChainRef.set(comparator);
      } else {
        comparatorChainRef.updateAndGet(p -> p.thenComparing(comparator));
      }
    });

  }
  return comparatorChainRef.get();
}
 
开发者ID:Juraji,项目名称:Biliomi,代码行数:19,代码来源:SortDirectiveQueryProcessor.java

示例7: findMatchAndRemoveForSeparateResponse

import java.util.concurrent.atomic.AtomicReference; //导入方法依赖的package包/类
public Optional<CoapTransaction> findMatchAndRemoveForSeparateResponse(CoapPacket req) {
    if ((req.getMessageType() == MessageType.Confirmable || req.getMessageType() == MessageType.NonConfirmable)
            && req.getCode() != null && req.getToken().length > 0) {

        AtomicReference<Optional<CoapTransaction>> transactionFound = new AtomicReference<>(Optional.empty());

        transactionQueues.computeIfPresent(req.getRemoteAddress(), (address, coapTransactions) -> {
            QueueUpdateResult result = coapTransactions.findAndRemoveSeparateResponse(req);

            transactionFound.set(result.coapTransaction);
            return result.transactionQueue;
        });

        return transactionFound.get();
    } else {
        if (LOGGER.isTraceEnabled()) {
            LOGGER.trace("findMatchAndRemoveForSeparateResponse(" + req.toString(false) + "): not found");
        }
        return Optional.empty();
    }
}
 
开发者ID:ARMmbed,项目名称:java-coap,代码行数:22,代码来源:TransactionManager.java

示例8: write

import java.util.concurrent.atomic.AtomicReference; //导入方法依赖的package包/类
@SuppressWarnings("rawtypes")
public void write(JSONSerializer serializer, Object object, Object fieldName, Type fieldType, int features) throws IOException {
    Object item;
    if (object instanceof AtomicReference) {
        AtomicReference val = (AtomicReference) object;
        item = val.get();
    } else {
        item = ((Reference) object).get();
    }
    serializer.write(item);
}
 
开发者ID:tiglabs,项目名称:jsf-sdk,代码行数:12,代码来源:ReferenceCodec.java

示例9: chooseImplementationIfRequired

import java.util.concurrent.atomic.AtomicReference; //导入方法依赖的package包/类
/***
 * Choose an implementation if needed
 *
 * @param runnerId
 *            the runner ID, e.g. NODEJS
 * @param moduleToRun
 *            the emf-full URI to the module to run
 * @return the selected implementation Id
 */
public String chooseImplementationIfRequired(String runnerId, URI moduleToRun) {
	// first see if we need to supply an implementationId
	// (we need one if there are API projects among the dependencies of the moduleToRun AND there exist 2 or more
	// implementations for them)
	final ApiUsage apiUsage = runnerHelper.getProjectExtendedDeps(runnerId, moduleToRun);
	final ApiImplMapping apiImplMapping = apiUsage.apiImplMapping;

	final List<String> availableImplIds = apiImplMapping.getAllImplIds();
	if (apiImplMapping.isEmpty())
		return null; // no API projects among the dependencies -> no need to bother the user
	if (availableImplIds.isEmpty())
		return null; // no implementations available -> error will be shown somewhere else
	if (availableImplIds.size() == 1)
		return availableImplIds.get(0); // exactly 1 implementation -> use that, no need to bother the user
	// make user choose:
	// We have to open the dialog on the UI-thread
	// See:
	// http://stackoverflow.com/questions/354796/whats-the-best-way-to-get-a-return-value-out-of-an-asyncexec-in-eclipse
	final AtomicReference<String> result = new AtomicReference<>();
	final ChooseImplementationDialog dlg = new ChooseImplementationDialog(null, apiImplMapping);
	Display.getDefault().syncExec(new Runnable() {
		@Override
		public void run() {
			if (dlg.open() == Window.OK) {
				result.set((String) dlg.getResult()[0]);
			} else {
				result.set(CANCEL);
			}
		}
	});

	return result.get();
}
 
开发者ID:eclipse,项目名称:n4js,代码行数:43,代码来源:ChooseImplementationHelper.java

示例10: allProposalsAt

import java.util.concurrent.atomic.AtomicReference; //导入方法依赖的package包/类
private ICompletionProposal[] allProposalsAt(RegionWithCursor offset, N4ContentAssistProcessorTestBuilder fixture) {
	AtomicReference<ICompletionProposal[]> w = new AtomicReference<>();

	Display.getDefault().syncExec(() -> {

		try {
			w.set(fixture.computeCompletionProposals(offset
					.getGlobalCursorOffset()));
		} catch (Exception e) {
			logger.warn("Cannot compute Completion Proposals", e);
		}
	});

	return w.get();
}
 
开发者ID:eclipse,项目名称:n4js,代码行数:16,代码来源:ContentAssistXpectMethod.java

示例11: stop

import java.util.concurrent.atomic.AtomicReference; //导入方法依赖的package包/类
private void stop(boolean swallowException) {
    log.trace("Stopping the Connect group member.");
    AtomicReference<Throwable> firstException = new AtomicReference<Throwable>();
    this.stopped = true;
    ClientUtils.closeQuietly(coordinator, "coordinator", firstException);
    ClientUtils.closeQuietly(metrics, "consumer metrics", firstException);
    ClientUtils.closeQuietly(client, "consumer network client", firstException);
    AppInfoParser.unregisterAppInfo(JMX_PREFIX, clientId);
    if (firstException.get() != null && !swallowException)
        throw new KafkaException("Failed to stop the Connect group member", firstException.get());
    else
        log.debug("The Connect group member has stopped.");
}
 
开发者ID:YMCoding,项目名称:kafka-0.11.0.0-src-with-comment,代码行数:14,代码来源:WorkerGroupMember.java

示例12: releaseWaiters

import java.util.concurrent.atomic.AtomicReference; //导入方法依赖的package包/类
/**
 * Removes and signals threads from queue for phase.
 */
private void releaseWaiters(int phase) {
    QNode q;   // first element of queue
    Thread t;  // its thread
    AtomicReference<QNode> head = (phase & 1) == 0 ? evenQ : oddQ;
    while ((q = head.get()) != null &&
           q.phase != (int) (root.state >>> PHASE_SHIFT)) {
        if (head.compareAndSet(q, q.next) &&
            (t = q.thread) != null) {
            q.thread = null;
            LockSupport.unpark(t);
        }
    }
}
 
开发者ID:retrostreams,项目名称:android-retroatomic,代码行数:17,代码来源:Phaser.java

示例13: getMousePosition

import java.util.concurrent.atomic.AtomicReference; //导入方法依赖的package包/类
private static Point getMousePosition(final Component component) throws Exception {
    final AtomicReference<Point> pos = new AtomicReference<Point>();
    SwingUtilities.invokeAndWait(new Runnable() {
        @Override
        public void run() {
            pos.set(component.getMousePosition());
        }
    });
    return pos.get();
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:11,代码来源:GetMousePositionWithOverlay.java

示例14: refreshDeviceCache

import java.util.concurrent.atomic.AtomicReference; //导入方法依赖的package包/类
private DeviceEvent refreshDeviceCache(ProviderId providerId, DeviceId deviceId) {
    AtomicReference<DeviceEvent.Type> eventType = new AtomicReference<>();
    Device device = devices.compute(deviceId, (k, existingDevice) -> {
        Device newDevice = composeDevice(deviceId);
        if (existingDevice == null) {
            eventType.set(DEVICE_ADDED);
        } else {
            // We allow only certain attributes to trigger update
            boolean propertiesChanged =
                    !Objects.equals(existingDevice.hwVersion(), newDevice.hwVersion()) ||
                            !Objects.equals(existingDevice.swVersion(), newDevice.swVersion()) ||
                            !Objects.equals(existingDevice.providerId(), newDevice.providerId());
            boolean annotationsChanged =
                    !AnnotationsUtil.isEqual(existingDevice.annotations(), newDevice.annotations());

            // Primary providers can respond to all changes, but ancillary ones
            // should respond only to annotation changes.
            if ((providerId.isAncillary() && annotationsChanged) ||
                    (!providerId.isAncillary() && (propertiesChanged || annotationsChanged))) {
                boolean replaced = devices.replace(deviceId, existingDevice, newDevice);
                verify(replaced, "Replacing devices cache failed. PID:%s [expected:%s, found:%s, new=%s]",
                        providerId, existingDevice, devices.get(deviceId), newDevice);
                eventType.set(DEVICE_UPDATED);
            }
        }
        return newDevice;
    });
    if (eventType.get() != null && !providerId.isAncillary()) {
        markOnline(deviceId);
    }
    return eventType.get() != null ? new DeviceEvent(eventType.get(), device) : null;
}
 
开发者ID:shlee89,项目名称:athena,代码行数:33,代码来源:ECDeviceStore.java

示例15: unsubscribe

import java.util.concurrent.atomic.AtomicReference; //导入方法依赖的package包/类
public void unsubscribe() {
    State newState;
    AtomicReference<State> localState = this.state;
    State oldState;
    do {
        oldState = (State) localState.get();
        if (!oldState.isUnsubscribed) {
            newState = oldState.unsubscribe();
        } else {
            return;
        }
    } while (!localState.compareAndSet(oldState, newState));
    unsubscribeActualIfApplicable(newState);
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:15,代码来源:RefCountSubscription.java


注:本文中的java.util.concurrent.atomic.AtomicReference.get方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。