@Override
    @Committing
    @PureWithSideEffects
    @SuppressWarnings("UseSpecificCatch")
    public void run() {
        try {
            final @Nonnull String address = getSocket().getInetAddress().getHostAddress();
            Log.debugging("Received a request from $.", address);
            final @Nonnull Time start = TimeBuilder.build();
            @Nullable Encryption<Signature<Compression<Pack>>> encryptedMethod = null;
            @Nullable Signature<Compression<Pack>> signedMethod = null;
            @Nullable Method<?> method = null;
            @Nullable Reply<?> reply = null;
            try {
                try {
                    final @Nonnull Pack pack = Pack.loadFrom(getSocket());
                    final @Nonnull Request request = pack.unpack(RequestConverter.INSTANCE, null);
                    encryptedMethod = request.getEncryption();
                    final @Nullable HostIdentifier recipient = encryptedMethod.getRecipient();
                    if (recipient == null) { throw RequestExceptionBuilder.withCode(RequestErrorCode.RECIPIENT).withMessage("The recipient may not be null.").build(); }
                    final @Nonnull Host host = Host.of(recipient);
                    signedMethod = encryptedMethod.getObject();
                    final @Nonnull SemanticType type = signedMethod.getObject().getObject().getType();
                    Log.debugging("Executing the method $ on host $.", type.getAddress(), recipient);
                    final @Nonnull InternalIdentifier subject;
                    if (type.equals(OpenAccount.TYPE)) { subject = recipient; } else { subject = signedMethod.getSubject(); }
                    final @Nonnull Account account = Account.with(host, subject.resolve());
                    method = MethodIndex.get(signedMethod, account);
                    reply = method.executeOnHost();
                    Database.commit();
                } catch (@Nonnull InternalException exception) {
                    throw RequestExceptionBuilder.withCode(RequestErrorCode.INTERNAL).withMessage("An internal problem occurred.").withCause(exception).build();
                } catch (@Nonnull ExternalException exception) {
                    throw RequestExceptionBuilder.withCode(RequestErrorCode.EXTERNAL).withMessage("An external problem occurred.").withCause(exception).build();
                }
            } catch (@Nonnull RequestException exception) {
                Database.rollback();
                Log.warning("A request error occurred:", exception);
                reply = RequestExceptionReplyBuilder.withRequestException(exception.isDecoded() ? RequestExceptionBuilder.withCode(RequestErrorCode.REQUEST).withMessage("Another server responded with a request error.").withCause(exception).build() : exception).build();
            }
            if (reply == null) { reply = EmptyReplyBuilder.build(); }
            final @Nonnull Compression<Pack> compressedReply = CompressionBuilder.withObject(reply.pack()).build();
            // The reply.pack() statement maps the semantic type of the reply converter, which results in a concurrent update if the client unpacks the response with the same database. The following commit prevents this. However, it is a suboptimal fix for this problem.
            try { Database.commit(); } catch (@Nonnull DatabaseException exception) { Database.rollback(); }
            final @Nonnull Signature<Compression<Pack>> signedReply;
            if (encryptedMethod != null && signedMethod != null) {
                signedReply = HostSignatureCreator.sign(compressedReply, CompressionConverterBuilder.withObjectConverter(PackConverter.INSTANCE).build()).about(signedMethod.getSubject()).as(encryptedMethod.getRecipient());
            } else {
                signedReply = SignatureBuilder.withObjectConverter(CompressionConverterBuilder.withObjectConverter(PackConverter.INSTANCE).build()).withObject(compressedReply).withSubject(HostIdentifier.DIGITALID).build();
            }
            final @Nonnull Encryption<Signature<Compression<Pack>>> encryptedReply;
            if (encryptedMethod instanceof RequestEncryption) {
                encryptedReply = ResponseEncryptionBuilder.withObject(signedReply).withSymmetricKey(((RequestEncryption) encryptedMethod).getSymmetricKey()).build();
            } else {
                encryptedReply = EncryptionBuilder.withObject(signedReply).build();
            }
            final @Nonnull Response response = ResponseBuilder.withEncryption(encryptedReply).build();
            response.pack().storeTo(getSocket());
            Log.information(method + " from " + address + " handled in " + start.ago().getValue() + " ms.");
        } catch (@Nonnull NetworkException exception) {
            Log.warning("Could not send a response.", exception);
        } catch (@Nonnull Throwable throwable) {
            Log.warning("Something went wrong.", throwable);
        } finally {
            try {
                if (!getSocket().isClosed()) { getSocket().close(); }
            } catch (@Nonnull IOException exception) {
                Log.warning("Could not close the socket.", exception);
            }
        }
    }
