Skip to content

Instantly share code, notes, and snippets.

package com.couchbase;
import com.couchbase.client.CouchbaseClient;
import com.couchbase.client.CouchbaseConnectionFactoryBuilder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Controller;
final ChannelHandler endpointHandler = new GenericEndpointHandler(this, responseBuffer);
bootstrap = new BootstrapAdapter(new Bootstrap()
.remoteAddress(hostname, port())
.group(environment.ioPool())
.channel(NioSocketChannel.class)
.option(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT)
.option(ChannelOption.TCP_NODELAY, false)
.handler(new ChannelInitializer<Channel>() {
@Override
protected void initChannel(Channel channel) throws Exception {
@daschl
daschl / HighPerf.java
Created May 16, 2014 06:21
Reactor Examples from JAX 2014
package example.couchbase;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import reactor.core.Environment;
import reactor.core.Reactor;
import reactor.core.spec.Reactors;
import reactor.event.Event;
import reactor.function.Consumer;
import reactor.net.NetChannel;
@daschl
daschl / Description
Last active August 29, 2015 14:01
JCStress static util method check.
Hey, thanks much for looking at this.
I got a potential race condition reported in one of our util classes (the StringUtils class attached here). Only concentrate on the isJSONObject method. Although its not 100% correct the focus on this here is that apparently there is a race condition with the matcher used for the final check. If 2 threads access it, there could be an issue with clear and match (https://www.couchbase.com/issues/browse/SPY-170).
Now I think I already know how to fix it, but I wanted to proof it with JCStress and also try it out.
So I cloned it and fiddled around with it and got it to run. Tests code is also attached.
- I want to pound my StringUtil.isJSONObject very hard to see if the exception described in the ticket is raised. I thought I do it like the other tests, catch it and return -1 not allowing it.
I tried to add a new .xml desc file but somehow it is not picked up, so I attached it to atomic-boolean.xml.. is there something I need to be on the lookout for where to place it?
@Override
protected void channelRead0(ChannelHandlerContext ctx, FullBinaryMemcacheResponse msg) throws Exception {
if (msg.getStatus() == BinaryMemcacheResponseStatus.SUCCESS) {
while(msg.content().isReadable()) {
short supported = msg.content().readShort();
if (supported == 0x01) {
SupportedDatatypes dtypes = new SupportedDatatypes(true, true);
LOGGER.debug(ctx.channel().remoteAddress() + " Hello detected: " + dtypes);
ctx.fireUserEventTriggered(dtypes);
}
┌─[✗]─[michael@daschlbase]─[~/code/rust/ketama]
└──╼ cargo build
Fresh rust-crypto v0.1.0 (https://github.com/DaGenix/rust-crypto.git)
Compiling ketama-rs v0.1.0 (file:/Users/michaelnitschinger/code/rust/ketama)
src/ketama.rs:12:5: 12:19 error: type `rust-crypto::md5::Md5` does not implement any method in scope named `input_str`
src/ketama.rs:12 sh.input_str(key);
^~~~~~~~~~~~~~
src/ketama.rs:13:13: 13:25 error: type `rust-crypto::md5::Md5` does not implement any method in scope named `result_str`
src/ketama.rs:13 println(sh.result_str());
^~~~~~~~~~~~
@daschl
daschl / ketama.rs
Created July 1, 2014 10:01
run with cargo test
<std macros>:8:12: 35:21 error: mismatched types: expected `bool` but found `<generic integer #0>` (expected bool but found integral variable)
<std macros>:8 if !$cond {
<std macros>:9 fail!($($arg),+)
<std macros>:10 }
<std macros>:11 );
<std macros>:12 )
error: internal compiler error: unexpected failure
note: the compiler hit an unexpected failure path. this is a bug.
note: we would appreciate a bug report: http://doc.rust-lang.org/complement-bugreport.html
note: run with `RUST_BACKTRACE=1` for a backtrace
// 1: do func1(); which returns an Observable<Res1>
// 2: once Res1 is onComplete (so done without error):
// 3a: do func2();
// 3b: as long as the result does not match a given codition.
// 4: if done, return the original result from func1
In sync it would more or less look like:
Res1 res1 = func1();
done = false;
@daschl
daschl / error.json
Created July 25, 2014 10:44
I need to parse and emit every item of the result set and then individually the info block (example). Also the code needs to see if an error arises and do something else.
{
"error":
{
"caller": "standard:50",
"cause": "Parse Error - syntax error",
"code": 4100,
"key": "parse_error",
"message": "Parse Error"
}
}
ioPool.shutdownGracefully().addListener(new GenericFutureListener<Future<?>>() {
@Override
public void operationComplete(Future<?> future) throws Exception {
System.err.println(future.isSuccess());
}
});
Error:(66, 49) java: incompatible types: <anonymous io.netty.util.concurrent.GenericFutureListener
<io.netty.util.concurrent.Future<?>>> cannot be converted to io.netty.util.concurrent.GenericFutureListener<? e