apache commons overview

18
Gary Hessler CEO Open Source Integration, LLC

Upload: ghessler

Post on 28-Nov-2014

2.404 views

Category:

Technology


0 download

DESCRIPTION

Presente to the Colorado Springs Open Source Users Group on March 27, 2008 by Gary Hessler.

TRANSCRIPT

Page 1: Apache Commons Overview

Gary HesslerCEO

Open Source Integration, LLC

Page 2: Apache Commons Overview

Overview of Apache Commons Overview of APIs Highlight Specific API

Logging

© 2008 Open Source Integration, LLC. All rights reserved. 2

Page 3: Apache Commons Overview

Main Level Apache Project http://commons.apache.org Collection of frequently needed utilities

and APIs Organization

Components Repository Sandbox Components Dormant

© 2008 Open Source Integration, LLC. All rights reserved. 3

Page 4: Apache Commons Overview

Attributes – Runtime API to metadata BeanUtils – Wrapper around Reflection

and Introspection APIs Betwixt – Maps JavaBeans to XML Chain – Chain of Responsibility Pattern CLI – Command line interface Codec – Encoders and Decoders Collections – Extends JDK collections API Configuration – Reads config files in

various formats© 2008 Open Source Integration,

LLC. All rights reserved. 4

Page 5: Apache Commons Overview

Daemon – Unix Daemon-like Java code DBCP – Database connection pool DBUtils – JDBC helper library Digester – XML configuration Discovery – Locates pluggable interfaces EL – Expression language interpreter Email – Java e-mail library FileUpload – HTML Form-based file upload IO – Collection of IO utilities

© 2008 Open Source Integration, LLC. All rights reserved. 5

Page 6: Apache Commons Overview

JCI – Java Compiler Interface Jelly – Java and XML scripting and

processing engine Jexl – Expression language engine JXPath – XPath interpreter Lang – Extension of the java.lang

package Launcher – Java application launcher Logging – Logging wrapper Math – Math and statistics components

© 2008 Open Source Integration, LLC. All rights reserved. 6

Page 7: Apache Commons Overview

Modeler – JMX’s Model Mbeans Net – Internet protocol suite Pool – Object Pool Primitives – Improved classes for working

with primitive types Proxy – Library for creating dynamic

proxies SCXML – A Java SCXML engine Transaction – Transaction library for files,

collections, etc.© 2008 Open Source Integration,

LLC. All rights reserved. 7

Page 8: Apache Commons Overview

Validator – XML Data validation framework

VFS – Virtual File System

© 2008 Open Source Integration, LLC. All rights reserved. 8

Page 9: Apache Commons Overview

Compress – API for tar, zip, and bzip2 CSV – Comma Separated File utilities Exec – External process execution and

environment management Finder – Library like Unix find command I18n – Localized message bundles Id – Id generator Javaflow – Captures the state of an

application Monitoring – Application monitoring

instrumentation (Performance, threads)© 2008 Open Source Integration,

LLC. All rights reserved. 9

Page 10: Apache Commons Overview

OpenPGP – Sign and verify data using OpenPGP

Performance – Framework for MicroBench clients

Pipeline – Pipeline utilities designed around work queues

© 2008 Open Source Integration, LLC. All rights reserved. 10

Page 11: Apache Commons Overview

Plug-able logging framework Pluggins provider for:

Log4j JDK 1.4 Avalon Logkit No Op Simple

© 2008 Open Source Integration, LLC. All rights reserved. 11

Page 12: Apache Commons Overview

General - Message Priorities/Levels It is important to ensure that log message are appropriate in

content and severity. The following guidelines are suggested: FATAL - Severe errors that cause premature termination. Expect

these to be immediately visible on a status console. ERROR - Other runtime errors or unexpected conditions. Expect

these to be immediately visible on a status console. WARN - Use of deprecated APIs, poor use of API, 'almost' errors,

other runtime situations that are undesirable or unexpected, but not necessarily "wrong". Expect these to be immediately visible on a status console.

INFO - Interesting runtime events (startup/shutdown). Expect these to be immediately visible on a console, so be conservative and keep to a minimum.

DEBUG - Detailed information on flow of through the system. Expect these to be written to logs only.

TRACE - More detailed information. Expect these to be written to logs only.

© 2008 Open Source Integration, LLC. All rights reserved. 12

Page 13: Apache Commons Overview

General - Default Message Priority/Level By default the message priority should be no

lower than info. That is, by default debug message should not be seen in the logs.

Why info level instead of debug? You want to have exception/problem information

available for first-pass problem determination in a production level enterprise application without turning on debug as a default log level.

There is simply too much information in debug to be appropriate for day-to-day operations.

© 2008 Open Source Integration, LLC. All rights reserved. 13

Page 14: Apache Commons Overview

Carbon Severity

Enum

Commons Log

Log4J JDK 1.4 Logger

LogKit

Fatal Fatal Fatal Severe Fatal_Error

Error Error Error Severe Error

Warn Warn Warn Warning Warn

Info Info Info Info Info

Debug Debug Debug Fine Debug

Trace Trace Debug Finest Debug

© 2008 Open Source Integration, LLC. All rights reserved. 14

Page 15: Apache Commons Overview

Example of using Commons Logging Shows different logging levels Shows logging level checks Shows exception logging Includes 2 jars (Commons & Log4j) Show simple Log4j configuration file

© 2008 Open Source Integration, LLC. All rights reserved. 15

Page 16: Apache Commons Overview

Simple logging example Can get quite elaborate with logging

Use rolling file appenders Log to XML Log to database Log to JMX Log to JMS Log to SMTP Log to Socket

© 2008 Open Source Integration, LLC. All rights reserved. 16

Page 17: Apache Commons Overview

Don’t reinvent the wheel Reduce time Reduce expenses

Use as example code and a learning tool Too much out there to know everything

about libraries Explore the commons website and

experiment!

© 2008 Open Source Integration, LLC. All rights reserved. 17

Page 18: Apache Commons Overview

© 2008 Open Source Integration, LLC. All rights reserved. 18

Questions ?