类java.nio.channels.IllegalSelectorException源码实例Demo

下面列出了怎么用java.nio.channels.IllegalSelectorException的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: training   文件: NormalSlot.java
@Override
public void park(char carType) {
	if (!isFree()) {
		throw new IllegalSelectorException();
	}
	this.carType = carType;
}
 
源代码2 项目: j2objc   文件: IllegalSelectorExceptionTest.java
/**
 * @tests {@link java.nio.channels.IllegalSelectorException#IllegalSelectorException()}
 */
public void test_Constructor() {
    IllegalSelectorException e = new IllegalSelectorException();
    assertNull(e.getMessage());
    assertNull(e.getLocalizedMessage());
    assertNull(e.getCause());
}
 
源代码3 项目: linstor-server   文件: TcpConnectorService.java
@Override
public Peer connect(InetSocketAddress address, Node node) throws IOException
{
    Selector srvSel = serverSelector;
    Peer peer;
    if (srvSel != null)
    {
        SocketChannel socketChannel = null;
        try
        {
            socketChannel = SocketChannel.open();
            socketChannel.configureBlocking(false);
            socketChannel.socket().setTcpNoDelay(true);
            String peerId = address.getAddress().getHostAddress() + ":" + address.getPort();
            SelectionKey connKey;
            synchronized (syncObj)
            {
                srvSel.wakeup();
                boolean connected = socketChannel.connect(address);
                if (connected)
                {
                    // if connect is true, we will never receive an OP_CONNECT
                    // even if we register for it.
                    // as the controller does not know about this peer (we didnt return yet)
                    // we will register for no operation.
                    // As soon as the controller tries to send a message, that will trigger the OP_WRITE anyways
                    connKey = socketChannel.register(srvSel, 0);
                }
                else
                {
                    // if connect returns false we will receive OP_CONNECT
                    // and we will need to call the finishConnection()
                    connKey = socketChannel.register(srvSel, OP_CONNECT);
                }
                peer = createTcpConnectorPeer(peerId, connKey, true, node);
                connKey.attach(peer);
                if (connected)
                {
                    // May throw SSLException
                    peer.connectionEstablished();
                    connObserver.outboundConnectionEstablished(peer);
                }
                else
                {
                    connObserver.outboundConnectionEstablishing(peer);
                }
                try
                {
                    node.setPeer(privilegedAccCtx, peer);
                }
                catch (AccessDeniedException accDeniedExc)
                {
                    throw new ImplementationError(
                        "TcpConnectorService privileged access context not authorized for node.setPeer() " +
                        "called from connect()",
                        accDeniedExc
                    );
                }
            }
        }
        catch (IOException ioExc)
        {
            try
            {
                if (socketChannel != null)
                {
                    socketChannel.close();
                }
            }
            catch (IOException ignored)
            {
            }
            throw ioExc;
        }
        catch (IllegalBlockingModeException blkModeException)
        {
            throw new IOException(
                "Connect request failed - Non-blocking I/O mode requested, but not supported"
            );
        }
        catch (IllegalSelectorException | ClosedSelectorException |
               CancelledKeyException connExc)
        {
            throw new IOException(
                "Connect request failed - Connector service '" + serviceInstanceName + "' state changed " +
                "while the operation was in progress"
            );
        }
    }
    else
    {
        throw new IOException(
            "Connect request failed - Connector service '" + serviceInstanceName + "' is stopped"
        );
    }
    return peer;
}
 
