Ron and Ella Wiki Page

Extremely Serious

Page 25 of 33

Deploy Function using Azure Functions Core Tools

Use the following command to deploy a(some) locally developed function(s) to azure function app.

func azure functionapp publish <AZURE_FUNCTION_APP>

Note: This command will only work if your terminal session was signed in to azure. The login using the command found here.

Where:

AZURE_FUNCTION_APP The name of the function app found in azure portal.

Using Proxy with NodeJS

Execute the following command to set the proxy for HTTP:

npm config set proxy <HOST>:<PORT>

Execute the following command to set the proxy for HTTPS:

npm config set https-proxy <HOST>:<PORT>

Where:

HOST The host that is running the proxy server
PORT The port the proxy server is listening.

Adding NuGet Package Reference to a Project

Add a NuGet package reference to .Net Core project using the following command:

dotnet add package <PACKAGE_NAME> [-v <VERSION>]

Where:

PACKAGE_NAME The NuGet package to be added
VERSION If the optional -v was used, the target VERSION of the NuGet package.

Example without the -v option

dotnet add package Microsoft.ApplicationInsights

Example with the -v option

dotnet add package Microsoft.ApplicationInsights -v 2.10.0

Philippine Internet Radio Stations

StationStreaming Address
Cool FM 90.1http://equinox.shoutca.st:8938/stream
iFM 93.9 Manilahttp://curiosity.shoutca.st:8098/stream
90.7 Love Radio Manilahttps://manilabr.radioca.st/stream
Magic 107http://curiosity.shoutca.st:8098/stream/1/
Star FM Manila 102.7 FMhttp://ample-zeno-06.radiojar.com/g1pmt17nz9duv
YES! FM 101.1 Manilahttp://37.59.28.208:8500/stream
Monster RX 93.1http://icecast.eradioportal.com:8000/monsterrx
Rakista Radiohttp://206.190.138.197:8000/stream/1/

ThreadPoolExecutor with ArrayBlockingQueue and Custom Thread Name

Create an implementation of ThreadFactory to create a thread with custom name for ThreadPoolExecutor as follows:

class MyThreadFactory implements ThreadFactory {
    private AtomicLong threadCounter;

    private MyThreadFactory() {
        threadCounter = new AtomicLong();
    }

    @Override
    public Thread newThread(Runnable runnable) {
        var thread=new Thread(runnable);
        thread.setName(String.join("-","my-thread",
                String.valueOf(threadCounter.incrementAndGet())));
        return thread;
    }
}

The preceding class will generate a thread with the name starting with my-thread. Use the instance of this class in constructing the ThreadPoolExecutor as follows:

var executor = new ThreadPoolExecutor(2, 4, 60L, TimeUnit.SECONDS,
        new ArrayBlockingQueue<>(100), new MyThreadFactory(), 
        new ThreadPoolExecutor.CallerRunsPolicy());

The preceding declaration creates an instance of ThreadPoolExecutor with 2 core threads, 4 maximum threads, 60 seconds keep alive and supports 100 items in the queue. The queue size is defined by the instance of ArrayBlockingQueue class.

Start all the core threads as follows:

executor.prestartAllCoreThreads();

Using a profiling tool we can search for all the threads whose names starts with my-thread like the following screenshot:

Don't forget to call any shutdown/terminate methods when done using the executor.

Getting a Resource using ModuleLayer

If the resource and the module are known, we can use the ModuleLayer to access it like the following snippet.

ModuleLayer.boot().findModule(<MODULE_NAME>).ifPresent(___module -> {
    try {
        var modResource = ___module.getResourceAsStream(<RESOURCE_NAME>);
    } catch (IOException e) {
        e.printStackTrace();
    }
});

Where:

MODULE_NAME -> the name of the module that has the resource.
RESOURCE_NAME -> the resource of interest.

« Older posts Newer posts »