Skip to content

Instantly share code, notes, and snippets.

/**
* Copyright (C) 2013 Couchbase, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
package controllers;
import play.libs.F;
import play.mvc.*;
public class Application extends Controller {
public static WebSocket<String> index() {
return new WebSocket<String>() {
@Override
@daschl
daschl / Main.java
Created October 14, 2013 12:23
async observe for the MASSES
import com.couchbase.client.CouchbaseClient;
import com.couchbase.client.CouchbaseConnectionFactory;
import com.couchbase.client.CouchbaseConnectionFactoryBuilder;
import com.couchbase.client.ObservedException;
import com.couchbase.client.ObservedModifiedException;
import com.couchbase.client.ObservedTimeoutException;
import net.spy.memcached.CASResponse;
import net.spy.memcached.PersistTo;
import net.spy.memcached.ReplicateTo;
import net.spy.memcached.internal.OperationCompletionListener;
@daschl
daschl / HighPerf.java
Created October 18, 2013 08:17
This code uses a Reactor and 3 consumers that write through the tcp-client. Things could be even more optimized, though the high througput is achieved through batching.
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.tcp.TcpClient;
@daschl
daschl / Log
Created October 23, 2013 13:28
Failing Test
/Library/Java/JavaVirtualMachines/jdk1.7.0_45.jdk/Contents/Home/bin/java -ea -Didea.launcher.port=7534 "-Didea.launcher.bin.path=/Applications/IntelliJ IDEA 12.app/bin" -Dfile.encoding=UTF-8 -classpath "/Applications/IntelliJ IDEA 12.app/lib/idea_rt.jar:/Applications/IntelliJ IDEA 12.app/plugins/junit/lib/junit-rt.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_45.jdk/Contents/Home/lib/ant-javafx.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_45.jdk/Contents/Home/lib/dt.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_45.jdk/Contents/Home/lib/javafx-doclet.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_45.jdk/Contents/Home/lib/javafx-mx.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_45.jdk/Contents/Home/lib/jconsole.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_45.jdk/Contents/Home/lib/sa-jdi.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_45.jdk/Contents/Home/lib/tools.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_45.jdk/Contents/Home/jre/lib/charsets.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_45.jdk/Conte
@daschl
daschl / LoggingHandlerTest.java
Created November 6, 2013 08:04
How do I assert that the active line is in there? It looks like the appender is working, but I dont know how to correctly assert the one line and ignore the others.
/*
* Copyright 2012 The Netty Project
*
* The Netty Project 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
@daschl
daschl / gist:7335922
Created November 6, 2013 13:20
sqoop password
[cloudera@localhost Downloads]$ file /home/cloudera/.password
/home/cloudera/.password: ASCII text
[cloudera@localhost Downloads]$ sqoop export --username hadoop --password-file ~/.password --table ignored --connect http://192.168.1.100:8091/pools --export-dir couchbase_hello_world --verbose --input-fields-terminated-by '\t' --lines-terminated-by '\n'
13/11/06 05:18:04 DEBUG tool.BaseSqoopTool: Enabled debug logging.
13/11/06 05:18:04 DEBUG util.CredentialsUtil: Fetching password from specified path: /home/cloudera/.password
13/11/06 05:18:05 WARN tool.BaseSqoopTool: Failed to load connection parameter file
java.io.IOException: The password file does not exist! /home/cloudera/.password
@daschl
daschl / gist:7889620
Created December 10, 2013 12:07
Odd string wrangling on encode
protected final ByteBuf SPACE = Unpooled.copiedBuffer(" ", CharsetUtil.UTF_8);
and
buffer.writeBytes(msg.getCmd().getValue().getBytes(CharsetUtil.UTF_8));
buffer.writeBytes(SPACE.copy());
buffer.writeBytes(msg.getKey().getBytes(CharsetUtil.UTF_8));
buffer.writeBytes(SPACE.copy());
buffer.writeInt(msg.getFlags());
buffer.writeBytes(SPACE.copy());
@daschl
daschl / ViewConnection.java
Last active December 31, 2015 12:19
connection management
import com.couchbase.client.http.HttpResponseCallback;
import com.couchbase.client.http.HttpUtil;
import com.couchbase.client.protocol.views.HttpOperation;
import com.couchbase.client.vbucket.Reconfigurable;
import com.couchbase.client.vbucket.config.Bucket;
import com.couchbase.client.vbucket.config.DefaultConfig;
import java.io.IOException;
import java.io.InterruptedIOException;
import java.io.UnsupportedEncodingException;
import java.net.InetSocketAddress;
2013-12-18 11:06:47.255 ERROR 18276 --- [nio-8080-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Handler processing failed; nested exception is java.lang.NoClassDefFoundError: org/hibernate/proxy/HibernateProxy] with root cause
java.lang.ClassNotFoundException: org.hibernate.proxy.HibernateProxy
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)