Saturday, November 17, 2018

AspectJ tutorials


AspectJ and AOP – The black magic of programming


https://blog.jayway.com/2015/09/03/aspectj-and-aop-the-black-magic-of-programming/

AspectJ – Dictionary

Aspects

The easiest way to describe aspects is as a funky Java Class. An Aspect contains other things than a normal class such as; pointcuts, advice, advice bodies and inner-type declarations. An aspect may also contain regular java classes and methods.

Pointcuts

Defines, in a multitude of different ways, a point in the code. The pointcut defines when an advice should be run.

Advice / Advice Body

Similar to a java method; contains the code that will be run once a pointcut has been triggered.

Annotation – Not AOP specific

Consists of meta-data and can be used at methods, classes, parameters, packages and in variables.
Annotations can contain an optional list of element-value pairs, such as ‘yourProperty = “someValue”‘ in the example above. In AspectJ we can define a pointcut by looking for annotations. The pointcut and advice can then use the element-value pairs from the annotation.

Weaving / Aspect weaving

There are a few different ways to inject the AOP code in our application, but one common denominator is that they all require some type of extra step to be applied to our code. This extra step is called weaving.

Compile-time weaving

If you have both the source code of the aspect and the code that you are using aspects in, you can compile your source-code and the aspect directly with an AspectJ compiler.

Post-compile weaving / Binary weaving

If you can’t, or don’t want to use source-code transforms to weave the aspects into the code, you can take already compiled classes or jars and inject aspects.

Load-time weaving

Acts the same way as post-compile weaving / binary weaving but waits to inject aspects into the code until the class loader loads the class file. This requires one or more weaving class loaders.

Saturday, September 22, 2018

Friday, September 7, 2018

ByteBuffer flip vs rewind

https://stackoverflow.com/questions/16461284/difference-between-bytebuffer-flip-and-bytebuffer-rewind


flip() makes it ready for write() (or for get())
         rewind() makes it ready for read() (or for put())

get() Example;
You might want to read data from the buffer (assuming that you had initially stored it in there)and use it for something else such as converting to a string and manipulate it for further use.
ByteBuffer buf = ByteBuffer.allocateDirect(80);
private String method(){
buf.flip();
byte[] bytes = byte[10]; //creates a byte array where you can place your data 
buf.get(bytes); //reads data from buffer and places it in the byte array created above
return bytes;
}
write() Example; After you have read data from socket channel into the buffer you might want to write it back to socket channel - assuming that you want to implement something like a server that echos same message received from client.
So you will read from channel to buffer and from buffer back to channel
SocketChannel socketChannel = SocketChannel.open();
...

ByteBuffer buf = ByteBuffer.allocateDirect(80);

int data = socketChannel.read(buf); // Reads from channel and places it into the buffer
while(data != -1){ //checks if not end of reading
buf.flip();        //prepares for writing
....
socketChannel.write(buf) // if you had initially placed data into buf and you want to read 
                         //from it so that you can write it back into the channel


  }

Saturday, July 7, 2018

How to build smaller Docker containers

https://www.youtube.com/watch?v=wGz_cbtCiEA

In this episode of Kubernetes Best Practices, Sandeep Dinesh shows how you can build small containers to make your Kubernetes deployments faster and more secure. See the associated article here → https://goo.gl/zjejFj Google Container Registry → https://goo.gl/ilwubv Google Container Builder → https://goo.gl/l1Obc1 Container Registry Vulnerability Scanning → https://goo.gl/5EiyLe Google Kubernetes Engine → https://goo.gl/2V8yah Docker Multistage Builds → https://goo.gl/nQmwW4

Tuesday, June 26, 2018

Lambda expression performance


https://stackoverflow.com/questions/22637900/java8-lambdas-vs-anonymous-classes

An anonymous inner class (AIC) is a class, which means that it has scope for variable defined inside the inner class.
Whereas,lambda expression is not a scope of its own, but is part of the enclosing scope.
 At runtime anonymous inner classes (AIC) require class loading, memory allocation and object initialization and invocation of a non-static method while lambda expression is pure compile time activity and don’t incur extra cost during runtime. So performance of lambda expression is better as compare to anonymous inner classes.**

Monday, June 25, 2018

Proper proxy setting for Docker



https://stackoverflow.com/questions/50148644/what-is-the-proper-proxy-settings-for-docker-and-kubernetes



We always include the scheme in our environment variables.

/etc/profile.d/proxy.sh:

#!/bin/bash
export http_proxy=http://:3128
export https_proxy=$http_proxy
export no_proxy=169.254.169.254,localhost,127.0.0.1
export HTTP_PROXY=$http_proxy
export HTTPS_PROXY=$https_proxy
export NO_PROXY=$no_proxy

/etc/systemd/system/docker.service.d/proxy.conf:


[Service]
Environment="HTTPS_PROXY=https://:3128/" "HTTP_PROXY=http://:3128/"

 

Monday, June 11, 2018

TortoiseSVN not save the password

https://stackoverflow.com/questions/27797593/tortoisesvn-not-save-the-password?rq=1

1) When Tortoise SVN was not saving my user/password credentials I solved the problem by going to TortoiseSVN settings -> Saved Data -> Clear Authentication data (see image below). Also check AllowAuthSave is set to true in TortoiseSVN settings -> Advanced.

 - or -


2) Whether or not to store passwords is set by the Subversion configuration file.
  • Right click on your desktop, so you see the TortoiseSVN menu. Go to TortoiseSVN->Settings.
  • In the General section, click on the Edit button for the Subversion Configuration File.
  • Two items you wan to change:
    • Make sure that password-stores = windows-cryptoapi is enabled. (I believe this is the default anyway) by removing the # in front of the line.
    • Look for the lines that say store-passwords = no and store-auth-creds = no. Change the no to a yes, and remove the # at the beginning of the line.
Save the changes, and close the initial settings box by clicking on Ok. Next time, when Subversion asks for the password, it will store it.