-
Notifications
You must be signed in to change notification settings - Fork 926
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #172 from trustin/content_streaming
HTTP/2 content streaming
- Loading branch information
Showing
343 changed files
with
20,999 additions
and
13,483 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
REVIEWBOARD_URL = 'https://rbcommons.com/s/armeria/' | ||
REPOSITORY = 'armeria' | ||
|
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
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,9 @@ | ||
Licensed under Public Domain (CC0) | ||
|
||
To the extent possible under law, the person who associated CC0 with | ||
this code has waived all copyright and related or neighboring | ||
rights to this code. | ||
|
||
You should have received a copy of the CC0 legalcode along with this | ||
work. If not, see <http://creativecommons.org/publicdomain/zero/1.0/>. | ||
|
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
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
82 changes: 82 additions & 0 deletions
82
src/main/java/com/linecorp/armeria/client/AbstractClientFactory.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,82 @@ | ||
/* | ||
* Copyright 2016 LINE Corporation | ||
* | ||
* LINE Corporation licenses this file to you 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 com.linecorp.armeria.client; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
|
||
import java.net.URI; | ||
import java.util.Optional; | ||
import java.util.Set; | ||
|
||
import com.linecorp.armeria.common.Scheme; | ||
|
||
public abstract class AbstractClientFactory implements ClientFactory { | ||
|
||
protected AbstractClientFactory() {} | ||
|
||
@Override | ||
public final <T> T newClient(String uri, Class<T> clientType, ClientOptionValue<?>... options) { | ||
requireNonNull(uri, "uri"); | ||
requireNonNull(options, "options"); | ||
return newClient(URI.create(uri), clientType, ClientOptions.of(options)); | ||
} | ||
|
||
@Override | ||
public final <T> T newClient(String uri, Class<T> clientType, ClientOptions options) { | ||
requireNonNull(uri, "uri"); | ||
return newClient(URI.create(uri), clientType, options); | ||
} | ||
|
||
@Override | ||
public final <T> T newClient(URI uri, Class<T> clientType, ClientOptionValue<?>... options) { | ||
requireNonNull(options, "options"); | ||
return newClient(uri, clientType, ClientOptions.of(options)); | ||
} | ||
|
||
protected final Scheme validate(URI uri, Class<?> clientType, ClientOptions options) { | ||
requireNonNull(uri, "uri"); | ||
requireNonNull(clientType, "clientType"); | ||
requireNonNull(options, "options"); | ||
|
||
final String scheme = uri.getScheme(); | ||
if (scheme == null) { | ||
throw new IllegalArgumentException("URI with missing scheme: " + uri); | ||
} | ||
|
||
if (uri.getAuthority() == null) { | ||
throw new IllegalArgumentException("URI with missing authority: " + uri); | ||
} | ||
|
||
final Optional<Scheme> parsedSchemeOpt = Scheme.tryParse(scheme); | ||
if (!parsedSchemeOpt.isPresent()) { | ||
throw new IllegalArgumentException("URI with unknown scheme: " + uri); | ||
} | ||
|
||
final Scheme parsedScheme = parsedSchemeOpt.get(); | ||
final Set<Scheme> supportedSchemes = supportedSchemes(); | ||
if (!supportedSchemes.contains(parsedScheme)) { | ||
throw new IllegalArgumentException( | ||
"URI with unsupported scheme: " + uri + " (expected: " + supportedSchemes + ')'); | ||
} | ||
|
||
return parsedScheme; | ||
} | ||
|
||
protected static Endpoint newEndpoint(URI uri) { | ||
return Endpoint.parse(uri.getAuthority()); | ||
} | ||
} |
110 changes: 110 additions & 0 deletions
110
src/main/java/com/linecorp/armeria/client/AllInOneClientFactory.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,110 @@ | ||
/* | ||
* Copyright 2016 LINE Corporation | ||
* | ||
* LINE Corporation licenses this file to you 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 com.linecorp.armeria.client; | ||
|
||
import java.net.URI; | ||
import java.util.Arrays; | ||
import java.util.Map; | ||
import java.util.Set; | ||
import java.util.function.Supplier; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import com.google.common.collect.ImmutableMap; | ||
|
||
import com.linecorp.armeria.client.http.HttpClientFactory; | ||
import com.linecorp.armeria.client.thrift.ThriftClientFactory; | ||
import com.linecorp.armeria.common.Scheme; | ||
|
||
import io.netty.channel.EventLoop; | ||
import io.netty.channel.EventLoopGroup; | ||
|
||
public class AllInOneClientFactory extends AbstractClientFactory { | ||
|
||
private static final Logger logger = LoggerFactory.getLogger(AllInOneClientFactory.class); | ||
|
||
static { | ||
if (AllInOneClientFactory.class.getClassLoader() == ClassLoader.getSystemClassLoader()) { | ||
Runtime.getRuntime().addShutdownHook(new Thread(ClientFactory::closeDefault)); | ||
} | ||
} | ||
|
||
private final ClientFactory mainFactory; | ||
private final Map<Scheme, ClientFactory> clientFactories; | ||
|
||
public AllInOneClientFactory() { | ||
this(SessionOptions.DEFAULT); | ||
} | ||
|
||
public AllInOneClientFactory(SessionOptions options) { | ||
// TODO(trustin): Allow specifying different options for different session protocols. | ||
// We have only one session protocol at the moment, so this is OK so far. | ||
final HttpClientFactory httpClientFactory = new HttpClientFactory(options); | ||
final ThriftClientFactory thriftClientFactory = new ThriftClientFactory(httpClientFactory); | ||
|
||
final ImmutableMap.Builder<Scheme, ClientFactory> builder = ImmutableMap.builder(); | ||
for (ClientFactory f : Arrays.asList(httpClientFactory, thriftClientFactory)) { | ||
f.supportedSchemes().forEach(s -> builder.put(s, f)); | ||
} | ||
|
||
clientFactories = builder.build(); | ||
mainFactory = httpClientFactory; | ||
} | ||
|
||
@Override | ||
public Set<Scheme> supportedSchemes() { | ||
return clientFactories.keySet(); | ||
} | ||
|
||
@Override | ||
public SessionOptions options() { | ||
return mainFactory.options(); | ||
} | ||
|
||
@Override | ||
public EventLoopGroup eventLoopGroup() { | ||
return mainFactory.eventLoopGroup(); | ||
} | ||
|
||
@Override | ||
public Supplier<EventLoop> eventLoopSupplier() { | ||
return mainFactory.eventLoopSupplier(); | ||
} | ||
|
||
@Override | ||
public <T> T newClient(URI uri, Class<T> clientType, ClientOptions options) { | ||
final Scheme scheme = validate(uri, clientType, options); | ||
return clientFactories.get(scheme).newClient(uri, clientType, options); | ||
} | ||
|
||
@Override | ||
public void close() { | ||
// The global default should never be closed. | ||
if (this == ClientFactory.DEFAULT) { | ||
logger.debug("Refusing to close the default {}; must be closed via closeDefault()", | ||
ClientFactory.class.getSimpleName()); | ||
return; | ||
} | ||
|
||
doClose(); | ||
} | ||
|
||
void doClose() { | ||
clientFactories.values().forEach(ClientFactory::close); | ||
} | ||
} |
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
Oops, something went wrong.