C# Loves Code Patterns

December 11, 2019

This post is part of the third annual C# Advent. Check out the home page for up to 50 C# blog posts in December 2019! Thanks, Matthew D. Groves for organizing it.

You might recall that LINQ has two forms. The first way is to call LINQ methods and the second is the special LINQ syntax. Here’s an example of the LINQ syntax.

Continue reading →

Synchronizing File Writes

November 27, 2019

Assuming we have a simple task to write events to a file, one event after another. Events can be written from multiple threads.

public interface EventLog {
    public final class Event{
        public final UUID id;
        public final ZonedDateTime created;
        public final String message;

        public Event(UUID id, ZonedDateTime created, String message) {
            this.id = id;
            this.created = created;
            this.message = message;
        }
    }

    void recordEvent(Event event);

    // Null Logger doing nothing to have a base line
    EventLog NULL_LOGGER = new NullLogger();

    class NullLogger implements EventLog {
        @Override
        public void recordEvent(Event event) {
            // do nothing;
        }

        @Override
        public void close() throws Exception {
        }
    }
}
Continue reading →

FileChannel Closes When Interrupted

November 12, 2019

Recently I worked on some threaded IO where a control thread interrupts the IO threads once in a while. Periodically the app started to fail with a java.nio.channels.ClosedChannelException.

FileChannel Closes When Interrupted
Figure 1. FileChannel Closes When Interrupted
Continue reading →

MVStore: Accessing Old Versions

November 6, 2019

A while back I blogged about MVStore basics. Let’s look at the way MVStore keeps old revisions around. First, MVStore maps have a .getVersion() method and a .openVersion() method pair. With that, you can access old version previous values. A new version of the map is created on (auto-) commit.

MVMap restores old versions of itself
Figure 1. MVMap restores old versions of itself
Continue reading →

Bastel Proxy: HTTPS and reverse proxy for development environments

November 5, 2019

I tend to work on web applications and services which are interconnected. Different parts of the website and the services run as separate processes. In production something like NGINX does the HTTPS termination and unifies the services to a single domain. I found it useful to have HTTPS and a reverse proxy in my development environment too. Browsers complain about plain HTTPS sites and even disable certain features. Further, if your website is split across different processes and one part runs on http://localhost:8080 and other on http://localhost:8081, you can run into cross-domain issues. Also, I found it less error-prone to mirror the domain structure than having tons of localhost:{port} pointing to each other.

One option is to run a production reverse proxy like NGINX. However, it requires quite a bit of configuration and you have to provide it the HTTPS certificates etc. I wanted a solution specific for developments which tries to minimize setup time.

Continue reading →