源代码4 项目: onedev   文件: Response.java
@Override
public void setContentType(String contentType)
{
    if (isCommitted() || !isMutable())
        return;

    if (contentType == null)
    {
        if (isWriting() && _characterEncoding != null)
            throw new IllegalSelectorException();

        if (_locale == null)
            _characterEncoding = null;
        _mimeType = null;
        _contentType = null;
        _fields.remove(HttpHeader.CONTENT_TYPE);
    }
    else
    {
        _contentType = contentType;
        _mimeType = MimeTypes.CACHE.get(contentType);

        String charset;
        if (_mimeType != null && _mimeType.getCharset() != null && !_mimeType.isCharsetAssumed())
            charset = _mimeType.getCharsetString();
        else
            charset = MimeTypes.getCharsetFromContentType(contentType);

        if (charset == null)
        {
            switch (_encodingFrom)
            {
                case NOT_SET:
                    break;
                case INFERRED:
                case SET_CONTENT_TYPE:
                    if (isWriting())
                    {
                        _mimeType = null;
                        _contentType = _contentType + ";charset=" + _characterEncoding;
                    }
                    else
                    {
                        _encodingFrom = EncodingFrom.NOT_SET;
                        _characterEncoding = null;
                    }
                    break;
                case SET_LOCALE:
                case SET_CHARACTER_ENCODING:
                {
                    _contentType = contentType + ";charset=" + _characterEncoding;
                    _mimeType = null;
                }
            }
        }
        else if (isWriting() && !charset.equalsIgnoreCase(_characterEncoding))
        {
            // too late to change the character encoding;
            _mimeType = null;
            _contentType = MimeTypes.getContentTypeWithoutCharset(_contentType);
            if (_characterEncoding != null)
                _contentType = _contentType + ";charset=" + _characterEncoding;
        }
        else
        {
            _characterEncoding = charset;
            _encodingFrom = EncodingFrom.SET_CONTENT_TYPE;
        }

        if (HttpGenerator.__STRICT || _mimeType == null)
            _fields.put(HttpHeader.CONTENT_TYPE, _contentType);
        else
        {
            _contentType = _mimeType.asString();
            _fields.put(_mimeType.getContentTypeField());
        }
    }
}
 
源代码5 项目: onedev   文件: PullRequest.java
public ObjectId getComparisonBase(ObjectId oldCommitId, ObjectId newCommitId) {
	if (isNew() || oldCommitId.equals(newCommitId))
		return oldCommitId;
	
	PullRequestInfoManager infoManager = OneDev.getInstance(PullRequestInfoManager.class);
	ObjectId comparisonBase = infoManager.getComparisonBase(this, oldCommitId, newCommitId);
	if (comparisonBase != null) {
		try {
			if (!getTargetProject().getRepository().getObjectDatabase().has(comparisonBase))
				comparisonBase = null;
		} catch (IOException e) {
			throw new RuntimeException(e);
		}
	}
	if (comparisonBase == null) {
		for (PullRequestUpdate update: getSortedUpdates()) {
			if (update.getCommits().contains(newCommitId)) {
				ObjectId targetHead = ObjectId.fromString(update.getTargetHeadCommitHash());
				Repository repo = getTargetProject().getRepository();
				ObjectId mergeBase1 = GitUtils.getMergeBase(repo, targetHead, newCommitId);
				if (mergeBase1 != null) {
					ObjectId mergeBase2 = GitUtils.getMergeBase(repo, mergeBase1, oldCommitId);
					if (mergeBase2.equals(mergeBase1)) {
						comparisonBase = oldCommitId;
						break;
					} else if (mergeBase2.equals(oldCommitId)) {
						comparisonBase = mergeBase1;
						break;
					} else {
						PersonIdent person = new PersonIdent("OneDev", "");
						comparisonBase = GitUtils.merge(repo, oldCommitId, mergeBase1, false, 
								person, person, "helper commit", true);
						break;
					}
				} else {
					return oldCommitId;
				}
			}
		}
		if (comparisonBase != null)
			infoManager.cacheComparisonBase(this, oldCommitId, newCommitId, comparisonBase);
		else
			throw new IllegalSelectorException();
	}
	return comparisonBase;
}
 
源代码6 项目: j2objc   文件: IllegalSelectorExceptionTest.java
/**
 * @tests serialization/deserialization compatibility.
 */
public void testSerializationSelf() throws Exception {

    SerializationTest.verifySelf(new IllegalSelectorException());
}
 
源代码7 项目: j2objc   文件: IllegalSelectorExceptionTest.java
/**
 * @tests serialization/deserialization compatibility with RI.
 */
public void testSerializationCompatibility() throws Exception {

    SerializationTest.verifyGolden(this, new IllegalSelectorException());
}
 
 类所在包
 同包方法