-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
jetty: Restore compatibility with jetty 12.0.7
jetty 12.0.7 introduced some backwards-incompatible changes that broke AFSocketClientConnector. Add support for a junixsocket-specific Transport implementation, and modify the jetty support code in a way that is both compatible with jetty 12.0.7 as well as backwards-compatible as before. jetty/jetty.project#11500
- Loading branch information
1 parent
db85ad0
commit f4cf74c
Showing
6 changed files
with
283 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
junixsocket-jetty/src/main/java/org/newsclub/net/unix/jetty/AFSocketConfigurator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
* junixsocket | ||
* | ||
* Copyright 2009-2023 Christian Kohlschütter | ||
* | ||
* 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. | ||
*/ | ||
package org.newsclub.net.unix.jetty; | ||
|
||
import java.io.IOException; | ||
import java.net.SocketAddress; | ||
import java.nio.channels.SocketChannel; | ||
import java.util.Map; | ||
|
||
import org.eclipse.jetty.io.ClientConnector; | ||
import org.eclipse.jetty.io.ClientConnector.Configurator; | ||
import org.newsclub.net.unix.AFSocketAddress; | ||
|
||
/** | ||
* A {@link ClientConnector.Configurator} for junixsocket {@link SocketChannel}s. | ||
* | ||
* @author Christian Kohlschütter | ||
*/ | ||
@Deprecated | ||
class AFSocketConfigurator extends Configurator { | ||
protected final AFSocketAddress addr; | ||
|
||
AFSocketConfigurator(AFSocketAddress addr) { | ||
super(); | ||
this.addr = addr; | ||
} | ||
|
||
@Override | ||
public ChannelWithAddress newChannelWithAddress(ClientConnector clientConnector, | ||
SocketAddress address, Map<String, Object> context) throws IOException { | ||
SocketChannel socketChannel = addr.getAddressFamily().newSocketChannel(); | ||
return new ChannelWithAddress(socketChannel, addr); | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
...et-jetty/src/main/java/org/newsclub/net/unix/jetty/AFSocketConfiguratorWithTransport.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* junixsocket | ||
* | ||
* Copyright 2009-2023 Christian Kohlschütter | ||
* | ||
* 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. | ||
*/ | ||
package org.newsclub.net.unix.jetty; | ||
|
||
import java.nio.channels.SocketChannel; | ||
|
||
import org.eclipse.jetty.io.ClientConnector; | ||
import org.eclipse.jetty.io.Transport; | ||
import org.newsclub.net.unix.AFSocketAddress; | ||
|
||
/** | ||
* A {@link ClientConnector.Configurator} for junixsocket {@link SocketChannel}s, as required by | ||
* jetty 12.0.7. | ||
* | ||
* @author Christian Kohlschütter | ||
*/ | ||
@Deprecated | ||
final class AFSocketConfiguratorWithTransport extends AFSocketConfigurator { | ||
AFSocketConfiguratorWithTransport(AFSocketAddress addr) { | ||
super(addr); | ||
} | ||
|
||
@Override | ||
public Transport newTransport() { | ||
return new AFSocketTransport.WithSocketChannel(addr); | ||
} | ||
} |
134 changes: 134 additions & 0 deletions
134
junixsocket-jetty/src/main/java/org/newsclub/net/unix/jetty/AFSocketTransport.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
/* | ||
* junixsocket | ||
* | ||
* Copyright 2009-2023 Christian Kohlschütter | ||
* | ||
* 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. | ||
*/ | ||
package org.newsclub.net.unix.jetty; | ||
|
||
import java.io.IOException; | ||
import java.nio.channels.DatagramChannel; | ||
import java.nio.channels.SelectableChannel; | ||
import java.nio.channels.SelectionKey; | ||
import java.nio.channels.SocketChannel; | ||
import java.util.Objects; | ||
|
||
import org.eclipse.jetty.io.DatagramChannelEndPoint; | ||
import org.eclipse.jetty.io.EndPoint; | ||
import org.eclipse.jetty.io.ManagedSelector; | ||
import org.eclipse.jetty.io.SocketChannelEndPoint; | ||
import org.eclipse.jetty.io.Transport; | ||
import org.eclipse.jetty.util.thread.Scheduler; | ||
import org.newsclub.net.unix.AFSocketAddress; | ||
|
||
/** | ||
* A {@link Transport} implementation for junixsocket socket and datagram channels (Unix domains | ||
* etc.) | ||
* <p> | ||
* This implementation should work with jetty version 12.0.7 or newer. | ||
* | ||
* @author Christian Kohlschütter | ||
*/ | ||
public class AFSocketTransport extends Transport.Socket { | ||
private final AFSocketAddress socketAddress; | ||
|
||
private AFSocketTransport(AFSocketAddress socketAddress) { | ||
super(); | ||
this.socketAddress = socketAddress; | ||
} | ||
|
||
/** | ||
* Constructs an {@link AFSocketTransport} that establishes a {@link SocketChannel} to the given | ||
* address. | ||
* | ||
* @param addr The target address. | ||
* @return The {@link Transport} instance. | ||
*/ | ||
public static AFSocketTransport withSocketChannel(AFSocketAddress addr) { | ||
return new WithSocketChannel(addr); | ||
} | ||
|
||
/** | ||
* Constructs an {@link AFSocketTransport} that establishes a {@link DatagramChannel} to the given | ||
* address. | ||
* | ||
* @param addr The target address. | ||
* @return The {@link Transport} instance. | ||
*/ | ||
public static AFSocketTransport withDatagramChannel(AFSocketAddress addr) { | ||
return new WithDatagramChannel(addr); | ||
} | ||
|
||
@Override | ||
public AFSocketAddress getSocketAddress() { | ||
return socketAddress; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(socketAddress); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object obj) { | ||
if (this == obj) { | ||
return true; | ||
} | ||
if (obj instanceof AFSocketTransport) { | ||
return Objects.equals(socketAddress, ((AFSocketTransport) obj).socketAddress); | ||
} | ||
return false; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return super.toString() + "[" + socketAddress.toString() + "]"; | ||
} | ||
|
||
static class WithSocketChannel extends AFSocketTransport { | ||
public WithSocketChannel(AFSocketAddress address) { | ||
super(address); | ||
} | ||
|
||
@Override | ||
public SelectableChannel newSelectableChannel() throws IOException { | ||
return getSocketAddress().getAddressFamily().getSelectorProvider().openSocketChannel(); | ||
} | ||
|
||
@Override | ||
public EndPoint newEndPoint(Scheduler scheduler, ManagedSelector selector, | ||
SelectableChannel selectable, SelectionKey selectionKey) { | ||
return new SocketChannelEndPoint((SocketChannel) selectable, selector, selectionKey, | ||
scheduler); | ||
} | ||
} | ||
|
||
static class WithDatagramChannel extends AFSocketTransport { | ||
public WithDatagramChannel(AFSocketAddress address) { | ||
super(address); | ||
} | ||
|
||
@Override | ||
public SelectableChannel newSelectableChannel() throws IOException { | ||
return getSocketAddress().getAddressFamily().getSelectorProvider().openDatagramChannel(); | ||
} | ||
|
||
@Override | ||
public EndPoint newEndPoint(Scheduler scheduler, ManagedSelector selector, | ||
SelectableChannel selectable, SelectionKey selectionKey) { | ||
return new DatagramChannelEndPoint((DatagramChannel) selectable, selector, selectionKey, | ||
scheduler); | ||
} | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
junixsocket-jetty/src/main/java/org/newsclub/net/unix/jetty/JettyCompat.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
* junixsocket | ||
* | ||
* Copyright 2009-2023 Christian Kohlschütter | ||
* | ||
* 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. | ||
*/ | ||
package org.newsclub.net.unix.jetty; | ||
|
||
final class JettyCompat { | ||
private static final boolean HAVE_TRANSPORT_CLASS; | ||
|
||
static { | ||
boolean found; | ||
try { | ||
Class.forName("org.eclipse.jetty.io.Transport"); | ||
found = true; | ||
} catch (Exception e) { // NOPMD | ||
found = false; | ||
} | ||
HAVE_TRANSPORT_CLASS = found; | ||
} | ||
|
||
private JettyCompat() { | ||
throw new IllegalStateException("No instances"); | ||
} | ||
|
||
static boolean hasTransportClass() { | ||
return HAVE_TRANSPORT_CLASS; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters