use of com.google.cloud.bigquery.connection.v1.Connection in project java-spring-boot-2021 by hocyadav.
the class GoogleBigQueryImpl method getConnection.
public static void getConnection(String projectId, String location, String connectionId) throws IOException {
try (ConnectionServiceClient client = ConnectionServiceClient.create()) {
ConnectionName name = ConnectionName.of(projectId, location, connectionId);
GetConnectionRequest request = GetConnectionRequest.newBuilder().setName(name.toString()).build();
Connection response = client.getConnection(request);
System.out.println("Connection info retrieved successfully :" + response.getName());
}
}
use of com.google.cloud.bigquery.connection.v1.Connection in project WorkHelperApp by hubme.
the class HttpLoggingInterceptor method intercept.
@Override
public Response intercept(Chain chain) throws IOException {
Level level = this.level;
Request request = chain.request();
if (level == Level.NONE) {
return chain.proceed(request);
}
boolean logBody = level == Level.BODY;
boolean logHeaders = logBody || level == Level.HEADERS;
RequestBody requestBody = request.body();
boolean hasRequestBody = requestBody != null;
Connection connection = chain.connection();
Protocol protocol = connection != null ? connection.protocol() : Protocol.HTTP_1_1;
String requestStartMessage = "--> " + request.method() + ' ' + request.url() + ' ' + protocol;
if (!logHeaders && hasRequestBody) {
requestStartMessage += " (" + requestBody.contentLength() + "-byte body)";
}
logger.log(requestStartMessage);
if (logHeaders) {
if (hasRequestBody) {
// them to be included (when available) so there values are known.
if (requestBody.contentType() != null) {
logger.log("Content-Type: " + requestBody.contentType());
}
if (requestBody.contentLength() != -1) {
logger.log("Content-Length: " + requestBody.contentLength());
}
}
Headers headers = request.headers();
for (int i = 0, count = headers.size(); i < count; i++) {
String name = headers.name(i);
// Skip headers from the request body as they are explicitly logged above.
if (!"Content-Type".equalsIgnoreCase(name) && !"Content-Length".equalsIgnoreCase(name)) {
logger.log(name + ": " + headers.value(i));
}
}
if (!logBody || !hasRequestBody) {
logger.log("--> END " + request.method());
} else if (bodyEncoded(request.headers())) {
logger.log("--> END " + request.method() + " (encoded body omitted)");
} else {
Buffer buffer = new Buffer();
requestBody.writeTo(buffer);
Charset charset = UTF8;
MediaType contentType = requestBody.contentType();
if (contentType != null) {
charset = contentType.charset(UTF8);
}
logger.log("");
if (isPlaintext(buffer)) {
logger.log(buffer.readString(charset));
logger.log("--> END " + request.method() + " (" + requestBody.contentLength() + "-byte body)");
} else {
logger.log("--> END " + request.method() + " (binary " + requestBody.contentLength() + "-byte body omitted)");
}
}
}
long startNs = System.nanoTime();
Response response;
try {
response = chain.proceed(request);
} catch (Exception e) {
logger.log("<-- HTTP FAILED: " + e);
throw e;
}
long tookMs = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - startNs);
ResponseBody responseBody = response.body();
long contentLength = responseBody.contentLength();
String bodySize = contentLength != -1 ? contentLength + "-byte" : "unknown-length";
logger.log("<-- " + response.code() + ' ' + response.message() + ' ' + response.request().url() + " (" + tookMs + "ms" + (!logHeaders ? ", " + bodySize + " body" : "") + ')');
if (logHeaders) {
Headers headers = response.headers();
for (int i = 0, count = headers.size(); i < count; i++) {
logger.log(headers.name(i) + ": " + headers.value(i));
}
if (!logBody || !HttpHeaders.hasBody(response)) {
logger.log("<-- END HTTP");
} else if (bodyEncoded(response.headers())) {
logger.log("<-- END HTTP (encoded body omitted)");
} else {
BufferedSource source = responseBody.source();
// Buffer the entire body.
source.request(Long.MAX_VALUE);
Buffer buffer = source.buffer();
Charset charset = UTF8;
MediaType contentType = responseBody.contentType();
if (contentType != null) {
charset = contentType.charset(UTF8);
}
if (!isPlaintext(buffer)) {
logger.log("");
logger.log("<-- END HTTP (binary " + buffer.size() + "-byte body omitted)");
return response;
}
if (contentLength != 0) {
logger.log("");
logger.log(buffer.clone().readString(charset));
}
logger.log("<-- END HTTP (" + buffer.size() + "-byte body)");
}
}
return response;
}
use of com.google.cloud.bigquery.connection.v1.Connection in project jboss-remoting by jboss-remoting.
the class ConnectionTestCase method testManyChannelsLotsOfData.
@Test
@Ignore
public void testManyChannelsLotsOfData() throws Exception {
final XnioWorker clientWorker = clientEndpoint.getXnioWorker();
final XnioWorker serverWorker = serverEndpoint.getXnioWorker();
final Queue<Throwable> problems = new ConcurrentLinkedQueue<Throwable>();
final CountDownLatch serverChannelCount = new CountDownLatch(CHANNEL_COUNT * CONNECTION_COUNT);
final CountDownLatch clientChannelCount = new CountDownLatch(CHANNEL_COUNT * CONNECTION_COUNT);
serverEndpoint.registerService("test", new OpenListener() {
public void channelOpened(final Channel channel) {
channel.receiveMessage(new Channel.Receiver() {
public void handleError(final Channel channel, final IOException error) {
problems.add(error);
error.printStackTrace();
serverChannelCount.countDown();
}
public void handleEnd(final Channel channel) {
serverChannelCount.countDown();
}
public void handleMessage(final Channel channel, final MessageInputStream message) {
try {
channel.receiveMessage(this);
while (message.read(junkBuffer) > -1) ;
} catch (Exception e) {
e.printStackTrace();
problems.add(e);
} finally {
IoUtils.safeClose(message);
}
}
});
}
public void registrationTerminated() {
}
}, OptionMap.EMPTY);
final AtomicReferenceArray<Connection> connections = new AtomicReferenceArray<Connection>(CONNECTION_COUNT);
for (int h = 0; h < CONNECTION_COUNT; h++) {
IoFuture<Connection> futureConnection = AuthenticationContext.empty().with(MatchRule.ALL, AuthenticationConfiguration.empty().useName("bob").usePassword("pass").setSaslMechanismSelector(SaslMechanismSelector.NONE.addMechanism("SCRAM-SHA-256"))).run(new PrivilegedAction<IoFuture<Connection>>() {
public IoFuture<Connection> run() {
try {
return clientEndpoint.connect(new URI("remote://localhost:30123"), OptionMap.EMPTY);
} catch (URISyntaxException e) {
throw new RuntimeException(e);
}
}
});
final Connection connection = futureConnection.get();
connections.set(h, connection);
for (int i = 0; i < CHANNEL_COUNT; i++) {
clientWorker.execute(new Runnable() {
public void run() {
final Random random = new Random();
final IoFuture<Channel> future = connection.openChannel("test", OptionMap.EMPTY);
try {
final Channel channel = future.get();
try {
final byte[] bytes = new byte[BUFFER_SIZE];
for (int j = 0; j < MESSAGE_COUNT; j++) {
final MessageOutputStream stream = channel.writeMessage();
try {
for (int k = 0; k < 100; k++) {
random.nextBytes(bytes);
stream.write(bytes, 0, random.nextInt(BUFFER_SIZE - 1) + 1);
}
stream.close();
} finally {
IoUtils.safeClose(stream);
}
stream.close();
}
} finally {
IoUtils.safeClose(channel);
}
} catch (IOException e) {
e.printStackTrace();
problems.add(e);
} finally {
clientChannelCount.countDown();
}
}
});
}
}
Thread.sleep(500);
serverChannelCount.await();
clientChannelCount.await();
for (int h = 0; h < CONNECTION_COUNT; h++) {
connections.get(h).close();
}
assertArrayEquals(new Object[0], problems.toArray());
}
use of com.google.cloud.bigquery.connection.v1.Connection in project jboss-remoting by jboss-remoting.
the class ConnectionTestCase method testChannelOptions.
@Test
public void testChannelOptions() throws Exception {
serverEndpoint.registerService("test", new OpenListener() {
@Override
public void channelOpened(Channel channel) {
//
Assert.assertTrue(channel.getOption(RemotingOptions.RECEIVE_WINDOW_SIZE) <= MAX_SERVER_RECEIVE);
Assert.assertTrue(channel.getOption(RemotingOptions.TRANSMIT_WINDOW_SIZE) <= MAX_SERVER_TRANSMIT);
}
@Override
public void registrationTerminated() {
//
}
}, OptionMap.create(RemotingOptions.RECEIVE_WINDOW_SIZE, MAX_SERVER_RECEIVE, RemotingOptions.TRANSMIT_WINDOW_SIZE, MAX_SERVER_TRANSMIT));
final Connection connection = AuthenticationContext.empty().with(MatchRule.ALL, AuthenticationConfiguration.empty().useName("bob").usePassword("pass").setSaslMechanismSelector(SaslMechanismSelector.NONE.addMechanism("SCRAM-SHA-256"))).run(new PrivilegedAction<Connection>() {
public Connection run() {
try {
return clientEndpoint.connect(new URI("remote://localhost:30123"), OptionMap.EMPTY).get();
} catch (IOException | URISyntaxException e) {
throw new RuntimeException(e);
}
}
});
IoFuture<Channel> future = connection.openChannel("test", OptionMap.create(RemotingOptions.RECEIVE_WINDOW_SIZE, 0x8000, RemotingOptions.TRANSMIT_WINDOW_SIZE, 0x12000));
Channel channel = future.get();
try {
Assert.assertEquals("transmit", 0x12000, (int) channel.getOption(RemotingOptions.TRANSMIT_WINDOW_SIZE));
Assert.assertEquals("receive", 0x8000, (int) channel.getOption(RemotingOptions.RECEIVE_WINDOW_SIZE));
} finally {
if (channel != null) {
channel.close();
}
}
future = connection.openChannel("test", OptionMap.create(RemotingOptions.RECEIVE_WINDOW_SIZE, 0x24000, RemotingOptions.TRANSMIT_WINDOW_SIZE, 0x24000));
channel = future.get();
try {
Assert.assertEquals("transmit", MAX_SERVER_RECEIVE, (int) channel.getOption(RemotingOptions.TRANSMIT_WINDOW_SIZE));
Assert.assertEquals("receive", MAX_SERVER_TRANSMIT, (int) channel.getOption(RemotingOptions.RECEIVE_WINDOW_SIZE));
} finally {
if (channel != null) {
channel.close();
}
}
}
use of com.google.cloud.bigquery.connection.v1.Connection in project jboss-remoting by jboss-remoting.
the class OutboundMessageCountTestCase method beforeTest.
@Before
public void beforeTest() throws IOException, URISyntaxException, InterruptedException {
System.gc();
System.runFinalization();
Logger.getLogger("TEST").infof("Running test %s", name.getMethodName());
final FutureResult<Channel> passer = new FutureResult<Channel>();
serviceRegistration = endpoint.registerService("org.jboss.test", new OpenListener() {
public void channelOpened(final Channel channel) {
passer.setResult(channel);
}
public void registrationTerminated() {
}
}, OptionMap.EMPTY);
IoFuture<Connection> futureConnection = AuthenticationContext.empty().with(MatchRule.ALL, AuthenticationConfiguration.empty().useName("bob").usePassword("pass").setSaslMechanismSelector(SaslMechanismSelector.NONE.addMechanism("SCRAM-SHA-256"))).run(new PrivilegedAction<IoFuture<Connection>>() {
public IoFuture<Connection> run() {
try {
return endpoint.connect(new URI("remote://[::1]:30123"), OptionMap.EMPTY);
} catch (URISyntaxException e) {
throw new RuntimeException(e);
}
}
});
connection = futureConnection.get();
final OptionMap channelCreationOptions = OptionMap.create(RemotingOptions.MAX_OUTBOUND_MESSAGES, MAX_OUTBOUND_MESSAGES);
IoFuture<Channel> futureChannel = connection.openChannel("org.jboss.test", channelCreationOptions);
clientChannel = futureChannel.get();
serverChannel = passer.getIoFuture().get();
assertNotNull(serverChannel);
}
Aggregations