diff --git a/rapidoid-net/src/main/java/org/rapidoid/net/abstracts/Channel.java b/rapidoid-net/src/main/java/org/rapidoid/net/abstracts/Channel.java index dc5acb209e..66a84add92 100644 --- a/rapidoid-net/src/main/java/org/rapidoid/net/abstracts/Channel.java +++ b/rapidoid-net/src/main/java/org/rapidoid/net/abstracts/Channel.java @@ -25,6 +25,6 @@ @Authors("Nikolche Mihajlovski") @Since("2.0.0") -public interface Channel extends CtxFull { +public interface Channel extends ProtocolContext { } diff --git a/rapidoid-net/src/main/java/org/rapidoid/net/abstracts/CtxConnection.java b/rapidoid-net/src/main/java/org/rapidoid/net/abstracts/CtxConnection.java deleted file mode 100644 index 6af3727e1b..0000000000 --- a/rapidoid-net/src/main/java/org/rapidoid/net/abstracts/CtxConnection.java +++ /dev/null @@ -1,52 +0,0 @@ -package org.rapidoid.net.abstracts; - -/* - * #%L - * rapidoid-net - * %% - * Copyright (C) 2014 - 2015 Nikolche Mihajlovski and contributors - * %% - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * #L% - */ - -import java.net.InetSocketAddress; - -import org.rapidoid.annotation.Authors; -import org.rapidoid.annotation.Since; - -@Authors("Nikolche Mihajlovski") -@Since("2.0.0") -public interface CtxConnection { - - String address(); - - InetSocketAddress getAddress(); - - long connId(); - - boolean isAsync(); - - T close(); - - T closeIf(boolean condition); - - boolean isClosing(); - - boolean isClosed(); - - void waitUntilClosing(); - - void log(String msg); - -} diff --git a/rapidoid-net/src/main/java/org/rapidoid/net/abstracts/CtxFull.java b/rapidoid-net/src/main/java/org/rapidoid/net/abstracts/CtxFull.java deleted file mode 100644 index 2201e694be..0000000000 --- a/rapidoid-net/src/main/java/org/rapidoid/net/abstracts/CtxFull.java +++ /dev/null @@ -1,32 +0,0 @@ -package org.rapidoid.net.abstracts; - -import org.rapidoid.annotation.Authors; -import org.rapidoid.annotation.Since; - -/* - * #%L - * rapidoid-net - * %% - * Copyright (C) 2014 - 2015 Nikolche Mihajlovski and contributors - * %% - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * #L% - */ - -@Authors("Nikolche Mihajlovski") -@Since("2.0.0") -public interface CtxFull extends CtxWrite, CtxRead, CtxConnection, CtxIO, CtxProtocol, CtxState { - -

P persistor(); - -} diff --git a/rapidoid-net/src/main/java/org/rapidoid/net/abstracts/CtxIO.java b/rapidoid-net/src/main/java/org/rapidoid/net/abstracts/CtxIO.java deleted file mode 100644 index c7dee0c8f0..0000000000 --- a/rapidoid-net/src/main/java/org/rapidoid/net/abstracts/CtxIO.java +++ /dev/null @@ -1,38 +0,0 @@ -package org.rapidoid.net.abstracts; - -/* - * #%L - * rapidoid-net - * %% - * Copyright (C) 2014 - 2015 Nikolche Mihajlovski and contributors - * %% - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * #L% - */ - -import org.rapidoid.annotation.Authors; -import org.rapidoid.annotation.Since; -import org.rapidoid.buffer.Buf; -import org.rapidoid.net.impl.RapidoidHelper; - -@Authors("Nikolche Mihajlovski") -@Since("2.0.0") -public interface CtxIO { - - Buf input(); - - Buf output(); - - RapidoidHelper helper(); - -} diff --git a/rapidoid-net/src/main/java/org/rapidoid/net/abstracts/CtxProtocol.java b/rapidoid-net/src/main/java/org/rapidoid/net/abstracts/CtxProtocol.java deleted file mode 100644 index 36b428200e..0000000000 --- a/rapidoid-net/src/main/java/org/rapidoid/net/abstracts/CtxProtocol.java +++ /dev/null @@ -1,32 +0,0 @@ -package org.rapidoid.net.abstracts; - -import org.rapidoid.annotation.Authors; -import org.rapidoid.annotation.Since; - -/* - * #%L - * rapidoid-net - * %% - * Copyright (C) 2014 - 2015 Nikolche Mihajlovski and contributors - * %% - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * #L% - */ - -@Authors("Nikolche Mihajlovski") -@Since("2.0.0") -public interface CtxProtocol { - - boolean isInitial(); - -} diff --git a/rapidoid-net/src/main/java/org/rapidoid/net/abstracts/CtxRead.java b/rapidoid-net/src/main/java/org/rapidoid/net/abstracts/CtxRead.java deleted file mode 100644 index 0c609cb058..0000000000 --- a/rapidoid-net/src/main/java/org/rapidoid/net/abstracts/CtxRead.java +++ /dev/null @@ -1,34 +0,0 @@ -package org.rapidoid.net.abstracts; - -import org.rapidoid.annotation.Authors; -import org.rapidoid.annotation.Since; - -/* - * #%L - * rapidoid-net - * %% - * Copyright (C) 2014 - 2015 Nikolche Mihajlovski and contributors - * %% - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * #L% - */ - -@Authors("Nikolche Mihajlovski") -@Since("2.0.0") -public interface CtxRead { - - String readln(); - - String readN(int count); - -} diff --git a/rapidoid-net/src/main/java/org/rapidoid/net/abstracts/CtxState.java b/rapidoid-net/src/main/java/org/rapidoid/net/abstracts/CtxState.java deleted file mode 100644 index 0db0a1ca18..0000000000 --- a/rapidoid-net/src/main/java/org/rapidoid/net/abstracts/CtxState.java +++ /dev/null @@ -1,33 +0,0 @@ -package org.rapidoid.net.abstracts; - -/* - * #%L - * rapidoid-net - * %% - * Copyright (C) 2014 - 2015 Nikolche Mihajlovski and contributors - * %% - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * #L% - */ - -import org.rapidoid.annotation.Authors; -import org.rapidoid.annotation.Since; -import org.rapidoid.net.impl.ConnState; - -@Authors("Nikolche Mihajlovski") -@Since("2.0.0") -public interface CtxState { - - ConnState state(); - -} diff --git a/rapidoid-net/src/main/java/org/rapidoid/net/abstracts/CtxWrite.java b/rapidoid-net/src/main/java/org/rapidoid/net/abstracts/ProtocolContext.java similarity index 63% rename from rapidoid-net/src/main/java/org/rapidoid/net/abstracts/CtxWrite.java rename to rapidoid-net/src/main/java/org/rapidoid/net/abstracts/ProtocolContext.java index 84731877f6..0989c7f26f 100644 --- a/rapidoid-net/src/main/java/org/rapidoid/net/abstracts/CtxWrite.java +++ b/rapidoid-net/src/main/java/org/rapidoid/net/abstracts/ProtocolContext.java @@ -1,5 +1,15 @@ package org.rapidoid.net.abstracts; +import java.io.File; +import java.net.InetSocketAddress; +import java.nio.ByteBuffer; + +import org.rapidoid.annotation.Authors; +import org.rapidoid.annotation.Since; +import org.rapidoid.buffer.Buf; +import org.rapidoid.net.impl.ConnState; +import org.rapidoid.net.impl.RapidoidHelper; + /* * #%L * rapidoid-net @@ -20,15 +30,37 @@ * #L% */ -import java.io.File; -import java.nio.ByteBuffer; - -import org.rapidoid.annotation.Authors; -import org.rapidoid.annotation.Since; - @Authors("Nikolche Mihajlovski") @Since("2.0.0") -public interface CtxWrite { +public interface ProtocolContext { + + /* CONNECTION */ + + String address(); + + InetSocketAddress getAddress(); + + long connId(); + + boolean isAsync(); + + T close(); + + T closeIf(boolean condition); + + boolean isClosing(); + + boolean isClosed(); + + void waitUntilClosing(); + + void log(String msg); + + /* PROTOCOL */ + + boolean isInitial(); + + /* WRITE */ T write(String s); @@ -46,9 +78,31 @@ public interface CtxWrite { T send(); + /* ASYNC */ + // due to async() web handling option, it ain't over till the fat lady sings "done" T async(); T done(); + /* READ */ + + String readln(); + + String readN(int count); + + /* IO */ + + Buf input(); + + Buf output(); + + RapidoidHelper helper(); + + /* EXTRAS */ + + ConnState state(); + +

P persistor(); + } diff --git a/rapidoid-net/src/main/java/org/rapidoid/net/impl/DefaultExchange.java b/rapidoid-net/src/main/java/org/rapidoid/net/impl/DefaultExchange.java index 44753a306e..42e43a7e13 100644 --- a/rapidoid-net/src/main/java/org/rapidoid/net/impl/DefaultExchange.java +++ b/rapidoid-net/src/main/java/org/rapidoid/net/impl/DefaultExchange.java @@ -36,14 +36,14 @@ import org.rapidoid.data.MultiData; import org.rapidoid.data.Range; import org.rapidoid.net.abstracts.Channel; -import org.rapidoid.net.abstracts.CtxFull; +import org.rapidoid.net.abstracts.ProtocolContext; import org.rapidoid.util.Constants; import org.rapidoid.util.Resetable; import org.rapidoid.util.U; @Authors("Nikolche Mihajlovski") @Since("2.0.0") -public abstract class DefaultExchange implements CtxFull, BufProvider, Resetable, Constants { +public abstract class DefaultExchange implements ProtocolContext, BufProvider, Resetable, Constants { protected Channel conn; diff --git a/rapidoid-x-net/src/main/java/org/rapidoidx/net/TCPClientBuilder.java b/rapidoid-x-net/src/main/java/org/rapidoidx/net/TCPClientBuilder.java index 9ec84184af..8d1b500dca 100644 --- a/rapidoid-x-net/src/main/java/org/rapidoidx/net/TCPClientBuilder.java +++ b/rapidoid-x-net/src/main/java/org/rapidoidx/net/TCPClientBuilder.java @@ -51,7 +51,7 @@ public interface TCPClientBuilder extends Builder { TCPClientBuilder protocol(Protocol protocol); - TCPClientBuilder exchange(Class> exchangeClass); + TCPClientBuilder exchange(Class> exchangeClass); TCPClientBuilder helper(Class helperClass); diff --git a/rapidoid-x-net/src/main/java/org/rapidoidx/net/TCPServerBuilder.java b/rapidoid-x-net/src/main/java/org/rapidoidx/net/TCPServerBuilder.java index 1e789ce9e1..9e9d55809d 100644 --- a/rapidoid-x-net/src/main/java/org/rapidoidx/net/TCPServerBuilder.java +++ b/rapidoid-x-net/src/main/java/org/rapidoidx/net/TCPServerBuilder.java @@ -45,7 +45,7 @@ public interface TCPServerBuilder extends Builder { TCPServerBuilder protocol(Protocol protocol); - TCPServerBuilder exchange(Class> exchangeClass); + TCPServerBuilder exchange(Class> exchangeClass); TCPServerBuilder helper(Class helperClass); diff --git a/rapidoid-x-net/src/main/java/org/rapidoidx/net/abstracts/Channel.java b/rapidoid-x-net/src/main/java/org/rapidoidx/net/abstracts/Channel.java index 20baa7468c..944931cbff 100644 --- a/rapidoid-x-net/src/main/java/org/rapidoidx/net/abstracts/Channel.java +++ b/rapidoid-x-net/src/main/java/org/rapidoidx/net/abstracts/Channel.java @@ -26,6 +26,6 @@ @Authors("Nikolche Mihajlovski") @Since("3.0.0") -public interface Channel extends CtxFull { +public interface Channel extends ProtocolContext { } diff --git a/rapidoid-x-net/src/main/java/org/rapidoidx/net/abstracts/CtxConnection.java b/rapidoid-x-net/src/main/java/org/rapidoidx/net/abstracts/CtxConnection.java deleted file mode 100644 index 28743391f4..0000000000 --- a/rapidoid-x-net/src/main/java/org/rapidoidx/net/abstracts/CtxConnection.java +++ /dev/null @@ -1,53 +0,0 @@ -package org.rapidoidx.net.abstracts; - -/* - * #%L - * rapidoid-x-net - * %% - * Copyright (C) 2014 - 2015 Nikolche Mihajlovski and contributors - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - * #L% - */ - -import java.net.InetSocketAddress; - -import org.rapidoid.annotation.Authors; -import org.rapidoid.annotation.Since; - -@Authors("Nikolche Mihajlovski") -@Since("3.0.0") -public interface CtxConnection { - - String address(); - - InetSocketAddress getAddress(); - - long connId(); - - boolean isAsync(); - - T close(); - - T closeIf(boolean condition); - - boolean isClosing(); - - boolean isClosed(); - - void waitUntilClosing(); - - void log(String msg); - -} diff --git a/rapidoid-x-net/src/main/java/org/rapidoidx/net/abstracts/CtxFull.java b/rapidoid-x-net/src/main/java/org/rapidoidx/net/abstracts/CtxFull.java deleted file mode 100644 index a9a7642bdf..0000000000 --- a/rapidoid-x-net/src/main/java/org/rapidoidx/net/abstracts/CtxFull.java +++ /dev/null @@ -1,31 +0,0 @@ -package org.rapidoidx.net.abstracts; - -import org.rapidoid.annotation.Authors; -import org.rapidoid.annotation.Since; - -/* - * #%L - * rapidoid-x-net - * %% - * Copyright (C) 2014 - 2015 Nikolche Mihajlovski and contributors - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - * #L% - */ - -@Authors("Nikolche Mihajlovski") -@Since("3.0.0") -public interface CtxFull extends CtxWrite, CtxRead, CtxConnection, CtxIO, CtxProtocol, CtxState { - -} diff --git a/rapidoid-x-net/src/main/java/org/rapidoidx/net/abstracts/CtxIO.java b/rapidoid-x-net/src/main/java/org/rapidoidx/net/abstracts/CtxIO.java deleted file mode 100644 index d458ed5279..0000000000 --- a/rapidoid-x-net/src/main/java/org/rapidoidx/net/abstracts/CtxIO.java +++ /dev/null @@ -1,39 +0,0 @@ -package org.rapidoidx.net.abstracts; - -/* - * #%L - * rapidoid-x-net - * %% - * Copyright (C) 2014 - 2015 Nikolche Mihajlovski and contributors - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - * #L% - */ - -import org.rapidoid.annotation.Authors; -import org.rapidoid.annotation.Since; -import org.rapidoidx.buffer.Buf; -import org.rapidoidx.net.impl.RapidoidHelper; - -@Authors("Nikolche Mihajlovski") -@Since("3.0.0") -public interface CtxIO { - - Buf input(); - - Buf output(); - - RapidoidHelper helper(); - -} diff --git a/rapidoid-x-net/src/main/java/org/rapidoidx/net/abstracts/CtxProtocol.java b/rapidoid-x-net/src/main/java/org/rapidoidx/net/abstracts/CtxProtocol.java deleted file mode 100644 index c256da1bea..0000000000 --- a/rapidoid-x-net/src/main/java/org/rapidoidx/net/abstracts/CtxProtocol.java +++ /dev/null @@ -1,35 +0,0 @@ -package org.rapidoidx.net.abstracts; - -import org.rapidoid.annotation.Authors; -import org.rapidoid.annotation.Since; - -/* - * #%L - * rapidoid-x-net - * %% - * Copyright (C) 2014 - 2015 Nikolche Mihajlovski and contributors - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - * #L% - */ - -@Authors("Nikolche Mihajlovski") -@Since("3.0.0") -public interface CtxProtocol { - - boolean isInitial(); - - T restart(); - -} diff --git a/rapidoid-x-net/src/main/java/org/rapidoidx/net/abstracts/CtxRead.java b/rapidoid-x-net/src/main/java/org/rapidoidx/net/abstracts/CtxRead.java deleted file mode 100644 index d95527a801..0000000000 --- a/rapidoid-x-net/src/main/java/org/rapidoidx/net/abstracts/CtxRead.java +++ /dev/null @@ -1,35 +0,0 @@ -package org.rapidoidx.net.abstracts; - -import org.rapidoid.annotation.Authors; -import org.rapidoid.annotation.Since; - -/* - * #%L - * rapidoid-x-net - * %% - * Copyright (C) 2014 - 2015 Nikolche Mihajlovski and contributors - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - * #L% - */ - -@Authors("Nikolche Mihajlovski") -@Since("3.0.0") -public interface CtxRead { - - String readln(); - - String readN(int count); - -} diff --git a/rapidoid-x-net/src/main/java/org/rapidoidx/net/abstracts/CtxState.java b/rapidoid-x-net/src/main/java/org/rapidoidx/net/abstracts/CtxState.java deleted file mode 100644 index 2509aea439..0000000000 --- a/rapidoid-x-net/src/main/java/org/rapidoidx/net/abstracts/CtxState.java +++ /dev/null @@ -1,36 +0,0 @@ -package org.rapidoidx.net.abstracts; - -/* - * #%L - * rapidoid-x-net - * %% - * Copyright (C) 2014 - 2015 Nikolche Mihajlovski and contributors - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - * #L% - */ - -import org.rapidoid.annotation.Authors; -import org.rapidoid.annotation.Since; -import org.rapidoidx.net.impl.ConnState; - -@Authors("Nikolche Mihajlovski") -@Since("3.0.0") -public interface CtxState { - - ConnState state(); - - ChannelHolder createHolder(); - -} diff --git a/rapidoid-x-net/src/main/java/org/rapidoidx/net/abstracts/CtxWrite.java b/rapidoid-x-net/src/main/java/org/rapidoidx/net/abstracts/ProtocolContext.java similarity index 63% rename from rapidoid-x-net/src/main/java/org/rapidoidx/net/abstracts/CtxWrite.java rename to rapidoid-x-net/src/main/java/org/rapidoidx/net/abstracts/ProtocolContext.java index 5abc1ee5a4..59a62338ef 100644 --- a/rapidoid-x-net/src/main/java/org/rapidoidx/net/abstracts/CtxWrite.java +++ b/rapidoid-x-net/src/main/java/org/rapidoidx/net/abstracts/ProtocolContext.java @@ -1,5 +1,15 @@ package org.rapidoidx.net.abstracts; +import java.io.File; +import java.net.InetSocketAddress; +import java.nio.ByteBuffer; + +import org.rapidoid.annotation.Authors; +import org.rapidoid.annotation.Since; +import org.rapidoidx.buffer.Buf; +import org.rapidoidx.net.impl.ConnState; +import org.rapidoidx.net.impl.RapidoidHelper; + /* * #%L * rapidoid-x-net @@ -21,15 +31,39 @@ * #L% */ -import java.io.File; -import java.nio.ByteBuffer; - -import org.rapidoid.annotation.Authors; -import org.rapidoid.annotation.Since; - @Authors("Nikolche Mihajlovski") @Since("3.0.0") -public interface CtxWrite { +public interface ProtocolContext { + + /* CONNECTION */ + + String address(); + + InetSocketAddress getAddress(); + + long connId(); + + boolean isAsync(); + + T close(); + + T closeIf(boolean condition); + + boolean isClosing(); + + boolean isClosed(); + + void waitUntilClosing(); + + void log(String msg); + + /* PROTOCOL */ + + boolean isInitial(); + + T restart(); // X-specific + + /* WRITE */ T write(String s); @@ -47,9 +81,31 @@ public interface CtxWrite { T send(); + /* ASYNC */ + // due to async() web handling option, it ain't over till the fat lady sings "done" T async(); T done(); + /* READ */ + + String readln(); + + String readN(int count); + + /* IO */ + + Buf input(); + + Buf output(); + + RapidoidHelper helper(); + + /* EXTRAS */ + + ConnState state(); + + ChannelHolder createHolder(); // X-specific + } diff --git a/rapidoid-x-net/src/main/java/org/rapidoidx/net/impl/DefaultExchange.java b/rapidoid-x-net/src/main/java/org/rapidoidx/net/impl/DefaultExchange.java index 91211e28ae..cdffac8f97 100644 --- a/rapidoid-x-net/src/main/java/org/rapidoidx/net/impl/DefaultExchange.java +++ b/rapidoid-x-net/src/main/java/org/rapidoidx/net/impl/DefaultExchange.java @@ -40,11 +40,11 @@ import org.rapidoidx.data.Range; import org.rapidoidx.net.abstracts.Channel; import org.rapidoidx.net.abstracts.ChannelHolder; -import org.rapidoidx.net.abstracts.CtxFull; +import org.rapidoidx.net.abstracts.ProtocolContext; @Authors("Nikolche Mihajlovski") @Since("3.0.0") -public abstract class DefaultExchange implements CtxFull, BufProvider, Resetable, Constants { +public abstract class DefaultExchange implements ProtocolContext, BufProvider, Resetable, Constants { protected Channel conn; @@ -66,14 +66,14 @@ public String address() { } @Override - public W write(String s) { + public T write(String s) { byte[] bytes = s.getBytes(); conn.write(bytes); return wrote(bytes.length); } @Override - public W writeln(String s) { + public T writeln(String s) { byte[] bytes = s.getBytes(); conn.write(bytes); conn.write(CR_LF); @@ -81,26 +81,26 @@ public W writeln(String s) { } @Override - public W write(byte[] bytes) { + public T write(byte[] bytes) { conn.write(bytes); return wrote(bytes.length); } @Override - public W write(byte[] bytes, int offset, int length) { + public T write(byte[] bytes, int offset, int length) { conn.write(bytes, offset, length); return wrote(length); } @Override - public W write(ByteBuffer buf) { + public T write(ByteBuffer buf) { int n = buf.remaining(); conn.write(buf); return wrote(n); } @Override - public W write(File file) { + public T write(File file) { long size = file.length(); U.must(size < Integer.MAX_VALUE); conn.write(file); @@ -108,26 +108,26 @@ public W write(File file) { } @Override - public W writeJSON(Object value) { + public T writeJSON(Object value) { conn.writeJSON(value); - return meW(); + return me(); } - private W wrote(int count) { + private T wrote(int count) { totalWritten.addAndGet(count); - return meW(); + return me(); } @Override public T close() { conn.close(); - return meT(); + return me(); } @Override public T closeIf(boolean condition) { conn.closeIf(condition); - return meT(); + return me(); } @Override @@ -193,13 +193,13 @@ public long getTotalWritten() { @Override public T restart() { conn.restart(); - return meT(); + return me(); } @Override - public W async() { + public T async() { conn.async(); - return meW(); + return me(); } @Override @@ -208,14 +208,14 @@ public boolean isAsync() { } @Override - public W done() { + public T done() { conn.done(); - return meW(); + return me(); } - public W send() { + public T send() { conn.send(); - return meW(); + return me(); } @Override @@ -254,13 +254,8 @@ public ChannelHolder createHolder() { } @SuppressWarnings("unchecked") - protected T meT() { + protected T me() { return (T) this; } - @SuppressWarnings("unchecked") - protected W meW() { - return (W) this; - } - } diff --git a/rapidoid-x-net/src/main/java/org/rapidoidx/net/impl/ExchangeProtocol.java b/rapidoid-x-net/src/main/java/org/rapidoidx/net/impl/ExchangeProtocol.java index cafdb906a0..f272216185 100644 --- a/rapidoid-x-net/src/main/java/org/rapidoidx/net/impl/ExchangeProtocol.java +++ b/rapidoid-x-net/src/main/java/org/rapidoidx/net/impl/ExchangeProtocol.java @@ -31,7 +31,7 @@ @Authors("Nikolche Mihajlovski") @Since("3.0.0") -public abstract class ExchangeProtocol> implements Protocol, CtxListener { +public abstract class ExchangeProtocol> implements Protocol, CtxListener { private final Class exchangeType; diff --git a/rapidoid-x-net/src/main/java/org/rapidoidx/net/impl/RapidoidClientLoop.java b/rapidoid-x-net/src/main/java/org/rapidoidx/net/impl/RapidoidClientLoop.java index fc25017e51..dc508ca9ad 100644 --- a/rapidoid-x-net/src/main/java/org/rapidoidx/net/impl/RapidoidClientLoop.java +++ b/rapidoid-x-net/src/main/java/org/rapidoidx/net/impl/RapidoidClientLoop.java @@ -69,12 +69,12 @@ public class RapidoidClientLoop extends AbstractEventLoop implements private final Class helperClass; - private final Class> exchangeClass; + private final Class> exchangeClass; // round-robin workers for new connections private int currentWorkerInd = 0; - public RapidoidClientLoop(Protocol protocol, Class> exchangeClass, + public RapidoidClientLoop(Protocol protocol, Class> exchangeClass, Class helperClass) { super("client"); diff --git a/rapidoid-x-net/src/main/java/org/rapidoidx/net/impl/RapidoidServerLoop.java b/rapidoid-x-net/src/main/java/org/rapidoidx/net/impl/RapidoidServerLoop.java index cd9d2cd7fe..d2828b95e4 100644 --- a/rapidoid-x-net/src/main/java/org/rapidoidx/net/impl/RapidoidServerLoop.java +++ b/rapidoid-x-net/src/main/java/org/rapidoidx/net/impl/RapidoidServerLoop.java @@ -65,11 +65,11 @@ public class RapidoidServerLoop extends AbstractEventLoop implements private final Class helperClass; - private final Class> exchangeClass; + private final Class> exchangeClass; private ServerSocketChannel serverSocketChannel; - public RapidoidServerLoop(Protocol protocol, Class> exchangeClass, + public RapidoidServerLoop(Protocol protocol, Class> exchangeClass, Class helperClass) { super("server"); this.protocol = protocol;