@Override
    @Committing
    @PureWithSideEffects
    @SuppressWarnings("UseSpecificCatch")
    public void run() {
        try {
            final @Nonnull String address = getSocket().getInetAddress().getHostAddress();
            Log.debugging("Received a request from $.", address);
            final @Nonnull Time start = TimeBuilder.build();
            @Nullable Encryption<Signature<Compression<Pack>>> encryptedMethod = null;
            @Nullable Signature<Compression<Pack>> signedMethod = null;
            @Nullable Method<?> method = null;
            @Nullable Reply<?> reply = null;
            try {
                try {
                    final @Nonnull Pack pack = Pack.loadFrom(getSocket());
                    final @Nonnull Request request = pack.unpack(RequestConverter.INSTANCE, null);
                    encryptedMethod = request.getEncryption();
                    final @Nullable HostIdentifier recipient = encryptedMethod.getRecipient();
                    if (recipient == null) { throw RequestExceptionBuilder.withCode(RequestErrorCode.RECIPIENT).withMessage("The recipient may not be null.").build(); }
                    final @Nonnull Host host = Host.of(recipient);
                    signedMethod = encryptedMethod.getObject();
                    final @Nonnull SemanticType type = signedMethod.getObject().getObject().getType();
                    Log.debugging("Executing the method $ on host $.", type.getAddress(), recipient);
                    final @Nonnull InternalIdentifier subject;
                    if (type.equals(OpenAccount.TYPE)) { subject = recipient; } else { subject = signedMethod.getSubject(); }
                    final @Nonnull Account account = Account.with(host, subject.resolve());
                    method = MethodIndex.get(signedMethod, account);
                    reply = method.executeOnHost();
                    Database.commit();
                } catch (@Nonnull InternalException exception) {
                    throw RequestExceptionBuilder.withCode(RequestErrorCode.INTERNAL).withMessage("An internal problem occurred.").withCause(exception).build();
                } catch (@Nonnull ExternalException exception) {
                    throw RequestExceptionBuilder.withCode(RequestErrorCode.EXTERNAL).withMessage("An external problem occurred.").withCause(exception).build();
                }
            } catch (@Nonnull RequestException exception) {
                Database.rollback();
                Log.warning("A request error occurred:", exception);
                reply = RequestExceptionReplyBuilder.withRequestException(exception.isDecoded() ? RequestExceptionBuilder.withCode(RequestErrorCode.REQUEST).withMessage("Another server responded with a request error.").withCause(exception).build() : exception).build();
            }
            if (reply == null) { reply = EmptyReplyBuilder.build(); }
            final @Nonnull Compression<Pack> compressedReply = CompressionBuilder.withObject(reply.pack()).build();
           
            try { Database.commit(); } catch (@Nonnull DatabaseException exception) { Database.rollback(); }
            final @Nonnull Signature<Compression<Pack>> signedReply;
            if (encryptedMethod != null && signedMethod != null) {
                signedReply = HostSignatureCreator.sign(compressedReply, CompressionConverterBuilder.withObjectConverter(PackConverter.INSTANCE).build()).about(signedMethod.getSubject()).as(encryptedMethod.getRecipient());
            } else {
                signedReply = SignatureBuilder.withObjectConverter(CompressionConverterBuilder.withObjectConverter(PackConverter.INSTANCE).build()).withObject(compressedReply).withSubject(HostIdentifier.DIGITALID).build();
            }
            final @Nonnull Encryption<Signature<Compression<Pack>>> encryptedReply;
            if (encryptedMethod instanceof RequestEncryption) {
                encryptedReply = ResponseEncryptionBuilder.withObject(signedReply).withSymmetricKey(((RequestEncryption) encryptedMethod).getSymmetricKey()).build();
            } else {
                encryptedReply = EncryptionBuilder.withObject(signedReply).build();
            }
            final @Nonnull Response response = ResponseBuilder.withEncryption(encryptedReply).build();
            response.pack().storeTo(getSocket());
            Log.information(method + " from " + address + " handled in " + start.ago().getValue() + " ms.");
        } catch (@Nonnull NetworkException exception) {
            Log.warning("Could not send a response.", exception);
        } catch (@Nonnull Throwable throwable) {
            Log.warning("Something went wrong.", throwable);
        } finally {
            try {
                if (!getSocket().isClosed()) { getSocket().close(); }
            } catch (@Nonnull IOException exception) {
                Log.warning("Could not close the socket.", exception);
            }
        }
    }
