java.nio.channels.IllegalSelectorException Java Examples

The following examples show how to use java.nio.channels.IllegalSelectorException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: NormalSlot.java    From training with MIT License 5 votes vote down vote up
@Override
public void park(char carType) {
	if (!isFree()) {
		throw new IllegalSelectorException();
	}
	this.carType = carType;
}
 
Example #2
Source File: IllegalSelectorExceptionTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * @tests {@link java.nio.channels.IllegalSelectorException#IllegalSelectorException()}
 */
public void test_Constructor() {
    IllegalSelectorException e = new IllegalSelectorException();
    assertNull(e.getMessage());
    assertNull(e.getLocalizedMessage());
    assertNull(e.getCause());
}
 
Example #3
Source File: TcpConnectorService.java    From linstor-server with GNU General Public License v3.0 4 votes vote down vote up
@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;
}
 
Example #4
Source File: Response.java    From onedev with MIT License 4 votes vote down vote up
@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());
        }
    }
}
 
Example #5
Source File: PullRequest.java    From onedev with MIT License 4 votes vote down vote up
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;
}
 
Example #6
Source File: IllegalSelectorExceptionTest.java    From j2objc with Apache License 2.0 4 votes vote down vote up
/**
 * @tests serialization/deserialization compatibility.
 */
public void testSerializationSelf() throws Exception {

    SerializationTest.verifySelf(new IllegalSelectorException());
}
 
Example #7
Source File: IllegalSelectorExceptionTest.java    From j2objc with Apache License 2.0 4 votes vote down vote up
/**
 * @tests serialization/deserialization compatibility with RI.
 */
public void testSerializationCompatibility() throws Exception {

    SerializationTest.verifyGolden(this, new IllegalSelectorException());
}