Skip to content

Instantly share code, notes, and snippets.

View Horusiath's full-sized avatar

Bartosz Sypytkowski Horusiath

View GitHub Profile
@Horusiath
Horusiath / Program.cs
Last active December 13, 2016 09:43
Akka cluster router
using System;
using Akka.Actor;
using Akka.Configuration;
using Akka.Routing;
namespace AkkaClustering
{
public class JobCoordinatorActor : ReceiveActor
{
public JobCoordinatorActor()
@Horusiath
Horusiath / stacktrace
Created January 11, 2017 11:10
DotNetty socket exception when connecting to 0.0.0.0:38223
at DotNetty.Transport.Channels.Sockets.SocketChannelAsyncOperation.Validate()
at DotNetty.Transport.Channels.Sockets.TcpSocketChannel.DoFinishConnect(SocketChannelAsyncOperation operation)
at DotNetty.Transport.Channels.Sockets.AbstractSocketChannel.AbstractSocketUnsafe.FinishConnect(SocketChannelAsyncOperation operation)
--- End of inner exception stack trace ---
--- End of inner exception stack trace ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at DotNetty.Transport.Bootstrapping.Bootstrap.<DoResolveAndConnectAsync>d__15.MoveNext()
@Horusiath
Horusiath / ReplicatorMessageSerializer.cs
Created January 13, 2017 15:59
DData serializer on proto-buf
internal sealed class ReplicatorMessageSerializer : SerializerWithStringManifest
{
#region internal classes
/// <summary>
/// A cache that is designed for a small number (&lt;= 32) of
/// entries. It is using instance equality.
/// Adding new entry overwrites oldest. It is
/// thread safe but duplicates of same entry may occur.
@Horusiath
Horusiath / Example.cs
Created January 16, 2017 13:26
Akka.NET new DotNetty-based transport pipelines (more or less accurate)
// server
new ServerBootstrap()
.Group(serverEventLoopGroup)
.Option(ChannelOption.SoReuseaddr, Settings.TcpReuseAddr)
.Option(ChannelOption.SoKeepalive, Settings.TcpKeepAlive)
.Option(ChannelOption.TcpNodelay, Settings.TcpNoDelay)
.Option(ChannelOption.AutoRead, false)
.Option(ChannelOption.SoBacklog, Settings.Backlog)
.ChannelFactory(() => Settings.EnforceIpFamily
? new TcpServerSocketChannel(addressFamily)
@Horusiath
Horusiath / Client.cs
Last active January 18, 2017 08:06
DotNetty example of failing TLS layer support
using System;
using System.IO;
using System.Net;
using System.Net.Sockets;
using System.Security.Cryptography.X509Certificates;
using System.Threading.Tasks;
using DotNetty.Buffers;
using DotNetty.Codecs;
using DotNetty.Common.Internal.Logging;
using DotNetty.Handlers.Logging;
@Horusiath
Horusiath / Program.cs
Created January 26, 2017 09:08
Akka.Persistence example with proto-buf.net as a custom domain event serializer
using System;
using Akka.Actor;
using Akka.Configuration;
using Akka.Persistence.SqlServer;
namespace TestApp
{
class Program
{
public static void Main()
@Horusiath
Horusiath / log
Created February 1, 2017 10:13
linux/mono DotNetty exception
Unhandled Exception:
System.AggregateException: One or more errors occurred. ---> System.AggregateException: One or more errors occurred. ---> System.Net.Sockets.SocketException: Invalid arguments
at System.Net.Sockets.Socket.Bind (System.Net.EndPoint local_end) [0x00036] in <filename unknown>:0
at DotNetty.Transport.Channels.Sockets.TcpServerSocketChannel.DoBind (System.Net.EndPoint localAddress) [0x00000] in <filename unknown>:0
at DotNetty.Transport.Channels.AbstractChannel+AbstractUnsafe.BindAsync (System.Net.EndPoint localAddress) [0x00026] in <filename unknown>:0
--- End of inner exception stack trace ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in <filename unknown>:0
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x0004e] in <filename unknown>:0
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x0002e] in <filename unkn
@Horusiath
Horusiath / missing union types.fs
Created June 15, 2017 10:35
Lack of union types
// we define two message-based protocols: one for data replication one for persistence
// those can be defined easily using discriminated union semantics
type ReplicationProtocol =
| Sync of Endpoint
| ReplicationProgess of ReplicaId * int
| Read of ReplicaId
| ReadRepair of ReplicaId
type PersistenceProtocol =
| Save of PersistenceId * byte[]
@Horusiath
Horusiath / AkklingAPI.fs
Last active March 13, 2018 11:25
akka-typed Akkling API idea
type Command = Job of string
let active (count: int): Behavior<Command> =
Actor.behavior (fun ctx msg ->
match msg with
| Job payload ->
printfn "Received %s, current state: %d" payload count
// return updated state behavior, equivalent of become
active (count + 1))
|> onSignal (fun ctx sig ->
@Horusiath
Horusiath / Example.cs
Created September 27, 2017 06:59
Generic Google Protocol Buffers serializer for Akka.NET
using System;
using Akka.Actor;
using Akka.Configuration;
using Akka.Serialization.Protobuf;
using ProtoBuf;
namespace App
{
/// <summary>
/// Interface used to recognize messages to be serialized by <see cref="ProtobufSerializer"/>.