@override @committing @purewithsideeffects @suppresswarnings("usespecificcatch") public void run() { try { final @nonnull string address = getsocket().getinetaddress().gethostaddress(); log.debugging("received a request from $.", address); final @nonnull time start = timebuilder.build(); @nullable encryption<signature<compression<pack>>> encryptedmethod = null; @nullable signature<compression<pack>> signedmethod = null; @nullable method<?> method = null; @nullable reply<?> reply = null; try { try { final @nonnull pack pack = pack.loadfrom(getsocket()); final @nonnull request request = pack.unpack(requestconverter.instance, null); encryptedmethod = request.getencryption(); final @nullable hostidentifier recipient = encryptedmethod.getrecipient(); if (recipient == null) { throw requestexceptionbuilder.withcode(requesterrorcode.recipient).withmessage("the recipient may not be null.").build(); } final @nonnull host host = host.of(recipient); signedmethod = encryptedmethod.getobject(); final @nonnull semantictype type = signedmethod.getobject().getobject().gettype(); log.debugging("executing the method $ on host $.", type.getaddress(), recipient); final @nonnull internalidentifier subject; if (type.equals(openaccount.type)) { subject = recipient; } else { subject = signedmethod.getsubject(); } final @nonnull account account = account.with(host, subject.resolve()); method = methodindex.get(signedmethod, account); reply = method.executeonhost(); database.commit(); } catch (@nonnull internalexception exception) { throw requestexceptionbuilder.withcode(requesterrorcode.internal).withmessage("an internal problem occurred.").withcause(exception).build(); } catch (@nonnull externalexception exception) { throw requestexceptionbuilder.withcode(requesterrorcode.external).withmessage("an external problem occurred.").withcause(exception).build(); } } catch (@nonnull requestexception exception) { database.rollback(); log.warning("a request error occurred:", exception); reply = requestexceptionreplybuilder.withrequestexception(exception.isdecoded() ? requestexceptionbuilder.withcode(requesterrorcode.request).withmessage("another server responded with a request error.").withcause(exception).build() : exception).build(); } if (reply == null) { reply = emptyreplybuilder.build(); } final @nonnull compression<pack> compressedreply = compressionbuilder.withobject(reply.pack()).build(); try { database.commit(); } catch (@nonnull databaseexception exception) { database.rollback(); } final @nonnull signature<compression<pack>> signedreply; if (encryptedmethod != null && signedmethod != null) { signedreply = hostsignaturecreator.sign(compressedreply, compressionconverterbuilder.withobjectconverter(packconverter.instance).build()).about(signedmethod.getsubject()).as(encryptedmethod.getrecipient()); } else { signedreply = signaturebuilder.withobjectconverter(compressionconverterbuilder.withobjectconverter(packconverter.instance).build()).withobject(compressedreply).withsubject(hostidentifier.digitalid).build(); } final @nonnull encryption<signature<compression<pack>>> encryptedreply; if (encryptedmethod instanceof requestencryption) { encryptedreply = responseencryptionbuilder.withobject(signedreply).withsymmetrickey(((requestencryption) encryptedmethod).getsymmetrickey()).build(); } else { encryptedreply = encryptionbuilder.withobject(signedreply).build(); } final @nonnull response response = responsebuilder.withencryption(encryptedreply).build(); response.pack().storeto(getsocket()); log.information(method + " from " + address + " handled in " + start.ago().getvalue() + " ms."); } catch (@nonnull networkexception exception) { log.warning("could not send a response.", exception); } catch (@nonnull throwable throwable) { log.warning("something went wrong.", throwable); } finally { try { if (!getsocket().isclosed()) { getsocket().close(); } } catch (@nonnull ioexception exception) { log.warning("could not close the socket.", exception); } } }